ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/disk_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.20 by ats, Thu Aug 28 23:05:56 2003 UTC vs.
Revision 1.28 by pajs, Thu Oct 9 15:22:59 2003 UTC

# Line 325 | Line 325 | diskio_stat_t *get_diskio_stats(int *entries){
325          time_t now;
326   #endif
327   #ifdef FREEBSD
328 <        struct statinfo stats;
328 >        static struct statinfo stats;
329 >        static int stats_init = 0;
330          int counter;
331          struct device_selection *dev_sel = NULL;
332          int n_selected, n_selections;
# Line 335 | Line 336 | diskio_stat_t *get_diskio_stats(int *entries){
336          num_diskio=0;
337  
338   #ifdef FREEBSD
339 <        stats.dinfo=malloc(sizeof(struct devinfo));
340 <        if(stats.dinfo==NULL) return NULL;
339 >        if (!stats_init) {
340 >                stats.dinfo=malloc(sizeof(struct devinfo));
341 >                bzero(stats.dinfo, sizeof(struct devinfo));
342 >                if(stats.dinfo==NULL) return NULL;
343 >                stats_init = 1;
344 >        }
345 > #ifdef FREEBSD5
346 >        if ((devstat_getdevs(NULL, &stats)) < 0) return NULL;
347 >        /* Not aware of a get all devices, so i said 999. If we ever                                                                           * find a machine with more than 999 disks, then i'll change                                                                           * this number :)                                                                                                                      */
348 >        if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL;
349 > #else
350          if ((getdevs(&stats)) < 0) return NULL;
351          /* Not aware of a get all devices, so i said 999. If we ever
352           * find a machine with more than 999 disks, then i'll change
353           * this number :)
354           */
355          if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL;
356 + #endif
357  
358          for(counter=0;counter<stats.dinfo->numdevs;counter++){
359                  dev_ptr=&stats.dinfo->devices[dev_sel[counter].position];
# Line 351 | Line 362 | diskio_stat_t *get_diskio_stats(int *entries){
362                   * devices.. like mem, proc.. and also doesn't report floppy
363                   * drives etc unless they are doing stuff :)
364                   */
365 + #ifdef FREEBSD5
366 +                if((dev_ptr->bytes[DEVSTAT_READ]==0) && (dev_ptr->bytes[DEVSTAT_WRITE]==0)) continue;
367 + #else
368                  if((dev_ptr->bytes_read==0) && (dev_ptr->bytes_written==0)) continue;
369 + #endif
370                  if((diskio_stats=diskio_stat_malloc(num_diskio+1, &sizeof_diskio_stats, diskio_stats))==NULL){
371                          return NULL;
372                  }
373                  diskio_stats_ptr=diskio_stats+num_diskio;
374 <                
374 >
375 > #ifdef FREEBSD5        
376 >                diskio_stats_ptr->read_bytes=dev_ptr->bytes[DEVSTAT_READ];
377 >                diskio_stats_ptr->write_bytes=dev_ptr->bytes[DEVSTAT_WRITE];
378 > #else
379                  diskio_stats_ptr->read_bytes=dev_ptr->bytes_read;
380                  diskio_stats_ptr->write_bytes=dev_ptr->bytes_written;
381 + #endif
382                  if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
383                  asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number);
384                  diskio_stats_ptr->systime=time(NULL);
# Line 366 | Line 386 | diskio_stat_t *get_diskio_stats(int *entries){
386                  num_diskio++;
387          }
388          free(dev_sel);
369        free(stats.dinfo);
389  
390   #endif
391   #ifdef SOLARIS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines