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> |
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; |
143 |
|
int len; |
144 |
|
int rc; |
145 |
|
time_t uptime; |
146 |
+ |
long tickspersec; |
147 |
|
#endif |
148 |
|
|
149 |
|
#ifdef LINUX |
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 |
|
|
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; |
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; |
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; |
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 |
|
} |