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