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.74 by ats, Mon Nov 1 20:36:46 2004 UTC vs.
Revision 1.80 by tdb, Thu Feb 24 12:34:45 2005 UTC

# Line 50 | Line 50
50                          "ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \
51                          "jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \
52                          "rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \
53 <                        "umsdos", "vfat", "xfs", "jfs"}
53 >                        "umsdos", "vfat", "xfs", "jfs", "nfs"}
54   #endif
55  
56   #ifdef CYGWIN
# Line 66 | Line 66
66   #include <sys/dkstat.h>
67   #include <devstat.h>
68   #define VALID_FS_TYPES {"hpfs", "msdosfs", "ntfs", "udf", "ext2fs", \
69 <                        "ufs", "mfs"}
69 >                        "ufs", "mfs", "nfs"}
70   #endif
71   #if defined(NETBSD) || defined(OPENBSD)
72   #include <sys/param.h>
73   #include <sys/sysctl.h>
74   #include <sys/disk.h>
75   #define VALID_FS_TYPES {"ffs", "mfs", "msdos", "lfs", "adosfs", "ext2fs", \
76 <                        "ntfs"}
76 >                        "ntfs", "nfs"}
77   #endif
78  
79   #ifdef HPUX
# Line 87 | Line 87
87   #include <stdio.h>
88   #include <time.h>
89   #define VALID_FS_TYPES {"vxfs", "hfs"}
90 + #define DISK_BATCH 30
91   #endif
92  
93   static void disk_stat_init(sg_fs_stats *d) {
# Line 105 | Line 106 | static int is_valid_fs_type(const char *type) {
106          const char *types[] = VALID_FS_TYPES;
107          int i;
108  
109 <        for (i = 0; i < (sizeof types / sizeof *types); i++) {
109 >        for (i = 0; i < (int) (sizeof types / sizeof *types); i++) {
110                  if (strcmp(types[i], type) == 0) {
111                          return 1;
112                  }
# Line 143 | Line 144 | sg_fs_stats *sg_get_fs_stats(int *entries){
144   #endif
145  
146   #ifdef ALLBSD
147 <        nummnt=getmntinfo(&mp , MNT_LOCAL);
147 >        nummnt=getmntinfo(&mp, MNT_WAIT);
148          if (nummnt<=0){
149                  sg_set_error_with_errno(SG_ERROR_GETMNTINFO, NULL);
150                  return NULL;
# Line 316 | Line 317 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
317          long long rbytes = 0, wbytes = 0;
318          struct dirent *dinfo = NULL;
319          struct stat lstatinfo;
320 <        struct pst_diskinfo pstat_diskinfo;
320 >        struct pst_diskinfo pstat_diskinfo[DISK_BATCH];
321          char fullpathbuf[1024] = {0};
322          dev_t diskid;
323          DIR *dh = NULL;
324 <        int disknum = 0;
324 >        int diskidx = 0;
325 >        int num, i;
326   #endif
327   #ifdef SOLARIS
328          kstat_ctl_t *kc;
# Line 370 | Line 372 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
372          num_diskio=0;
373  
374   #ifdef HPUX
375 <
376 <        /* The "128" here is arbitrary, it can be increased to any number
377 <           at the expense of only more system calls to pstat(). */
378 <        for (disknum = 0; disknum < 128; disknum++) {
379 <                if (pstat_getdisk(&pstat_diskinfo, sizeof(pstat_diskinfo), 1, disknum) == -1) {
375 >        while (1) {
376 >                num = pstat_getdisk(pstat_diskinfo, sizeof pstat_diskinfo[0],
377 >                                    DISK_BATCH, diskidx);
378 >                if (num == -1) {
379 >                        sg_set_error_with_errno(SG_ERROR_PSTAT,
380 >                                                "pstat_getdisk");
381 >                        return NULL;
382 >                } else if (num == 0) {
383                          break;
384                  }
385  
386 <                if (pstat_diskinfo.psd_idx != disknum) {
387 <                        continue;
383 <                }
386 >                for (i = 0; i < num; i++) {
387 >                        struct pst_diskinfo *di = &pstat_diskinfo[i];
388  
389 <                /* Skip "disabled" disks.. */
390 <                if (pstat_diskinfo.psd_status == 0) {
387 <                        continue;
388 <                }
389 <
390 <                /* We can't seperate the reads from the writes, we'll
391 <                   just give the same to each. */
392 <                rbytes = wbytes = (pstat_diskinfo.psd_dkwds * 64);
393 <
394 <                /* Skip unused disks. */
395 <                if (rbytes == 0 && wbytes == 0) {
396 <                        continue;
397 <                }
398 <
399 <                if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) {
400 <                        return NULL;
401 <                }
402 <
403 <                diskio_stats_ptr = diskio_stats + num_diskio;
404 <
405 <                diskio_stats_ptr->read_bytes = rbytes;
406 <                diskio_stats_ptr->write_bytes = wbytes;
407 <
408 <                diskio_stats_ptr->systime = time(NULL);
409 <
410 <                num_diskio++;
411 <
412 <                if (diskio_stats_ptr->disk_name == NULL) {
413 <                        dh = opendir("/dev/dsk");
414 <                        if (dh == NULL) {
389 >                        /* Skip "disabled" disks. */
390 >                        if (di->psd_status == 0) {
391                                  continue;
392                          }
393 <
394 <                        diskid = (pstat_diskinfo.psd_dev.psd_major << 24) | pstat_diskinfo.psd_dev.psd_minor;
395 <                        while (1) {
396 <                                dinfo = readdir(dh);
397 <                                if (dinfo == NULL) {
398 <                                        break;
399 <                                }
400 <                                snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name);
401 <                                if (lstat(fullpathbuf, &lstatinfo) < 0) {
393 >        
394 >                        /* We can't seperate the reads from the writes, we'll
395 >                         * just give the same to each. (This value is in
396 >                         * 64-byte chunks according to the pstat header file,
397 >                         * and can wrap to be negative.)
398 >                         */
399 >                        rbytes = wbytes = ((unsigned long) di->psd_dkwds) * 64LL;
400 >        
401 >                        /* Skip unused disks. */
402 >                        if (rbytes == 0 && wbytes == 0) {
403 >                                continue;
404 >                        }
405 >        
406 >                        if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) {
407 >                                return NULL;
408 >                        }
409 >        
410 >                        diskio_stats_ptr = diskio_stats + num_diskio;
411 >        
412 >                        diskio_stats_ptr->read_bytes = rbytes;
413 >                        diskio_stats_ptr->write_bytes = wbytes;
414 >        
415 >                        diskio_stats_ptr->systime = time(NULL);
416 >        
417 >                        num_diskio++;
418 >        
419 >                        /* FIXME This should use a static cache, like the Linux
420 >                         * code below. */
421 >                        if (diskio_stats_ptr->disk_name == NULL) {
422 >                                dh = opendir("/dev/dsk");
423 >                                if (dh == NULL) {
424                                          continue;
425                                  }
426 <
427 <                                if (lstatinfo.st_rdev == diskid) {
428 <                                        if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) {
426 >        
427 >                                diskid = (di->psd_dev.psd_major << 24) | di->psd_dev.psd_minor;
428 >                                while (1) {
429 >                                        dinfo = readdir(dh);
430 >                                        if (dinfo == NULL) {
431 >                                                break;
432 >                                        }
433 >                                        snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name);
434 >                                        if (lstat(fullpathbuf, &lstatinfo) < 0) {
435 >                                                continue;
436 >                                        }
437 >        
438 >                                        if (lstatinfo.st_rdev == diskid) {
439 >                                                if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) {
440 >                                                        return NULL;
441 >                                                }
442 >                                                break;
443 >                                        }
444 >                                }
445 >                                closedir(dh);
446 >        
447 >                                if (diskio_stats_ptr->disk_name == NULL) {
448 >                                        if (sg_update_string(&diskio_stats_ptr->disk_name, di->psd_hw_path.psh_name) < 0) {
449                                                  return NULL;
450                                          }
433                                        break;
451                                  }
452                          }
436                        closedir(dh);
437
438                        if (diskio_stats_ptr->disk_name == NULL) {
439                                if (sg_update_string(&diskio_stats_ptr->disk_name, pstat_diskinfo.psd_hw_path.psh_name) < 0) {
440                                        return NULL;
441                                }
442                        }
453                  }
454 +                diskidx = pstat_diskinfo[num - 1].psd_idx + 1;
455          }
456   #endif
457   #ifdef OPENBSD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines