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.79 by tdb, Sat Nov 6 23:54:12 2004 UTC vs.
Revision 1.82 by tdb, Mon Oct 9 14:47:58 2006 UTC

# Line 33 | Line 33
33   #include <stdlib.h>
34   #include <sys/types.h>
35   #include <dirent.h>
36 #include <string.h>
36   #endif
37 + #include <string.h>
38  
39   #ifdef SOLARIS
40   #include <procfs.h>
# Line 78 | Line 78
78   #include <unistd.h>
79   #define PROCESS_BATCH 30
80   #endif
81 + #ifdef WIN32
82 + #include <windows.h>
83 + #include <psapi.h>
84 + #endif
85  
86   static void proc_state_init(sg_process_stats *s) {
87          s->process_name = NULL;
# Line 139 | Line 143 | sg_process_stats *sg_get_process_stats(int *entries){
143          int len;
144          int rc;
145          time_t uptime;
146 +        long tickspersec;
147   #endif
148  
149   #ifdef LINUX
# Line 251 | Line 256 | sg_process_stats *sg_get_process_stats(int *entries){
256  
257                  /* cpu */
258                  proc_state_ptr->cpu_percent = (100.0 * (utime + stime)) / ((uptime * 100.0) - starttime);
259 +                tickspersec = sysconf (_SC_CLK_TCK);
260 +                if (tickspersec < 0) {
261 +                        proc_state_ptr->time_spent = 0;
262 +                }
263 +                else {
264 +                        proc_state_ptr->time_spent = (utime + stime) / tickspersec;
265 +                }
266  
267                  fclose(f);
268  
# Line 755 | Line 767 | sg_process_stats *sg_get_process_stats(int *entries){
767          sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
768          return NULL;
769   #endif
770 + #ifdef WIN32
771 +        /* FIXME The data needed for this is probably do able with the
772 +         * "performance registry". Although using this appears to be a black
773 +         * art and closely guarded secret.
774 +         * This is not directly used in ihost, so not considered a priority */
775 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Win32");
776 +        return NULL;
777 + #endif
778  
779          *entries = proc_state_size;
780          return proc_state;
# Line 762 | Line 782 | sg_process_stats *sg_get_process_stats(int *entries){
782  
783   sg_process_count *sg_get_process_count() {
784          static sg_process_count process_stat;
785 + #ifndef WIN32
786          sg_process_stats *ps;
787          int ps_size, x;
788 + #else
789 +        DWORD aProcesses[1024];
790 +        DWORD cbNeeded;
791 + #endif
792  
793          process_stat.sleeping = 0;
794          process_stat.running = 0;
# Line 771 | Line 796 | sg_process_count *sg_get_process_count() {
796          process_stat.stopped = 0;
797          process_stat.total = 0;
798  
799 + #ifndef WIN32
800          ps = sg_get_process_stats(&ps_size);
801          if (ps == NULL) {
802                  return NULL;
# Line 799 | Line 825 | sg_process_count *sg_get_process_count() {
825          }
826  
827          process_stat.total = ps_size;
828 + #else
829 +        if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
830 +                return NULL;
831 +        process_stat.total = cbNeeded / sizeof(DWORD);
832 + #endif
833  
834          return &process_stat;
835   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines