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.11 by tdb, Tue Apr 6 14:53:01 2004 UTC vs.
Revision 1.12 by tdb, Sun May 30 15:21:19 2004 UTC

# Line 23 | Line 23
23   ctypedef long time_t
24  
25   cdef extern from "statgrab.h":
26 <    ctypedef struct cpu_states_t:
26 >    ctypedef struct sg_cpu_stats:
27          long long user
28          long long kernel
29          long long idle
# Line 33 | Line 33 | cdef extern from "statgrab.h":
33          long long total
34          time_t systime
35  
36 <    ctypedef struct cpu_percent_t:
36 >    ctypedef struct sg_cpu_percents:
37          float user
38          float kernel
39          float idle
# Line 42 | Line 42 | cdef extern from "statgrab.h":
42          float nice
43          time_t time_taken
44  
45 <    ctypedef struct mem_stat_t:
45 >    ctypedef struct sg_mem_stats:
46          long long total
47          long long free
48          long long used
49          long long cache
50  
51 <    ctypedef struct load_stat_t:
51 >    ctypedef struct sg_load_stats:
52          double min1
53          double min5
54          double min15
55  
56 <    ctypedef struct user_stat_t:
56 >    ctypedef struct sg_user_stats:
57          char *name_list
58          int num_entries
59  
60 <    ctypedef struct swap_stat_t:
60 >    ctypedef struct sg_swap_stats:
61          long long total
62          long long used
63          long long free
64  
65 <    ctypedef struct general_stat_t:
65 >    ctypedef struct sg_host_info:
66          char *os_name
67          char *os_release
68          char *os_version
# Line 70 | Line 70 | cdef extern from "statgrab.h":
70          char *hostname
71          time_t uptime
72  
73 <    ctypedef struct disk_stat_t:
73 >    ctypedef struct sg_fs_stats:
74          char *device_name
75          char *fs_type
76          char *mnt_point
# Line 81 | Line 81 | cdef extern from "statgrab.h":
81          long long used_inodes
82          long long free_inodes
83  
84 <    ctypedef struct diskio_stat_t:
84 >    ctypedef struct sg_disk_io_stats:
85          char *disk_name
86          long long read_bytes
87          long long write_bytes
88          time_t systime
89  
90 <    ctypedef struct process_stat_t:
90 >    ctypedef struct sg_process_count:
91          int total
92          int running
93          int sleeping
94          int stopped
95          int zombie
96  
97 <    ctypedef struct network_stat_t:
97 >    ctypedef struct sg_network_io_stats:
98          char *interface_name
99          long long tx
100          long long rx
# Line 105 | Line 105 | cdef extern from "statgrab.h":
105          long long collisions
106          time_t systime
107  
108 <    ctypedef enum statgrab_duplex:
109 <        FULL_DUPLEX
110 <        HALF_DUPLEX
111 <        UNKNOWN_DUPLEX
108 >    ctypedef enum sg_iface_duplex:
109 >        SG_IFACE_DUPLEX_FULL
110 >        SG_IFACE_DUPLEX_HALF
111 >        SG_IFACE_DUPLEX_UNKNOWN
112  
113 <    ctypedef struct network_iface_stat_t:
113 >    ctypedef struct sg_network_iface_stats:
114          char *interface_name
115          int speed
116 <        statgrab_duplex dup
116 >        sg_iface_duplex dup
117          int up
118  
119 <    ctypedef struct page_stat_t:
119 >    ctypedef struct sg_page_stats:
120          long long pages_pagein
121          long long pages_pageout
122          time_t systime
123  
124 <    cdef extern cpu_states_t *get_cpu_totals()
125 <    cdef extern cpu_states_t *get_cpu_diff()
126 <    cdef extern cpu_percent_t *cpu_percent_usage()
127 <    cdef extern mem_stat_t *get_memory_stats()
128 <    cdef extern load_stat_t *get_load_stats()
129 <    cdef extern user_stat_t *get_user_stats()
130 <    cdef extern swap_stat_t *get_swap_stats()
131 <    cdef extern general_stat_t *get_general_stats()
132 <    cdef extern disk_stat_t *get_disk_stats(int *entries)
133 <    cdef extern diskio_stat_t *get_diskio_stats(int *entries)
134 <    cdef extern diskio_stat_t *get_diskio_stats_diff(int *entries)
135 <    cdef extern process_stat_t *get_process_stats()
136 <    cdef extern network_stat_t *get_network_stats(int *entries)
137 <    cdef extern network_stat_t *get_network_stats_diff(int *entries)
138 <    cdef extern network_iface_stat_t *get_network_iface_stats(int *entries)
139 <    cdef extern page_stat_t *get_page_stats()
140 <    cdef extern page_stat_t *get_page_stats_diff()
141 <    cdef extern int statgrab_init()
142 <    cdef extern int statgrab_drop_privileges()
124 >    cdef extern sg_cpu_stats *sg_get_cpu_stats()
125 >    cdef extern sg_cpu_stats *sg_get_cpu_stats_diff()
126 >    cdef extern sg_cpu_percents *sg_get_cpu_percents()
127 >    cdef extern sg_mem_stats *sg_get_mem_stats()
128 >    cdef extern sg_load_stats *sg_get_load_stats()
129 >    cdef extern sg_user_stats *sg_get_user_stats()
130 >    cdef extern sg_swap_stats *sg_get_swap_stats()
131 >    cdef extern sg_host_info *sg_get_host_info()
132 >    cdef extern sg_fs_stats *sg_get_fs_stats(int *entries)
133 >    cdef extern sg_disk_io_stats *sg_get_disk_io_stats(int *entries)
134 >    cdef extern sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries)
135 >    cdef extern sg_process_count *sg_get_process_count()
136 >    cdef extern sg_network_io_stats *sg_get_network_io_stats(int *entries)
137 >    cdef extern sg_network_io_stats *sg_get_network_io_stats_diff(int *entries)
138 >    cdef extern sg_network_iface_stats *sg_get_network_iface_stats(int *entries)
139 >    cdef extern sg_page_stats *sg_get_page_stats()
140 >    cdef extern sg_page_stats *sg_get_page_stats_diff()
141 >    cdef extern int sg_init()
142 >    cdef extern int sg_drop_privileges()
143  
144  
145 < py_FULL_DUPLEX = FULL_DUPLEX
146 < py_HALF_DUPLEX = HALF_DUPLEX
147 < py_UNKNOWN_DUPLEX = UNKNOWN_DUPLEX
145 > py_SG_IFACE_DUPLEX_FULL = SG_IFACE_DUPLEX_FULL
146 > py_SG_IFACE_DUPLEX_HALF = SG_IFACE_DUPLEX_HALF
147 > py_SG_IFACE_DUPLEX_UNKNOWN = SG_IFACE_DUPLEX_UNKNOWN
148  
149  
150   class Result:
# Line 164 | Line 164 | class StatgrabException(Exception):
164          return repr(self.value)
165  
166  
167 < def py_get_cpu_totals():
168 <    cdef cpu_states_t *s
169 <    s = get_cpu_totals()
167 > def py_sg_get_cpu_stats():
168 >    cdef sg_cpu_stats *s
169 >    s = sg_get_cpu_stats()
170      if s == NULL:
171 <        raise StatgrabException, 'get_cpu_totals() returned NULL'
171 >        raise StatgrabException, 'sg_get_cpu_stats() returned NULL'
172      return Result(
173          {'user': s.user,
174           'kernel': s.kernel,
# Line 181 | Line 181 | def py_get_cpu_totals():
181          }
182      )
183  
184 < def py_get_cpu_diff():
185 <    cdef cpu_states_t *s
186 <    s = get_cpu_diff()
184 > def py_sg_get_cpu_stats_diff():
185 >    cdef sg_cpu_stats *s
186 >    s = sg_get_cpu_stats_diff()
187      if s == NULL:
188 <        raise StatgrabException, 'get_cpu_diff() returned NULL'
188 >        raise StatgrabException, 'sg_get_cpu_stats_diff() returned NULL'
189      return Result(
190          {'user': s.user,
191           'kernel': s.kernel,
# Line 198 | Line 198 | def py_get_cpu_diff():
198          }
199      )
200  
201 < def py_cpu_percent_usage():
202 <    cdef cpu_percent_t *s
203 <    s = cpu_percent_usage()
201 > def py_sg_get_cpu_percents():
202 >    cdef sg_cpu_percents *s
203 >    s = sg_get_cpu_percents()
204      if s == NULL:
205 <        raise StatgrabException, 'cpu_percent_usage() returned NULL'
205 >        raise StatgrabException, 'sg_get_cpu_percents() returned NULL'
206      return Result(
207          {'user': s.user,
208           'kernel': s.kernel,
# Line 214 | Line 214 | def py_cpu_percent_usage():
214          }
215      )
216  
217 < def py_get_memory_stats():
218 <    cdef mem_stat_t *s
219 <    s = get_memory_stats()
217 > def py_sg_get_mem_stats():
218 >    cdef sg_mem_stats *s
219 >    s = sg_get_mem_stats()
220      if s == NULL:
221 <        raise StatgrabException, 'get_memory_stats() returned NULL'
221 >        raise StatgrabException, 'sg_get_mem_stats() returned NULL'
222      return Result(
223          {'total': s.total,
224           'used': s.used,
# Line 227 | Line 227 | def py_get_memory_stats():
227          }
228      )
229  
230 < def py_get_load_stats():
231 <    cdef load_stat_t *s
232 <    s = get_load_stats()
230 > def py_sg_get_load_stats():
231 >    cdef sg_load_stats *s
232 >    s = sg_get_load_stats()
233      if s == NULL:
234 <        raise StatgrabException, 'get_load_stats() returned NULL'
234 >        raise StatgrabException, 'sg_get_load_stats() returned NULL'
235      return Result(
236          {'min1': s.min1,
237           'min5': s.min5,
# Line 239 | Line 239 | def py_get_load_stats():
239          }
240      )
241  
242 < def py_get_user_stats():
243 <    cdef user_stat_t *s
244 <    s = get_user_stats()
242 > def py_sg_get_user_stats():
243 >    cdef sg_user_stats *s
244 >    s = sg_get_user_stats()
245      if s == NULL:
246 <        raise StatgrabException, 'get_user_stats() returned NULL'
246 >        raise StatgrabException, 'sg_get_user_stats() returned NULL'
247      return Result(
248          {'name_list': s.name_list,
249           'num_entries': s.num_entries,
250          }
251      )
252  
253 < def py_get_swap_stats():
254 <    cdef swap_stat_t *s
255 <    s = get_swap_stats()
253 > def py_sg_get_swap_stats():
254 >    cdef sg_swap_stats *s
255 >    s = sg_get_swap_stats()
256      if s == NULL:
257 <        raise StatgrabException, 'get_swap_stats() returned NULL'
257 >        raise StatgrabException, 'sg_get_swap_stats() returned NULL'
258      return Result(
259          {'total': s.total,
260           'used': s.used,
# Line 262 | Line 262 | def py_get_swap_stats():
262          }
263      )
264  
265 < def py_get_general_stats():
266 <    cdef general_stat_t *s
267 <    s = get_general_stats()
265 > def py_sg_get_host_info():
266 >    cdef sg_host_info *s
267 >    s = sg_get_host_info()
268      if s == NULL:
269 <        raise StatgrabException, 'get_general_stats() returned NULL'
269 >        raise StatgrabException, 'sg_get_host_info() returned NULL'
270      return Result(
271          {'os_name': s.os_name,
272           'os_release': s.os_release,
# Line 277 | Line 277 | def py_get_general_stats():
277          }
278      )
279  
280 < def py_get_disk_stats():
281 <    cdef disk_stat_t *s
280 > def py_sg_get_fs_stats():
281 >    cdef sg_fs_stats *s
282      cdef int entries
283 <    s = get_disk_stats(&entries)
283 >    s = sg_get_fs_stats(&entries)
284      if s == NULL:
285 <        raise StatgrabException, 'get_disk_stats() returned NULL'
285 >        raise StatgrabException, 'sg_get_fs_stats() returned NULL'
286      list = []
287      for i from 0 <= i < entries:
288          list.append(Result(
# Line 300 | Line 300 | def py_get_disk_stats():
300          s = s + 1
301      return list
302  
303 < def py_get_diskio_stats():
304 <    cdef diskio_stat_t *s
303 > def py_sg_get_disk_io_stats():
304 >    cdef sg_disk_io_stats *s
305      cdef int entries
306 <    s = get_diskio_stats(&entries)
306 >    s = sg_get_disk_io_stats(&entries)
307      if s == NULL:
308 <        raise StatgrabException, 'get_diskio_stats() returned NULL'
308 >        raise StatgrabException, 'sg_get_disk_io_stats() returned NULL'
309      list = []
310      for i from 0 <= i < entries:
311          list.append(Result(
# Line 318 | Line 318 | def py_get_diskio_stats():
318          s = s + 1
319      return list
320  
321 < def py_get_diskio_stats_diff():
322 <    cdef diskio_stat_t *s
321 > def py_sg_get_disk_io_stats_diff():
322 >    cdef sg_disk_io_stats *s
323      cdef int entries
324 <    s = get_diskio_stats_diff(&entries)
324 >    s = sg_get_disk_io_stats_diff(&entries)
325      if s == NULL:
326 <        raise StatgrabException, 'get_diskio_stats_diff() returned NULL'
326 >        raise StatgrabException, 'sg_get_disk_io_stats_diff() returned NULL'
327      list = []
328      for i from 0 <= i < entries:
329          list.append(Result(
# Line 336 | Line 336 | def py_get_diskio_stats_diff():
336          s = s + 1
337      return list
338  
339 < def py_get_process_stats():
340 <    cdef process_stat_t *s
341 <    s = get_process_stats()
339 > def py_sg_get_process_count():
340 >    cdef sg_process_count *s
341 >    s = sg_get_process_count()
342      if s == NULL:
343 <        raise StatgrabException, 'get_process_stats() returned NULL'
343 >        raise StatgrabException, 'sg_get_process_count() returned NULL'
344      return Result(
345          {'total': s.total,
346           'running': s.running,
# Line 350 | Line 350 | def py_get_process_stats():
350          }
351      )
352  
353 < def py_get_network_stats():
354 <    cdef network_stat_t *s
353 > def py_sg_get_network_io_stats():
354 >    cdef sg_network_io_stats *s
355      cdef int entries
356 <    s = get_network_stats(&entries)
356 >    s = sg_get_network_io_stats(&entries)
357      if s == NULL:
358 <        raise StatgrabException, 'get_network_stats() returned NULL'
358 >        raise StatgrabException, 'sg_get_network_io_stats() returned NULL'
359      list = []
360      for i from 0 <= i < entries:
361          list.append(Result(
# Line 373 | Line 373 | def py_get_network_stats():
373          s = s + 1
374      return list
375  
376 < def py_get_network_stats_diff():
377 <    cdef network_stat_t *s
376 > def py_sg_get_network_io_stats_diff():
377 >    cdef sg_network_io_stats *s
378      cdef int entries
379 <    s = get_network_stats_diff(&entries)
379 >    s = sg_get_network_io_stats_diff(&entries)
380      if s == NULL:
381 <        raise StatgrabException, 'get_network_stats_diff() returned NULL'
381 >        raise StatgrabException, 'sg_get_network_io_stats_diff() returned NULL'
382      list = []
383      for i from 0 <= i < entries:
384          list.append(Result(
# Line 396 | Line 396 | def py_get_network_stats_diff():
396          s = s + 1
397      return list
398  
399 < def py_get_network_iface_stats():
400 <    cdef network_iface_stat_t *s
399 > def py_sg_get_network_iface_stats():
400 >    cdef sg_network_iface_stats *s
401      cdef int entries
402 <    s = get_network_iface_stats(&entries)
402 >    s = sg_get_network_iface_stats(&entries)
403      if s == NULL:
404 <        raise StatgrabException, 'get_network_iface_stats() returned NULL'
404 >        raise StatgrabException, 'sg_get_network_iface_stats() returned NULL'
405      list = []
406      for i from 0 <= i < entries:
407          list.append(Result(
# Line 414 | Line 414 | def py_get_network_iface_stats():
414          s = s + 1
415      return list
416  
417 < def py_get_page_stats():
418 <    cdef page_stat_t *s
419 <    s = get_page_stats()
417 > def py_sg_get_page_stats():
418 >    cdef sg_page_stats *s
419 >    s = sg_get_page_stats()
420      if s == NULL:
421 <        raise StatgrabException, 'get_page_stats() returned NULL'
421 >        raise StatgrabException, 'sg_get_page_stats() returned NULL'
422      return Result(
423          {'pages_pagein': s.pages_pagein,
424           'pages_pageout': s.pages_pageout,
425          }
426      )
427  
428 < def py_get_page_stats_diff():
429 <    cdef page_stat_t *s
430 <    s = get_page_stats_diff()
428 > def py_sg_get_page_stats_diff():
429 >    cdef sg_page_stats *s
430 >    s = sg_get_page_stats_diff()
431      if s == NULL:
432 <        raise StatgrabException, 'get_page_stats_diff() returned NULL'
432 >        raise StatgrabException, 'sg_get_page_stats_diff() returned NULL'
433      return Result(
434          {'pages_pagein': s.pages_pagein,
435           'pages_pageout': s.pages_pageout,
436          }
437      )
438  
439 < def py_statgrab_init():
440 <    if statgrab_init() == 0:
439 > def py_sg_init():
440 >    if sg_init() == 0:
441          return True
442      else:
443          return False
444  
445 < def py_statgrab_drop_privileges():
446 <    if statgrab_drop_privileges() == 0:
445 > def py_sg_drop_privileges():
446 >    if sg_drop_privileges() == 0:
447          return True
448      else:
449          return False

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines