ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/pystatgrab/_statgrab.pyx
Revision: 1.21
Committed: Mon Jun 16 21:06:49 2008 UTC (16 years, 5 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +10 -9 lines
Log Message:
Modify the Result class to extend dict. Then overload __getattr__ to still
allow it to be used as if it had attributes. This makes it easier to work
with the data (iteration over values, etc) and maintains compatibility.

File Contents

# User Rev Content
1 tdb 1.3 #
2 tdb 1.11 # i-scream pystatgrab
3 tdb 1.15 # http://www.i-scream.org/pystatgrab/
4 tdb 1.3 # Copyright (C) 2000-2004 i-scream
5     #
6     # This program is free software; you can redistribute it and/or
7     # modify it under the terms of the GNU General Public License
8     # as published by the Free Software Foundation; either version 2
9     # of the License, or (at your option) any later version.
10     #
11     # This program is distributed in the hope that it will be useful,
12     # but WITHOUT ANY WARRANTY; without even the implied warranty of
13     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     # GNU General Public License for more details.
15     #
16     # You should have received a copy of the GNU General Public License
17     # along with this program; if not, write to the Free Software
18     # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     #
20 tdb 1.21 # $Id: _statgrab.pyx,v 1.20 2007/07/13 22:26:19 tdb Exp $
21 tdb 1.3 #
22 tdb 1.1
23     ctypedef long time_t
24 tdb 1.14 ctypedef int pid_t
25     ctypedef int uid_t
26     ctypedef int gid_t
27 tdb 1.1
28     cdef extern from "statgrab.h":
29 tdb 1.13 cdef extern int sg_init()
30 tdb 1.20 cdef extern int sg_shutdown()
31     cdef extern int sg_snapshot()
32 tdb 1.13 cdef extern int sg_drop_privileges()
33    
34 tdb 1.14 ctypedef enum sg_error:
35     SG_ERROR_NONE = 0
36     SG_ERROR_ASPRINTF
37     SG_ERROR_DEVSTAT_GETDEVS
38     SG_ERROR_DEVSTAT_SELECTDEVS
39     SG_ERROR_ENOENT
40     SG_ERROR_GETIFADDRS
41     SG_ERROR_GETMNTINFO
42     SG_ERROR_GETPAGESIZE
43     SG_ERROR_KSTAT_DATA_LOOKUP
44     SG_ERROR_KSTAT_LOOKUP
45     SG_ERROR_KSTAT_OPEN
46     SG_ERROR_KSTAT_READ
47     SG_ERROR_KVM_GETSWAPINFO
48     SG_ERROR_KVM_OPENFILES
49     SG_ERROR_MALLOC
50     SG_ERROR_OPEN
51     SG_ERROR_OPENDIR
52     SG_ERROR_PARSE
53     SG_ERROR_SETEGID
54     SG_ERROR_SETEUID
55     SG_ERROR_SETMNTENT
56     SG_ERROR_SOCKET
57     SG_ERROR_SWAPCTL
58     SG_ERROR_SYSCONF
59     SG_ERROR_SYSCTL
60     SG_ERROR_SYSCTLBYNAME
61     SG_ERROR_SYSCTLNAMETOMIB
62     SG_ERROR_UNAME
63     SG_ERROR_UNSUPPORTED
64     SG_ERROR_XSW_VER_MISMATCH
65    
66     cdef extern void sg_set_error(sg_error code, char *arg)
67 tdb 1.15 cdef extern void sg_set_error_with_errno(sg_error code, char *arg)
68 tdb 1.14 cdef extern sg_error sg_get_error()
69     cdef extern char *sg_get_error_arg()
70 tdb 1.15 cdef extern int sg_get_error_errno()
71 tdb 1.14 cdef extern char *sg_str_error(sg_error code)
72    
73 tdb 1.13 ctypedef struct sg_host_info:
74     char *os_name
75     char *os_release
76     char *os_version
77     char *platform
78     char *hostname
79     time_t uptime
80    
81     cdef extern sg_host_info *sg_get_host_info()
82    
83 tdb 1.12 ctypedef struct sg_cpu_stats:
84 tdb 1.1 long long user
85     long long kernel
86     long long idle
87     long long iowait
88     long long swap
89     long long nice
90     long long total
91     time_t systime
92    
93 tdb 1.13 cdef extern sg_cpu_stats *sg_get_cpu_stats()
94     cdef extern sg_cpu_stats *sg_get_cpu_stats_diff()
95    
96 tdb 1.12 ctypedef struct sg_cpu_percents:
97 tdb 1.1 float user
98     float kernel
99     float idle
100     float iowait
101     float swap
102     float nice
103     time_t time_taken
104    
105 tdb 1.13 cdef extern sg_cpu_percents *sg_get_cpu_percents()
106    
107 tdb 1.12 ctypedef struct sg_mem_stats:
108 tdb 1.1 long long total
109     long long free
110     long long used
111     long long cache
112    
113 tdb 1.13 cdef extern sg_mem_stats *sg_get_mem_stats()
114    
115 tdb 1.12 ctypedef struct sg_load_stats:
116 tdb 1.1 double min1
117     double min5
118     double min15
119    
120 tdb 1.13 cdef extern sg_load_stats *sg_get_load_stats()
121    
122 tdb 1.12 ctypedef struct sg_user_stats:
123 tdb 1.1 char *name_list
124     int num_entries
125    
126 tdb 1.13 cdef extern sg_user_stats *sg_get_user_stats()
127    
128 tdb 1.12 ctypedef struct sg_swap_stats:
129 tdb 1.1 long long total
130     long long used
131     long long free
132    
133 tdb 1.13 cdef extern sg_swap_stats *sg_get_swap_stats()
134 tdb 1.1
135 tdb 1.12 ctypedef struct sg_fs_stats:
136 tdb 1.1 char *device_name
137     char *fs_type
138     char *mnt_point
139     long long size
140     long long used
141     long long avail
142     long long total_inodes
143     long long used_inodes
144     long long free_inodes
145 tdb 1.17 long long avail_inodes
146     long long io_size
147     long long block_size
148     long long total_blocks
149     long long free_blocks
150     long long used_blocks
151     long long avail_blocks
152 tdb 1.1
153 tdb 1.13 cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
154    
155 tdb 1.12 ctypedef struct sg_disk_io_stats:
156 tdb 1.1 char *disk_name
157     long long read_bytes
158     long long write_bytes
159     time_t systime
160    
161 tdb 1.13 cdef extern sg_disk_io_stats *sg_get_disk_io_stats(int *entries)
162     cdef extern sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries)
163 tdb 1.1
164 tdb 1.12 ctypedef struct sg_network_io_stats:
165 tdb 1.1 char *interface_name
166     long long tx
167     long long rx
168 tdb 1.9 long long ipackets
169     long long opackets
170     long long ierrors
171     long long oerrors
172     long long collisions
173 tdb 1.1 time_t systime
174    
175 tdb 1.13 cdef extern sg_network_io_stats *sg_get_network_io_stats(int *entries)
176     cdef extern sg_network_io_stats *sg_get_network_io_stats_diff(int *entries)
177    
178 tdb 1.12 ctypedef enum sg_iface_duplex:
179     SG_IFACE_DUPLEX_FULL
180     SG_IFACE_DUPLEX_HALF
181     SG_IFACE_DUPLEX_UNKNOWN
182 tdb 1.5
183 tdb 1.12 ctypedef struct sg_network_iface_stats:
184 tdb 1.5 char *interface_name
185     int speed
186 tdb 1.16 sg_iface_duplex duplex
187 tdb 1.8 int up
188 tdb 1.5
189 tdb 1.13 cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries)
190    
191 tdb 1.12 ctypedef struct sg_page_stats:
192 tdb 1.1 long long pages_pagein
193     long long pages_pageout
194     time_t systime
195    
196 tdb 1.12 cdef extern sg_page_stats *sg_get_page_stats()
197     cdef extern sg_page_stats *sg_get_page_stats_diff()
198 tdb 1.13
199 tdb 1.14 ctypedef enum sg_process_state:
200     SG_PROCESS_STATE_RUNNING
201     SG_PROCESS_STATE_SLEEPING
202     SG_PROCESS_STATE_STOPPED
203     SG_PROCESS_STATE_ZOMBIE
204     SG_PROCESS_STATE_UNKNOWN
205    
206     ctypedef struct sg_process_stats:
207     char *process_name
208     char *proctitle
209     pid_t pid
210     pid_t parent
211     pid_t pgid
212     uid_t uid
213     uid_t euid
214     gid_t gid
215     gid_t egid
216     unsigned long long proc_size
217     unsigned long long proc_resident
218     time_t time_spent
219     double cpu_percent
220     int nice
221     sg_process_state state
222    
223     cdef extern sg_process_stats *sg_get_process_stats(int *entries)
224    
225 tdb 1.13 ctypedef struct sg_process_count:
226     int total
227     int running
228     int sleeping
229     int stopped
230     int zombie
231    
232     cdef extern sg_process_count *sg_get_process_count()
233 tdb 1.12
234    
235 tdb 1.14 py_SG_ERROR_NONE = SG_ERROR_NONE
236     py_SG_ERROR_ASPRINTF = SG_ERROR_ASPRINTF
237     py_SG_ERROR_DEVSTAT_GETDEVS = SG_ERROR_DEVSTAT_GETDEVS
238     py_SG_ERROR_DEVSTAT_SELECTDEVS = SG_ERROR_DEVSTAT_SELECTDEVS
239     py_SG_ERROR_ENOENT = SG_ERROR_ENOENT
240     py_SG_ERROR_GETIFADDRS = SG_ERROR_GETIFADDRS
241     py_SG_ERROR_GETMNTINFO = SG_ERROR_GETMNTINFO
242     py_SG_ERROR_GETPAGESIZE = SG_ERROR_GETPAGESIZE
243     py_SG_ERROR_KSTAT_DATA_LOOKUP = SG_ERROR_KSTAT_DATA_LOOKUP
244     py_SG_ERROR_KSTAT_LOOKUP = SG_ERROR_KSTAT_LOOKUP
245     py_SG_ERROR_KSTAT_OPEN = SG_ERROR_KSTAT_OPEN
246     py_SG_ERROR_KSTAT_READ = SG_ERROR_KSTAT_READ
247     py_SG_ERROR_KVM_GETSWAPINFO = SG_ERROR_KVM_GETSWAPINFO
248     py_SG_ERROR_KVM_OPENFILES = SG_ERROR_KVM_OPENFILES
249     py_SG_ERROR_MALLOC = SG_ERROR_MALLOC
250     py_SG_ERROR_OPEN = SG_ERROR_OPEN
251     py_SG_ERROR_OPENDIR = SG_ERROR_OPENDIR
252     py_SG_ERROR_PARSE = SG_ERROR_PARSE
253     py_SG_ERROR_SETEGID = SG_ERROR_SETEGID
254     py_SG_ERROR_SETEUID = SG_ERROR_SETEUID
255     py_SG_ERROR_SETMNTENT = SG_ERROR_SETMNTENT
256     py_SG_ERROR_SOCKET = SG_ERROR_SOCKET
257     py_SG_ERROR_SWAPCTL = SG_ERROR_SWAPCTL
258     py_SG_ERROR_SYSCONF = SG_ERROR_SYSCONF
259     py_SG_ERROR_SYSCTL = SG_ERROR_SYSCTL
260     py_SG_ERROR_SYSCTLBYNAME = SG_ERROR_SYSCTLBYNAME
261     py_SG_ERROR_SYSCTLNAMETOMIB = SG_ERROR_SYSCTLNAMETOMIB
262     py_SG_ERROR_UNAME = SG_ERROR_UNAME
263     py_SG_ERROR_UNSUPPORTED = SG_ERROR_UNSUPPORTED
264     py_SG_ERROR_XSW_VER_MISMATCH = SG_ERROR_XSW_VER_MISMATCH
265    
266 tdb 1.12 py_SG_IFACE_DUPLEX_FULL = SG_IFACE_DUPLEX_FULL
267     py_SG_IFACE_DUPLEX_HALF = SG_IFACE_DUPLEX_HALF
268     py_SG_IFACE_DUPLEX_UNKNOWN = SG_IFACE_DUPLEX_UNKNOWN
269 tdb 1.1
270 tdb 1.14 py_SG_PROCESS_STATE_RUNNING = SG_PROCESS_STATE_RUNNING
271     py_SG_PROCESS_STATE_SLEEPING = SG_PROCESS_STATE_SLEEPING
272     py_SG_PROCESS_STATE_STOPPED = SG_PROCESS_STATE_STOPPED
273     py_SG_PROCESS_STATE_ZOMBIE = SG_PROCESS_STATE_ZOMBIE
274     py_SG_PROCESS_STATE_UNKNOWN = SG_PROCESS_STATE_UNKNOWN
275    
276 tdb 1.1
277 tdb 1.21 class Result(dict):
278 tdb 1.2 def __init__(self, attrs):
279 tdb 1.21 self.attrs = attrs # to maintain compatibility
280     super(Result, self).__init__(attrs)
281    
282     def __getattr__(self, item):
283     try:
284     return self.__getitem__(item)
285     except KeyError:
286     raise AttributeError(item)
287 tdb 1.2
288 tdb 1.4 class StatgrabException(Exception):
289 tdb 1.3 def __init__(self, value):
290     self.value = value
291     def __str__(self):
292     return repr(self.value)
293    
294 tdb 1.2
295 tdb 1.13 def py_sg_init():
296     if sg_init() == 0:
297     return True
298     else:
299     return False
300    
301 tdb 1.19 def py_sg_shutdown():
302     if sg_shutdown() == 0:
303     return True
304     else:
305     return False
306    
307     def py_sg_snapshot():
308     if sg_snapshot() == 0:
309     return True
310     else:
311     return False
312    
313 tdb 1.13 def py_sg_drop_privileges():
314     if sg_drop_privileges() == 0:
315     return True
316     else:
317     return False
318    
319 tdb 1.14 def py_sg_set_error(code, arg):
320     sg_set_error(code, arg)
321    
322 tdb 1.15 def py_sg_set_error_with_errno(code, arg):
323     sg_set_error_with_errno(code, arg)
324    
325 tdb 1.14 def py_sg_get_error():
326     cdef sg_error s
327     s = sg_get_error()
328     return s
329    
330     def py_sg_get_error_arg():
331     s = sg_get_error_arg()
332 tdb 1.15 return s
333    
334     def py_sg_get_error_errno():
335     s = sg_get_error_errno()
336 tdb 1.14 return s
337    
338     def py_sg_str_error(code):
339     s = sg_str_error(code)
340     return s
341    
342 tdb 1.13 def py_sg_get_host_info():
343     cdef sg_host_info *s
344     s = sg_get_host_info()
345     if s == NULL:
346     raise StatgrabException, 'sg_get_host_info() returned NULL'
347     return Result(
348     {'os_name': s.os_name,
349     'os_release': s.os_release,
350     'os_version': s.os_version,
351     'platform': s.platform,
352     'hostname': s.hostname,
353     'uptime': s.uptime,
354     }
355     )
356    
357 tdb 1.12 def py_sg_get_cpu_stats():
358     cdef sg_cpu_stats *s
359     s = sg_get_cpu_stats()
360 tdb 1.3 if s == NULL:
361 tdb 1.12 raise StatgrabException, 'sg_get_cpu_stats() returned NULL'
362 tdb 1.2 return Result(
363     {'user': s.user,
364     'kernel': s.kernel,
365     'idle': s.idle,
366     'iowait': s.iowait,
367     'swap': s.swap,
368     'nice': s.nice,
369     'total': s.total,
370     'systime': s.systime,
371     }
372     )
373 tdb 1.1
374 tdb 1.12 def py_sg_get_cpu_stats_diff():
375     cdef sg_cpu_stats *s
376     s = sg_get_cpu_stats_diff()
377 tdb 1.3 if s == NULL:
378 tdb 1.12 raise StatgrabException, 'sg_get_cpu_stats_diff() returned NULL'
379 tdb 1.2 return Result(
380     {'user': s.user,
381     'kernel': s.kernel,
382     'idle': s.idle,
383     'iowait': s.iowait,
384     'swap': s.swap,
385     'nice': s.nice,
386     'total': s.total,
387     'systime': s.systime,
388     }
389     )
390 tdb 1.1
391 tdb 1.12 def py_sg_get_cpu_percents():
392     cdef sg_cpu_percents *s
393     s = sg_get_cpu_percents()
394 tdb 1.3 if s == NULL:
395 tdb 1.12 raise StatgrabException, 'sg_get_cpu_percents() returned NULL'
396 tdb 1.2 return Result(
397     {'user': s.user,
398     'kernel': s.kernel,
399     'idle': s.idle,
400     'iowait': s.iowait,
401     'swap': s.swap,
402     'nice': s.nice,
403     'time_taken': s.time_taken,
404     }
405     )
406 tdb 1.1
407 tdb 1.12 def py_sg_get_mem_stats():
408     cdef sg_mem_stats *s
409     s = sg_get_mem_stats()
410 tdb 1.3 if s == NULL:
411 tdb 1.12 raise StatgrabException, 'sg_get_mem_stats() returned NULL'
412 tdb 1.2 return Result(
413     {'total': s.total,
414     'used': s.used,
415     'free': s.free,
416     'cache': s.cache,
417     }
418     )
419 tdb 1.1
420 tdb 1.12 def py_sg_get_load_stats():
421     cdef sg_load_stats *s
422     s = sg_get_load_stats()
423 tdb 1.3 if s == NULL:
424 tdb 1.12 raise StatgrabException, 'sg_get_load_stats() returned NULL'
425 tdb 1.2 return Result(
426     {'min1': s.min1,
427     'min5': s.min5,
428     'min15': s.min15,
429     }
430     )
431 tdb 1.1
432 tdb 1.12 def py_sg_get_user_stats():
433     cdef sg_user_stats *s
434     s = sg_get_user_stats()
435 tdb 1.3 if s == NULL:
436 tdb 1.12 raise StatgrabException, 'sg_get_user_stats() returned NULL'
437 tdb 1.2 return Result(
438     {'name_list': s.name_list,
439     'num_entries': s.num_entries,
440     }
441     )
442 tdb 1.1
443 tdb 1.12 def py_sg_get_swap_stats():
444     cdef sg_swap_stats *s
445     s = sg_get_swap_stats()
446 tdb 1.3 if s == NULL:
447 tdb 1.12 raise StatgrabException, 'sg_get_swap_stats() returned NULL'
448 tdb 1.2 return Result(
449     {'total': s.total,
450     'used': s.used,
451     'free': s.free,
452     }
453     )
454 tdb 1.1
455 tdb 1.12 def py_sg_get_fs_stats():
456     cdef sg_fs_stats *s
457 tdb 1.1 cdef int entries
458 tdb 1.12 s = sg_get_fs_stats(&entries)
459 tdb 1.3 if s == NULL:
460 tdb 1.12 raise StatgrabException, 'sg_get_fs_stats() returned NULL'
461 tdb 1.6 list = []
462 tdb 1.1 for i from 0 <= i < entries:
463 tdb 1.2 list.append(Result(
464     {'device_name': s.device_name,
465     'fs_type': s.fs_type,
466     'mnt_point': s.mnt_point,
467     'size': s.size,
468     'used': s.used,
469     'avail': s.avail,
470     'total_inodes': s.total_inodes,
471     'used_inodes': s.used_inodes,
472     'free_inodes': s.free_inodes,
473 tdb 1.17 'avail_inodes': s.avail_inodes,
474     'io_size': s.io_size,
475     'block_size': s.block_size,
476     'total_blocks': s.total_blocks,
477     'free_blocks': s.free_blocks,
478     'used_blocks': s.used_blocks,
479     'avail_blocks': s.avail_blocks,
480 tdb 1.2 }
481     ))
482 tdb 1.1 s = s + 1
483     return list
484    
485 tdb 1.12 def py_sg_get_disk_io_stats():
486     cdef sg_disk_io_stats *s
487 tdb 1.1 cdef int entries
488 tdb 1.12 s = sg_get_disk_io_stats(&entries)
489 tdb 1.3 if s == NULL:
490 tdb 1.12 raise StatgrabException, 'sg_get_disk_io_stats() returned NULL'
491 tdb 1.6 list = []
492 tdb 1.1 for i from 0 <= i < entries:
493 tdb 1.2 list.append(Result(
494     {'disk_name': s.disk_name,
495     'read_bytes': s.read_bytes,
496     'write_bytes': s.write_bytes,
497     'systime': s.systime,
498     }
499     ))
500 tdb 1.1 s = s + 1
501     return list
502    
503 tdb 1.12 def py_sg_get_disk_io_stats_diff():
504     cdef sg_disk_io_stats *s
505 tdb 1.1 cdef int entries
506 tdb 1.12 s = sg_get_disk_io_stats_diff(&entries)
507 tdb 1.3 if s == NULL:
508 tdb 1.12 raise StatgrabException, 'sg_get_disk_io_stats_diff() returned NULL'
509 tdb 1.6 list = []
510 tdb 1.1 for i from 0 <= i < entries:
511 tdb 1.2 list.append(Result(
512     {'disk_name': s.disk_name,
513     'read_bytes': s.read_bytes,
514     'write_bytes': s.write_bytes,
515     'systime': s.systime,
516     }
517     ))
518 tdb 1.1 s = s + 1
519     return list
520    
521 tdb 1.12 def py_sg_get_network_io_stats():
522     cdef sg_network_io_stats *s
523 tdb 1.1 cdef int entries
524 tdb 1.12 s = sg_get_network_io_stats(&entries)
525 tdb 1.3 if s == NULL:
526 tdb 1.12 raise StatgrabException, 'sg_get_network_io_stats() returned NULL'
527 tdb 1.6 list = []
528 tdb 1.1 for i from 0 <= i < entries:
529 tdb 1.2 list.append(Result(
530     {'interface_name': s.interface_name,
531     'tx': s.tx,
532     'rx': s.rx,
533 tdb 1.9 'ipackets': s.ipackets,
534     'opackets': s.opackets,
535     'ierrors': s.ierrors,
536     'oerrors': s.oerrors,
537     'collisions': s.collisions,
538 tdb 1.2 'systime': s.systime,
539     }
540     ))
541 tdb 1.1 s = s + 1
542     return list
543    
544 tdb 1.12 def py_sg_get_network_io_stats_diff():
545     cdef sg_network_io_stats *s
546 tdb 1.1 cdef int entries
547 tdb 1.12 s = sg_get_network_io_stats_diff(&entries)
548 tdb 1.3 if s == NULL:
549 tdb 1.12 raise StatgrabException, 'sg_get_network_io_stats_diff() returned NULL'
550 tdb 1.6 list = []
551 tdb 1.1 for i from 0 <= i < entries:
552 tdb 1.2 list.append(Result(
553     {'interface_name': s.interface_name,
554     'tx': s.tx,
555     'rx': s.rx,
556 tdb 1.9 'ipackets': s.ipackets,
557     'opackets': s.opackets,
558     'ierrors': s.ierrors,
559     'oerrors': s.oerrors,
560     'collisions': s.collisions,
561 tdb 1.2 'systime': s.systime,
562 tdb 1.5 }
563     ))
564     s = s + 1
565     return list
566    
567 tdb 1.12 def py_sg_get_network_iface_stats():
568     cdef sg_network_iface_stats *s
569 tdb 1.5 cdef int entries
570 tdb 1.12 s = sg_get_network_iface_stats(&entries)
571 tdb 1.5 if s == NULL:
572 tdb 1.12 raise StatgrabException, 'sg_get_network_iface_stats() returned NULL'
573 tdb 1.6 list = []
574 tdb 1.5 for i from 0 <= i < entries:
575     list.append(Result(
576     {'interface_name': s.interface_name,
577     'speed': s.speed,
578 tdb 1.16 'duplex': s.duplex,
579 tdb 1.8 'up' : s.up,
580 tdb 1.2 }
581     ))
582 tdb 1.1 s = s + 1
583     return list
584    
585 tdb 1.12 def py_sg_get_page_stats():
586     cdef sg_page_stats *s
587     s = sg_get_page_stats()
588 tdb 1.3 if s == NULL:
589 tdb 1.12 raise StatgrabException, 'sg_get_page_stats() returned NULL'
590 tdb 1.2 return Result(
591     {'pages_pagein': s.pages_pagein,
592     'pages_pageout': s.pages_pageout,
593     }
594     )
595 tdb 1.1
596 tdb 1.12 def py_sg_get_page_stats_diff():
597     cdef sg_page_stats *s
598     s = sg_get_page_stats_diff()
599 tdb 1.3 if s == NULL:
600 tdb 1.12 raise StatgrabException, 'sg_get_page_stats_diff() returned NULL'
601 tdb 1.2 return Result(
602     {'pages_pagein': s.pages_pagein,
603     'pages_pageout': s.pages_pageout,
604     }
605     )
606 tdb 1.14
607     def py_sg_get_process_stats():
608     cdef sg_process_stats *s
609     cdef int entries
610     s = sg_get_process_stats(&entries)
611     if s == NULL:
612     raise StatgrabException, 'sg_get_process_stats() returned NULL'
613     list = []
614     for i from 0 <= i < entries:
615 ats 1.18 if s.process_name is NULL:
616     process_name = ''
617     else:
618     process_name = s.process_name
619     if s.proctitle is NULL:
620     proctitle = ''
621     else:
622     proctitle = s.proctitle
623 tdb 1.14 list.append(Result(
624 ats 1.18 {'process_name': process_name,
625     'proctitle' : proctitle,
626 tdb 1.14 'pid' : s.pid,
627     'parent' : s.parent,
628     'pgid' : s.pgid,
629     'uid' : s.uid,
630     'euid' : s.euid,
631     'gid' : s.gid,
632     'egid' : s.egid,
633     'proc_size' : s.proc_size,
634     'proc_resident' : s.proc_resident,
635     'time_spent' : s.time_spent,
636     'cpu_percent' : s.cpu_percent,
637     'nice' : s.nice,
638     'state' : s.state,
639     }
640     ))
641     s = s + 1
642     return list
643 tdb 1.1
644 tdb 1.13 def py_sg_get_process_count():
645     cdef sg_process_count *s
646     s = sg_get_process_count()
647     if s == NULL:
648     raise StatgrabException, 'sg_get_process_count() returned NULL'
649     return Result(
650     {'total': s.total,
651     'running': s.running,
652     'sleeping': s.sleeping,
653     'stopped': s.stopped,
654     'zombie': s.zombie,
655     }
656     )