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

Comparing projects/libstatgrab/src/libstatgrab/process_stats.c (file contents):
Revision 1.64 by pajs, Wed Apr 7 15:46:34 2004 UTC vs.
Revision 1.69 by ats, Thu Apr 8 13:16:05 2004 UTC

# Line 130 | Line 130 | sg_process_stats *sg_get_process_stats(int *entries){
130  
131   #ifdef LINUX
132          if ((f=fopen("/proc/uptime", "r")) == NULL) {
133 +                sg_set_error(SG_ERROR_OPEN, "/proc/uptime");
134                  return NULL;
135          }
136          if((fscanf(f,"%lu %*d",&uptime)) != 1){
137 +                sg_set_error(SG_ERROR_PARSE, NULL);
138                  return NULL;
139          }
140          fclose(f);
141   #endif
142  
143          if((proc_dir=opendir(PROC_LOCATION))==NULL){
144 +                sg_set_error(SG_ERROR_OPENDIR, PROC_LOCATION);
145                  return NULL;
146          }
147  
# Line 303 | Line 306 | sg_process_stats *sg_get_process_stats(int *entries){
306          mib[2] = KERN_PROC_ALL;
307  
308          if(sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
309 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_PROC.KERN_PROC_ALL");
310                  return NULL;
311          }
312  
# Line 315 | Line 319 | sg_process_stats *sg_get_process_stats(int *entries){
319          memset(kp_stats, 0, size);
320  
321          if(sysctl(mib, 3, kp_stats, &size, NULL, 0) < 0) {
322 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_PROC.KERN_PROC_ALL");
323                  free(kp_stats);
324                  return NULL;
325          }
# Line 360 | Line 365 | sg_process_stats *sg_get_process_stats(int *entries){
365  
366   #ifdef FREEBSD5
367                  if(sysctlbyname("kern.ps_arg_cache_limit", &buflen, &size, NULL, 0) < 0) {
368 +                        sg_set_error(SG_ERROR_SYSCTLBYNAME, "kern.ps_arg_cache_limit");
369                          return NULL;
370                  }
371   #else
# Line 369 | Line 375 | sg_process_stats *sg_get_process_stats(int *entries){
375                  mib[1] = KERN_ARGMAX;
376  
377                  if(sysctl(mib, 2, &buflen, &size, NULL, 0) < 0) {
378 +                        sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_ARGMAX");
379                          return NULL;
380                  }
381   #endif
# Line 520 | Line 527 | sg_process_stats *sg_get_process_stats(int *entries){
527                          mib[4] = 0;
528  
529                          if(sysctl(mib, 5, NULL, &size, NULL, 0) < 0) {
530 +                                sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_LWP.pid.structsize.0");
531                                  return NULL;
532                          }
533  
# Line 532 | Line 540 | sg_process_stats *sg_get_process_stats(int *entries){
540                          }
541  
542                          if(sysctl(mib, 5, kl_stats, &size, NULL, 0) < 0) {
543 +                                sg_set_error(SG_ERROR_SYSCTL, "CTL_KERN.KERN_LWP.pid.structsize.buffersize");
544                                  return NULL;
545                          }
546                  }
# Line 616 | Line 625 | sg_process_stats *sg_get_process_stats(int *entries){
625   #endif
626  
627   #ifdef CYGWIN
628 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
629          return NULL;
630   #endif
631  
# Line 665 | Line 675 | sg_process_count *sg_get_process_count() {
675  
676          return &process_stat;
677   }
678 +
679 + int sg_process_compare_pid(const void *va, const void *vb) {
680 +        const sg_process_stats *a = (sg_process_stats *)va;
681 +        const sg_process_stats *b = (sg_process_stats *)vb;
682 +
683 +        if (a->pid < b->pid) {
684 +                return -1;
685 +        } else if (a->pid == b->pid) {
686 +                return 0;
687 +        } else {
688 +                return 1;
689 +        }
690 + }
691 +
692 + int sg_process_compare_uid(const void *va, const void *vb) {
693 +        const sg_process_stats *a = (sg_process_stats *)va;
694 +        const sg_process_stats *b = (sg_process_stats *)vb;
695 +
696 +        if (a->uid < b->uid) {
697 +                return -1;
698 +        } else if (a->uid == b->uid) {
699 +                return 0;
700 +        } else {
701 +                return 1;
702 +        }
703 + }
704 +
705 + int sg_process_compare_gid(const void *va, const void *vb) {
706 +        const sg_process_stats *a = (sg_process_stats *)va;
707 +        const sg_process_stats *b = (sg_process_stats *)vb;
708 +
709 +        if (a->gid < b->gid) {
710 +                return -1;
711 +        } else if (a->gid == b->gid) {
712 +                return 0;
713 +        } else {
714 +                return 1;
715 +        }
716 + }
717 +
718 + int sg_process_compare_size(const void *va, const void *vb) {
719 +        const sg_process_stats *a = (sg_process_stats *)va;
720 +        const sg_process_stats *b = (sg_process_stats *)vb;
721 +
722 +        if (a->proc_size < b->proc_size) {
723 +                return -1;
724 +        } else if (a->proc_size == b->proc_size) {
725 +                return 0;
726 +        } else {
727 +                return 1;
728 +        }
729 + }
730 +
731 + int sg_process_compare_res(const void *va, const void *vb) {
732 +        const sg_process_stats *a = (sg_process_stats *)va;
733 +        const sg_process_stats *b = (sg_process_stats *)vb;
734 +
735 +        if (a->proc_resident < b->proc_resident) {
736 +                return -1;
737 +        } else if (a->proc_resident == b->proc_resident) {
738 +                return 0;
739 +        } else {
740 +                return 1;
741 +        }
742 + }
743 +
744 + int sg_process_compare_cpu(const void *va, const void *vb) {
745 +        const sg_process_stats *a = (sg_process_stats *)va;
746 +        const sg_process_stats *b = (sg_process_stats *)vb;
747 +
748 +        if (a->cpu_percent < b->cpu_percent) {
749 +                return -1;
750 +        } else if (a->cpu_percent == b->cpu_percent) {
751 +                return 0;
752 +        } else {
753 +                return 1;
754 +        }
755 + }
756 +
757 + int sg_process_compare_time(const void *va, const void *vb) {
758 +        const sg_process_stats *a = (sg_process_stats *)va;
759 +        const sg_process_stats *b = (sg_process_stats *)vb;
760 +
761 +        if (a->time_spent < b->time_spent) {
762 +                return -1;
763 +        } else if (a->time_spent == b->time_spent) {
764 +                return 0;
765 +        } else {
766 +                return 1;
767 +        }
768 + }
769 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines