ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/pystatgrab/_statgrab.pyx
(Generate patch)

Comparing projects/pystatgrab/_statgrab.pyx (file contents):
Revision 1.13 by tdb, Sun May 30 15:32:28 2004 UTC vs.
Revision 1.21 by tdb, Mon Jun 16 21:06:49 2008 UTC

# Line 1 | Line 1
1   #
2   # i-scream pystatgrab
3 < # http://www.i-scream.org
3 > # http://www.i-scream.org/pystatgrab/
4   # Copyright (C) 2000-2004 i-scream
5   #
6   # This program is free software; you can redistribute it and/or
# Line 21 | Line 21
21   #
22  
23   ctypedef long time_t
24 + ctypedef int pid_t
25 + ctypedef int uid_t
26 + ctypedef int gid_t
27  
28   cdef extern from "statgrab.h":
29      cdef extern int sg_init()
30 +    cdef extern int sg_shutdown()
31 +    cdef extern int sg_snapshot()
32      cdef extern int sg_drop_privileges()
33  
34 +    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 +    cdef extern void sg_set_error_with_errno(sg_error code, char *arg)
68 +    cdef extern sg_error sg_get_error()
69 +    cdef extern char *sg_get_error_arg()
70 +    cdef extern int sg_get_error_errno()
71 +    cdef extern char *sg_str_error(sg_error code)
72 +
73      ctypedef struct sg_host_info:
74          char *os_name
75          char *os_release
# Line 98 | Line 142 | cdef extern from "statgrab.h":
142          long long total_inodes
143          long long used_inodes
144          long long free_inodes
145 +        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  
153      cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
154  
# Line 132 | Line 183 | cdef extern from "statgrab.h":
183      ctypedef struct sg_network_iface_stats:
184          char *interface_name
185          int speed
186 <        sg_iface_duplex dup
186 >        sg_iface_duplex duplex
187          int up
188  
189      cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries)
# Line 145 | Line 196 | cdef extern from "statgrab.h":
196      cdef extern sg_page_stats *sg_get_page_stats()
197      cdef extern sg_page_stats *sg_get_page_stats_diff()
198  
199 +    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      ctypedef struct sg_process_count:
226          int total
227          int running
# Line 155 | Line 232 | cdef extern from "statgrab.h":
232      cdef extern sg_process_count *sg_get_process_count()
233  
234  
235 + 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   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  
270 + 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 < class Result:
276 >
277 > class Result(dict):
278      def __init__(self, attrs):
279 <        self.attrs = attrs
280 <        for attr in attrs:
167 <            setattr(self, attr, attrs[attr])
168 <    def __getitem__(self, item):
169 <        return getattr(self, item)
170 <    def __repr__(self):
171 <        return str(self.attrs)
279 >        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 +
288   class StatgrabException(Exception):
289      def __init__(self, value):
290          self.value = value
# Line 183 | Line 298 | def py_sg_init():
298      else:
299          return False
300  
301 + 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   def py_sg_drop_privileges():
314      if sg_drop_privileges() == 0:
315          return True
316      else:
317          return False
318  
319 + def py_sg_set_error(code, arg):
320 +    sg_set_error(code, arg)
321 +
322 + def py_sg_set_error_with_errno(code, arg):
323 +    sg_set_error_with_errno(code, arg)
324 +
325 + 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 +    return s
333 +
334 + def py_sg_get_error_errno():
335 +    s = sg_get_error_errno()
336 +    return s
337 +
338 + def py_sg_str_error(code):
339 +    s = sg_str_error(code)
340 +    return s
341 +
342   def py_sg_get_host_info():
343      cdef sg_host_info *s
344      s = sg_get_host_info()
# Line 320 | Line 470 | def py_sg_get_fs_stats():
470               'total_inodes': s.total_inodes,
471               'used_inodes': s.used_inodes,
472               'free_inodes': s.free_inodes,
473 +             '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              }
481          ))
482          s = s + 1
# Line 418 | Line 575 | def py_sg_get_network_iface_stats():
575          list.append(Result(
576              {'interface_name': s.interface_name,
577               'speed': s.speed,
578 <             'dup': s.dup,
578 >             'duplex': s.duplex,
579               'up' : s.up,
580              }
581          ))
# Line 446 | Line 603 | def py_sg_get_page_stats_diff():
603           'pages_pageout': s.pages_pageout,
604          }
605      )
606 +
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 +        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 +        list.append(Result(
624 +            {'process_name': process_name,
625 +             'proctitle' : proctitle,
626 +             '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  
644   def py_sg_get_process_count():
645      cdef sg_process_count *s

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines