sigar-test 0.7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/NOTICE +117 -0
  4. data/README +2 -0
  5. data/Rakefile +105 -0
  6. data/bindings/SigarBuild.pm +301 -0
  7. data/bindings/SigarWrapper.pm +3025 -0
  8. data/bindings/ruby/extconf.rb +131 -0
  9. data/bindings/ruby/rbsigar.c +888 -0
  10. data/include/sigar.h +984 -0
  11. data/include/sigar_fileinfo.h +157 -0
  12. data/include/sigar_format.h +65 -0
  13. data/include/sigar_getline.h +18 -0
  14. data/include/sigar_log.h +80 -0
  15. data/include/sigar_private.h +429 -0
  16. data/include/sigar_ptql.h +53 -0
  17. data/include/sigar_util.h +197 -0
  18. data/src/os/aix/aix_sigar.c +2168 -0
  19. data/src/os/aix/sigar_os.h +73 -0
  20. data/src/os/darwin/Info.plist.in +27 -0
  21. data/src/os/darwin/darwin_sigar.c +3718 -0
  22. data/src/os/darwin/sigar_os.h +80 -0
  23. data/src/os/hpux/hpux_sigar.c +1361 -0
  24. data/src/os/hpux/sigar_os.h +49 -0
  25. data/src/os/linux/linux_sigar.c +2810 -0
  26. data/src/os/linux/sigar_os.h +82 -0
  27. data/src/os/solaris/get_mib2.c +321 -0
  28. data/src/os/solaris/get_mib2.h +127 -0
  29. data/src/os/solaris/kstats.c +181 -0
  30. data/src/os/solaris/procfs.c +97 -0
  31. data/src/os/solaris/sigar_os.h +224 -0
  32. data/src/os/solaris/solaris_sigar.c +2732 -0
  33. data/src/os/win32/peb.c +212 -0
  34. data/src/os/win32/sigar.rc.in +40 -0
  35. data/src/os/win32/sigar_os.h +685 -0
  36. data/src/os/win32/sigar_pdh.h +47 -0
  37. data/src/os/win32/win32_sigar.c +4109 -0
  38. data/src/sigar.c +2444 -0
  39. data/src/sigar_cache.c +253 -0
  40. data/src/sigar_fileinfo.c +815 -0
  41. data/src/sigar_format.c +696 -0
  42. data/src/sigar_getline.c +1849 -0
  43. data/src/sigar_ptql.c +1976 -0
  44. data/src/sigar_signal.c +216 -0
  45. data/src/sigar_util.c +1060 -0
  46. data/src/sigar_version.c.in +22 -0
  47. data/src/sigar_version_autoconf.c.in +22 -0
  48. data/version.properties +11 -0
  49. metadata +91 -0
@@ -0,0 +1,3025 @@
1
+ #
2
+ # Copyright (c) 2007-2009 Hyperic, Inc.
3
+ # Copyright (c) 2009 SpringSource, Inc.
4
+ # Copyright (c) 2009-2010 VMware, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ #extension source generator for all bindings
20
+ package SigarWrapper;
21
+
22
+ use strict;
23
+ use Cwd;
24
+ use Exporter;
25
+ use File::Path;
26
+ use IO::File ();
27
+
28
+ use vars qw(@ISA @EXPORT);
29
+ @ISA = qw(Exporter);
30
+ @EXPORT = qw(generate);
31
+
32
+ my %platforms = (
33
+ A => "AIX",
34
+ D => "Darwin",
35
+ F => "FreeBSD",
36
+ H => "HPUX",
37
+ L => "Linux",
38
+ S => "Solaris",
39
+ W => "Win32",
40
+ );
41
+
42
+ my %has_name_arg = map { $_, 1 } qw(FileSystemUsage DiskUsage
43
+ FileAttrs DirStat DirUsage
44
+ NetInterfaceConfig NetInterfaceStat);
45
+
46
+
47
+ my %proc_no_arg = map { $_, 1 } qw(stat);
48
+
49
+ my %get_not_impl = map { $_, 1 } qw(net_address net_route net_connection net_stat cpu_perc
50
+ arp who cpu_info file_system); #list funcs only
51
+
52
+ sub supported_platforms {
53
+ my $p = shift;
54
+ return 'Undocumented' unless $p;
55
+ if ($p eq '*') {
56
+ return 'All';
57
+ }
58
+
59
+ my @platforms;
60
+ for (split //, $p) {
61
+ push @platforms, $platforms{$_};
62
+ }
63
+
64
+ return join ", ", @platforms;
65
+ }
66
+
67
+ sub hash {
68
+ return unpack("%32C*", shift) % 65535;
69
+ }
70
+
71
+ my $nfs_v2 = [
72
+ {
73
+ name => 'null', type => 'Long',
74
+ },
75
+ {
76
+ name => 'getattr', type => 'Long',
77
+ },
78
+ {
79
+ name => 'setattr', type => 'Long',
80
+ },
81
+ {
82
+ name => 'root', type => 'Long',
83
+ },
84
+ {
85
+ name => 'lookup', type => 'Long',
86
+ },
87
+ {
88
+ name => 'readlink', type => 'Long',
89
+ },
90
+ {
91
+ name => 'read', type => 'Long',
92
+ },
93
+ {
94
+ name => 'writecache', type => 'Long',
95
+ },
96
+ {
97
+ name => 'write', type => 'Long',
98
+ },
99
+ {
100
+ name => 'create', type => 'Long',
101
+ },
102
+ {
103
+ name => 'remove', type => 'Long',
104
+ },
105
+ {
106
+ name => 'rename', type => 'Long',
107
+ },
108
+ {
109
+ name => 'link', type => 'Long',
110
+ },
111
+ {
112
+ name => 'symlink', type => 'Long',
113
+ },
114
+ {
115
+ name => 'mkdir', type => 'Long',
116
+ },
117
+ {
118
+ name => 'rmdir', type => 'Long',
119
+ },
120
+ {
121
+ name => 'readdir', type => 'Long',
122
+ },
123
+ {
124
+ name => 'fsstat', type => 'Long',
125
+ },
126
+ ];
127
+
128
+ my $nfs_v3 = [
129
+ {
130
+ name => 'null', type => 'Long',
131
+ },
132
+ {
133
+ name => 'getattr', type => 'Long',
134
+ },
135
+ {
136
+ name => 'setattr', type => 'Long',
137
+ },
138
+ {
139
+ name => 'lookup', type => 'Long',
140
+ },
141
+ {
142
+ name => 'access', type => 'Long',
143
+ },
144
+ {
145
+ name => 'readlink', type => 'Long',
146
+ },
147
+ {
148
+ name => 'read', type => 'Long',
149
+ },
150
+ {
151
+ name => 'write', type => 'Long',
152
+ },
153
+ {
154
+ name => 'create', type => 'Long',
155
+ },
156
+ {
157
+ name => 'mkdir', type => 'Long',
158
+ },
159
+ {
160
+ name => 'symlink', type => 'Long',
161
+ },
162
+ {
163
+ name => 'mknod', type => 'Long',
164
+ },
165
+ {
166
+ name => 'remove', type => 'Long',
167
+ },
168
+ {
169
+ name => 'rmdir', type => 'Long',
170
+ },
171
+ {
172
+ name => 'rename', type => 'Long',
173
+ },
174
+ {
175
+ name => 'link', type => 'Long',
176
+ },
177
+ {
178
+ name => 'readdir', type => 'Long',
179
+ },
180
+ {
181
+ name => 'readdirplus', type => 'Long',
182
+ },
183
+ {
184
+ name => 'fsstat', type => 'Long',
185
+ },
186
+ {
187
+ name => 'fsinfo', type => 'Long',
188
+ },
189
+ {
190
+ name => 'pathconf', type => 'Long',
191
+ },
192
+ {
193
+ name => 'commit', type => 'Long',
194
+ },
195
+ ];
196
+
197
+ use vars qw(%classes %cmds);
198
+
199
+ %classes = (
200
+ Mem => [
201
+ {
202
+ name => 'total', type => 'Long',
203
+ desc => 'Total system memory',
204
+ plat => '*',
205
+ cmd => {
206
+ AIX => 'lsattr -El sys0 -a realmem',
207
+ Darwin => '',
208
+ FreeBSD => '',
209
+ HPUX => '',
210
+ Linux => 'free',
211
+ Solaris => '',
212
+ Win32 => 'taskman',
213
+ },
214
+ },
215
+ {
216
+ name => 'ram', type => 'Long',
217
+ desc => 'System Random Access Memory (in MB)',
218
+ plat => '*',
219
+ cmd => {
220
+ AIX => 'lsattr -El sys0 -a realmem',
221
+ Darwin => '',
222
+ FreeBSD => '',
223
+ HPUX => '',
224
+ Linux => 'cat /proc/mtrr | head -1',
225
+ Solaris => '',
226
+ Win32 => '',
227
+ },
228
+ },
229
+ {
230
+ name => 'used', type => 'Long',
231
+ desc => 'Total used system memory',
232
+ plat => '*',
233
+ cmd => {
234
+ AIX => '',
235
+ Darwin => '',
236
+ FreeBSD => '',
237
+ HPUX => '',
238
+ Linux => 'free',
239
+ Solaris => '',
240
+ Win32 => 'taskman',
241
+ },
242
+ },
243
+ {
244
+ name => 'free', type => 'Long',
245
+ desc => 'Total free system memory (e.g. Linux plus cached)',
246
+ plat => '*',
247
+ cmd => {
248
+ AIX => '',
249
+ Darwin => '',
250
+ FreeBSD => '',
251
+ HPUX => '',
252
+ Linux => 'free',
253
+ Solaris => '',
254
+ Win32 => 'taskman',
255
+ },
256
+ },
257
+ {
258
+ name => 'actual_used', type => 'Long',
259
+ desc => 'Actual total used system memory (e.g. Linux minus buffers)',
260
+ plat => '*',
261
+ cmd => {
262
+ AIX => '',
263
+ Darwin => '',
264
+ FreeBSD => '',
265
+ HPUX => '',
266
+ Linux => 'free',
267
+ Solaris => '',
268
+ Win32 => 'taskman',
269
+ },
270
+ },
271
+ {
272
+ name => 'actual_free', type => 'Long',
273
+ desc => 'Actual total free system memory',
274
+ plat => '*',
275
+ cmd => {
276
+ AIX => '',
277
+ Darwin => '',
278
+ FreeBSD => '',
279
+ HPUX => '',
280
+ Linux => 'free',
281
+ Solaris => '',
282
+ Win32 => 'taskman',
283
+ },
284
+ },
285
+ {
286
+ name => 'used_percent', type => 'Double',
287
+ desc => 'Percent total used system memory',
288
+ plat => '*',
289
+ cmd => {
290
+ AIX => '',
291
+ Darwin => '',
292
+ FreeBSD => '',
293
+ HPUX => '',
294
+ Linux => 'free',
295
+ Solaris => '',
296
+ Win32 => 'taskman',
297
+ },
298
+ },
299
+ {
300
+ name => 'free_percent', type => 'Double',
301
+ desc => 'Percent total free system memory',
302
+ plat => '*',
303
+ cmd => {
304
+ AIX => '',
305
+ Darwin => '',
306
+ FreeBSD => '',
307
+ HPUX => '',
308
+ Linux => 'free',
309
+ Solaris => '',
310
+ Win32 => 'taskman',
311
+ },
312
+ },
313
+ ],
314
+ Swap => [
315
+ {
316
+ name => 'total', type => 'Long',
317
+ desc => 'Total system swap',
318
+ plat => '*',
319
+ cmd => {
320
+ AIX => 'lsps -s',
321
+ Darwin => 'sysctl vm.swapusage',
322
+ FreeBSD => '',
323
+ HPUX => '',
324
+ Linux => 'free',
325
+ Solaris => 'swap -s',
326
+ Win32 => '',
327
+ },
328
+ },
329
+ {
330
+ name => 'used', type => 'Long',
331
+ desc => 'Total used system swap',
332
+ plat => '*',
333
+ cmd => {
334
+ AIX => 'lsps -s',
335
+ Darwin => '',
336
+ FreeBSD => '',
337
+ HPUX => '',
338
+ Linux => 'free',
339
+ Solaris => 'swap -s',
340
+ Win32 => '',
341
+ },
342
+ },
343
+ {
344
+ name => 'free', type => 'Long',
345
+ desc => 'Total free system swap',
346
+ plat => '*',
347
+ cmd => {
348
+ AIX => '',
349
+ Darwin => '',
350
+ FreeBSD => '',
351
+ HPUX => '',
352
+ Linux => 'free',
353
+ Solaris => 'swap -s',
354
+ Win32 => '',
355
+ },
356
+ },
357
+ {
358
+ name => 'page_in', type => 'Long',
359
+ desc => 'Pages in',
360
+ plat => '*',
361
+ cmd => {
362
+ AIX => '',
363
+ Darwin => '',
364
+ FreeBSD => '',
365
+ HPUX => '',
366
+ Linux => 'vmstat',
367
+ Solaris => 'vmstat',
368
+ Win32 => '',
369
+ },
370
+ },
371
+ {
372
+ name => 'page_out', type => 'Long',
373
+ desc => 'Pages out',
374
+ plat => '*',
375
+ cmd => {
376
+ AIX => '',
377
+ Darwin => '',
378
+ FreeBSD => '',
379
+ HPUX => '',
380
+ Linux => 'vmstat',
381
+ Solaris => 'vmstat',
382
+ Win32 => '',
383
+ },
384
+ },
385
+ ],
386
+ Cpu => [
387
+ {
388
+ name => 'user', type => 'Long',
389
+ desc => 'Total system cpu user time',
390
+ plat => '*'
391
+ },
392
+ {
393
+ name => 'sys', type => 'Long',
394
+ desc => 'Total system cpu kernel time',
395
+ plat => '*'
396
+ },
397
+ {
398
+ name => 'nice', type => 'Long',
399
+ desc => 'Total system cpu nice time',
400
+ plat => 'DFHL'
401
+ },
402
+ {
403
+ name => 'idle', type => 'Long',
404
+ desc => 'Total system cpu idle time',
405
+ plat => '*'
406
+ },
407
+ {
408
+ name => 'wait', type => 'Long',
409
+ desc => 'Total system cpu io wait time',
410
+ plat => 'ALHS'
411
+ },
412
+ {
413
+ name => 'irq', type => 'Long',
414
+ desc => 'Total system cpu time servicing interrupts',
415
+ plat => 'FLHW'
416
+ },
417
+ {
418
+ name => 'soft_irq', type => 'Long',
419
+ desc => 'Total system cpu time servicing softirqs',
420
+ plat => 'L'
421
+ },
422
+ {
423
+ name => 'stolen', type => 'Long',
424
+ desc => 'Total system cpu involuntary wait time',
425
+ plat => 'L'
426
+ },
427
+ {
428
+ name => 'total', type => 'Long',
429
+ desc => 'Total system cpu time',
430
+ plat => '*'
431
+ },
432
+ ],
433
+ CpuPerc => [
434
+ {
435
+ name => 'user', type => 'Double',
436
+ desc => 'Percent system cpu user time',
437
+ plat => '*'
438
+ },
439
+ {
440
+ name => 'sys', type => 'Double',
441
+ desc => 'Percent system cpu kernel time',
442
+ plat => '*'
443
+ },
444
+ {
445
+ name => 'nice', type => 'Double',
446
+ desc => 'Percent system cpu nice time',
447
+ plat => 'DFHL'
448
+ },
449
+ {
450
+ name => 'idle', type => 'Double',
451
+ desc => 'Percent system cpu idle time',
452
+ plat => '*'
453
+ },
454
+ {
455
+ name => 'wait', type => 'Double',
456
+ desc => 'Percent system cpu io wait time',
457
+ plat => 'ALHS'
458
+ },
459
+ {
460
+ name => 'irq', type => 'Double',
461
+ desc => 'Percent system cpu time servicing interrupts',
462
+ plat => 'FLHW'
463
+ },
464
+ {
465
+ name => 'soft_irq', type => 'Double',
466
+ desc => 'Percent system cpu time servicing softirqs',
467
+ plat => 'L'
468
+ },
469
+ {
470
+ name => 'stolen', type => 'Double',
471
+ desc => 'Percent system cpu involuntary wait time',
472
+ plat => 'L'
473
+ },
474
+ {
475
+ name => 'combined', type => 'Double',
476
+ desc => 'Sum of User + Sys + Nice + Wait',
477
+ plat => '*'
478
+ },
479
+ ],
480
+ CpuInfo => [
481
+ {
482
+ name => 'vendor', type => 'String',
483
+ desc => 'CPU vendor id',
484
+ plat => '*'
485
+ },
486
+ {
487
+ name => 'model', type => 'String',
488
+ desc => 'CPU model',
489
+ plat => '*'
490
+ },
491
+ {
492
+ name => 'mhz', type => 'Int',
493
+ desc => 'Current CPU speed',
494
+ plat => '*'
495
+ },
496
+ {
497
+ name => 'mhz_max', type => 'Int',
498
+ desc => 'Maximum CPU speed',
499
+ plat => 'DL'
500
+ },
501
+ {
502
+ name => 'mhz_min', type => 'Int',
503
+ desc => 'Maximum CPU speed',
504
+ plat => 'DL'
505
+ },
506
+ {
507
+ name => 'cache_size', type => 'Long',
508
+ desc => 'CPU cache size',
509
+ plat => 'ADL'
510
+ },
511
+ {
512
+ name => 'total_cores', type => 'Int',
513
+ desc => 'Total CPU cores (logical)',
514
+ },
515
+ {
516
+ name => 'total_sockets', type => 'Int',
517
+ desc => 'Total CPU sockets (physical)',
518
+ },
519
+ {
520
+ name => 'cores_per_socket', type => 'Int',
521
+ desc => 'Number of CPU cores per CPU socket',
522
+ },
523
+ ],
524
+ Uptime => [
525
+ {
526
+ name => 'uptime', type => 'Double',
527
+ desc => 'Time since machine started in seconds',
528
+ plat => '*'
529
+ },
530
+ ],
531
+
532
+ ProcMem => [
533
+ {
534
+ name => 'size', type => 'Long',
535
+ desc => 'Total process virtual memory',
536
+ plat => '*'
537
+ },
538
+ {
539
+ name => 'resident', type => 'Long',
540
+ desc => 'Total process resident memory',
541
+ plat => '*'
542
+ },
543
+ {
544
+ name => 'share', type => 'Long',
545
+ desc => 'Total process shared memory',
546
+ plat => 'AHLS'
547
+ },
548
+ {
549
+ name => 'minor_faults', type => 'Long',
550
+ desc => 'non i/o page faults',
551
+ plat => 'AHLS'
552
+ },
553
+ {
554
+ name => 'major_faults', type => 'Long',
555
+ desc => 'i/o page faults',
556
+ plat => 'AHLS'
557
+ },
558
+ {
559
+ name => 'page_faults', type => 'Long',
560
+ desc => 'Total number of page faults',
561
+ plat => 'ADHLSW'
562
+ },
563
+ ],
564
+ ProcCred => [
565
+ {
566
+ name => 'uid', type => 'Long',
567
+ desc => 'Process user id',
568
+ plat => 'ADFHLS'
569
+ },
570
+ {
571
+ name => 'gid', type => 'Long',
572
+ desc => 'Process group id',
573
+ plat => 'ADFHLS'
574
+ },
575
+ {
576
+ name => 'euid', type => 'Long',
577
+ desc => 'Process effective user id',
578
+ plat => 'ADFHLS'
579
+ },
580
+ {
581
+ name => 'egid', type => 'Long',
582
+ desc => 'Process effective group id',
583
+ plat => 'ADFHLS'
584
+ },
585
+ ],
586
+ ProcCredName => [
587
+ {
588
+ name => 'user', type => 'String',
589
+ desc => 'Process owner user name',
590
+ plat => '*'
591
+ },
592
+ {
593
+ name => 'group', type => 'String',
594
+ desc => 'Process owner group name',
595
+ plat => '*'
596
+ },
597
+ ],
598
+ ProcTime => [
599
+ {
600
+ name => 'start_time', type => 'Long',
601
+ desc => 'Time process was started in seconds',
602
+ plat => '*'
603
+ },
604
+ {
605
+ name => 'user', type => 'Long',
606
+ desc => 'Process cpu user time',
607
+ plat => '*'
608
+ },
609
+ {
610
+ name => 'sys', type => 'Long',
611
+ desc => 'Process cpu kernel time',
612
+ plat => '*'
613
+ },
614
+ {
615
+ name => 'total', type => 'Long',
616
+ desc => 'Process cpu time (sum of User and Sys)',
617
+ plat => '*'
618
+ },
619
+ ],
620
+ ProcCpu => [
621
+ {
622
+ name => 'percent', type => 'Double',
623
+ desc => 'Process cpu usage',
624
+ plat => '*'
625
+ },
626
+ {
627
+ name => 'last_time', type => 'Long',
628
+ desc => '',
629
+ plat => '*'
630
+ },
631
+ ],
632
+ ProcDiskIO => [
633
+ {
634
+ name => 'bytes_read', type => 'Long',
635
+ desc => 'Bytes Read',
636
+ plat => 'LW'
637
+ },
638
+ {
639
+ name => 'bytes_written', type => 'Long',
640
+ desc => 'Bytes Written',
641
+ plat => 'LW'
642
+ },
643
+ {
644
+ name => 'bytes_total', type => 'Long',
645
+ desc => 'Bytes Total',
646
+ plat => 'LWAHS'
647
+ }
648
+ ],
649
+
650
+ ProcCumulativeDiskIO => [
651
+ {
652
+ name => 'bytes_read', type => 'Long',
653
+ desc => 'Bytes Read from Start',
654
+ plat => 'LW'
655
+ },
656
+ {
657
+ name => 'bytes_written', type => 'Long',
658
+ desc => 'Bytes Written from Start',
659
+ plat => 'LW'
660
+ },
661
+ {
662
+ name => 'bytes_total', type => 'Long',
663
+ desc => 'Bytes Total from Start',
664
+ plat => 'LWAHS'
665
+ }
666
+ ],
667
+
668
+ DumpPidCache => [
669
+ {
670
+ name => 'dummy', type => 'Long',
671
+ desc => 'Dummy',
672
+ plat => 'LWAHS'
673
+ }
674
+ ],
675
+
676
+
677
+ ProcState => [
678
+ {
679
+ name => 'state', type => 'Char',
680
+ desc => 'Process state (Running, Zombie, etc.)',
681
+ plat => '*'
682
+ },
683
+ {
684
+ name => 'name', type => 'String',
685
+ desc => 'Name of the process program',
686
+ plat => '*'
687
+ },
688
+ {
689
+ name => 'ppid', type => 'Long',
690
+ desc => 'Process parent process id',
691
+ plat => '*'
692
+ },
693
+ {
694
+ name => 'tty', type => 'Int',
695
+ desc => 'Device number of rocess controling terminal',
696
+ plat => 'AHLS'
697
+ },
698
+ {
699
+ name => 'nice', type => 'Int',
700
+ desc => 'Nice value of process',
701
+ plat => 'ADFHLS'
702
+ },
703
+ {
704
+ name => 'priority', type => 'Int',
705
+ desc => 'Kernel scheduling priority of process',
706
+ plat => 'DFHLSW'
707
+ },
708
+ {
709
+ name => 'threads', type => 'Long',
710
+ desc => 'Number of active threads',
711
+ plat => 'ADHLSW'
712
+ },
713
+ {
714
+ name => 'processor', type => 'Int',
715
+ desc => 'Processor number last run on',
716
+ plat => 'AHLS'
717
+ },
718
+ ],
719
+ ProcFd => [
720
+ {
721
+ name => 'total', type => 'Long',
722
+ desc => 'Total number of open file descriptors',
723
+ plat => 'AHLSW'
724
+ },
725
+ ],
726
+ ProcStat => [
727
+ {
728
+ name => 'total', type => 'Long',
729
+ desc => 'Total number of processes',
730
+ plat => '*'
731
+ },
732
+ {
733
+ name => 'idle', type => 'Long',
734
+ desc => 'Total number of processes in idle state',
735
+ plat => '*'
736
+ },
737
+ {
738
+ name => 'running', type => 'Long',
739
+ desc => 'Total number of processes in run state',
740
+ plat => '*'
741
+ },
742
+ {
743
+ name => 'sleeping', type => 'Long',
744
+ desc => 'Total number of processes in sleep state',
745
+ plat => '*'
746
+ },
747
+ {
748
+ name => 'stopped', type => 'Long',
749
+ desc => 'Total number of processes in stop state',
750
+ plat => '*'
751
+ },
752
+ {
753
+ name => 'zombie', type => 'Long',
754
+ desc => 'Total number of processes in zombie state',
755
+ plat => '*'
756
+ },
757
+ {
758
+ name => 'threads', type => 'Long',
759
+ desc => 'Total number of threads',
760
+ plat => '*'
761
+ },
762
+ ],
763
+ ProcExe => [
764
+ {
765
+ name => 'name', type => 'String',
766
+ desc => 'Name of process executable',
767
+ plat => 'FLSW',
768
+ cmd => {
769
+ AIX => '',
770
+ Darwin => '',
771
+ FreeBSD => '',
772
+ HPUX => '',
773
+ Linux => 'ls -l /proc/$$/exe',
774
+ Solaris => '',
775
+ Win32 => '',
776
+ },
777
+ },
778
+ {
779
+ name => 'cwd', type => 'String',
780
+ desc => 'Name of process current working directory',
781
+ plat => 'LSW',
782
+ cmd => {
783
+ AIX => '',
784
+ Darwin => '',
785
+ FreeBSD => '',
786
+ HPUX => '',
787
+ Linux => 'ls -l /proc/$$/cwd',
788
+ Solaris => '',
789
+ Win32 => '',
790
+ },
791
+ },
792
+ ],
793
+ ThreadCpu => [
794
+ {
795
+ name => 'user', type => 'Long',
796
+ desc => 'Thread cpu user time',
797
+ plat => 'AHLSW'
798
+ },
799
+ {
800
+ name => 'sys', type => 'Long',
801
+ desc => 'Thread cpu kernel time',
802
+ plat => 'AHLSW'
803
+ },
804
+ {
805
+ name => 'total', type => 'Long',
806
+ desc => 'Thread cpu time (sum of User and Sys)',
807
+ plat => 'AHLSW'
808
+ },
809
+ ],
810
+ FileSystem => [
811
+ {
812
+ name => 'dir_name', type => 'String',
813
+ desc => 'Directory name',
814
+ plat => '*'
815
+ },
816
+ {
817
+ name => 'dev_name', type => 'String',
818
+ desc => 'Device name',
819
+ plat => '*'
820
+ },
821
+ {
822
+ name => 'type_name', type => 'String',
823
+ desc => 'File system generic type name',
824
+ plat => '*'
825
+ },
826
+ {
827
+ name => 'sys_type_name', type => 'String',
828
+ desc => 'File system os specific type name',
829
+ plat => '*'
830
+ },
831
+ {
832
+ name => 'options', type => 'String',
833
+ desc => 'File system mount options',
834
+ plat => '*'
835
+ },
836
+ {
837
+ name => 'type', type => 'Int',
838
+ desc => 'File system type',
839
+ plat => '*'
840
+ },
841
+ {
842
+ name => 'flags', type => 'Long',
843
+ desc => 'File system flags',
844
+ plat => '*'
845
+ },
846
+ ],
847
+ FileSystemUsage => [
848
+ {
849
+ name => 'total', type => 'Long',
850
+ desc => 'Total Kbytes of filesystem',
851
+ plat => '*'
852
+ },
853
+ {
854
+ name => 'free', type => 'Long',
855
+ desc => 'Total free Kbytes on filesystem',
856
+ plat => '*'
857
+ },
858
+ {
859
+ name => 'used', type => 'Long',
860
+ desc => 'Total used Kbytes on filesystem',
861
+ plat => '*'
862
+ },
863
+ {
864
+ name => 'avail', type => 'Long',
865
+ desc => 'Total free Kbytes on filesystem available to caller',
866
+ plat => '*'
867
+ },
868
+ {
869
+ name => 'files', type => 'Long',
870
+ desc => 'Total number of file nodes on the filesystem',
871
+ plat => 'ADFHLS'
872
+ },
873
+ {
874
+ name => 'free_files', type => 'Long',
875
+ desc => 'Number of free file nodes on the filesystem',
876
+ plat => 'ADFHLS'
877
+ },
878
+ {
879
+ name => 'disk_reads', type => 'Long',
880
+ desc => 'Number of physical disk reads',
881
+ plat => 'AFHLSW'
882
+ },
883
+ {
884
+ name => 'disk_writes', type => 'Long',
885
+ desc => 'Number of physical disk writes',
886
+ plat => 'AFHLSW'
887
+ },
888
+ {
889
+ name => 'disk_read_bytes', type => 'Long',
890
+ desc => 'Number of physical disk bytes read',
891
+ plat => ''
892
+ },
893
+ {
894
+ name => 'disk_write_bytes', type => 'Long',
895
+ desc => 'Number of physical disk bytes written',
896
+ plat => ''
897
+ },
898
+ {
899
+ name => 'disk_queue', type => 'Double',
900
+ desc => '',
901
+ plat => ''
902
+ },
903
+ {
904
+ name => 'disk_service_time', type => 'Double',
905
+ desc => '',
906
+ plat => ''
907
+ },
908
+ {
909
+ name => 'use_percent', type => 'Double',
910
+ desc => 'Percent of disk used',
911
+ plat => '*'
912
+ },
913
+ ],
914
+ DiskUsage => [
915
+ {
916
+ name => 'reads', type => 'Long',
917
+ desc => 'Number of physical disk reads',
918
+ plat => 'AFHLSW'
919
+ },
920
+ {
921
+ name => 'writes', type => 'Long',
922
+ desc => 'Number of physical disk writes',
923
+ plat => 'AFHLSW'
924
+ },
925
+ {
926
+ name => 'read_bytes', type => 'Long',
927
+ desc => 'Number of physical disk bytes read',
928
+ plat => ''
929
+ },
930
+ {
931
+ name => 'write_bytes', type => 'Long',
932
+ desc => 'Number of physical disk bytes written',
933
+ plat => ''
934
+ },
935
+ {
936
+ name => 'queue', type => 'Double',
937
+ desc => '',
938
+ plat => ''
939
+ },
940
+ {
941
+ name => 'service_time', type => 'Double',
942
+ desc => '',
943
+ plat => ''
944
+ },
945
+ ],
946
+ FileAttrs => [
947
+ {
948
+ name => 'permissions', type => 'Long',
949
+ },
950
+ {
951
+ name => 'type', type => 'Int',
952
+ },
953
+ {
954
+ name => 'uid', type => 'Long',
955
+ },
956
+ {
957
+ name => 'gid', type => 'Long',
958
+ },
959
+ {
960
+ name => 'inode', type => 'Long',
961
+ },
962
+ {
963
+ name => 'device', type => 'Long',
964
+ },
965
+ {
966
+ name => 'nlink', type => 'Long',
967
+ },
968
+ {
969
+ name => 'size', type => 'Long',
970
+ },
971
+ {
972
+ name => 'atime', type => 'Long',
973
+ },
974
+ {
975
+ name => 'ctime', type => 'Long',
976
+ },
977
+ {
978
+ name => 'mtime', type => 'Long',
979
+ },
980
+ ],
981
+ DirStat => [
982
+ {
983
+ name => 'total', type => 'Long',
984
+ },
985
+ {
986
+ name => 'files', type => 'Long',
987
+ },
988
+ {
989
+ name => 'subdirs', type => 'Long',
990
+ },
991
+ {
992
+ name => 'symlinks', type => 'Long',
993
+ },
994
+ {
995
+ name => 'chrdevs', type => 'Long',
996
+ },
997
+ {
998
+ name => 'blkdevs', type => 'Long',
999
+ },
1000
+ {
1001
+ name => 'sockets', type => 'Long',
1002
+ },
1003
+ {
1004
+ name => 'disk_usage', type => 'Long',
1005
+ },
1006
+ ],
1007
+ NetInfo => [
1008
+ {
1009
+ name => 'default_gateway', type => 'String',
1010
+ desc => '',
1011
+ plat => ''
1012
+ },
1013
+ {
1014
+ name => 'default_gateway_interface', type => 'String',
1015
+ desc => '',
1016
+ plat => ''
1017
+ },
1018
+ {
1019
+ name => 'host_name', type => 'String',
1020
+ desc => '',
1021
+ plat => ''
1022
+ },
1023
+ {
1024
+ name => 'domain_name', type => 'String',
1025
+ desc => '',
1026
+ plat => ''
1027
+ },
1028
+ {
1029
+ name => 'primary_dns', type => 'String',
1030
+ desc => '',
1031
+ plat => ''
1032
+ },
1033
+ {
1034
+ name => 'secondary_dns', type => 'String',
1035
+ desc => '',
1036
+ plat => ''
1037
+ },
1038
+ ],
1039
+ NetRoute => [
1040
+ {
1041
+ name => 'destination', type => 'NetAddress',
1042
+ desc => '',
1043
+ plat => 'HLW'
1044
+ },
1045
+ {
1046
+ name => 'gateway', type => 'NetAddress',
1047
+ desc => '',
1048
+ plat => 'HLW'
1049
+ },
1050
+ {
1051
+ name => 'flags', type => 'Long',
1052
+ desc => '',
1053
+ plat => 'L'
1054
+ },
1055
+ {
1056
+ name => 'refcnt', type => 'Long',
1057
+ desc => '',
1058
+ plat => 'L'
1059
+ },
1060
+ {
1061
+ name => 'use', type => 'Long',
1062
+ desc => '',
1063
+ plat => 'L'
1064
+ },
1065
+ {
1066
+ name => 'metric', type => 'Long',
1067
+ desc => '',
1068
+ plat => 'L'
1069
+ },
1070
+ {
1071
+ name => 'mask', type => 'NetAddress',
1072
+ desc => '',
1073
+ plat => 'HL'
1074
+ },
1075
+ {
1076
+ name => 'mtu', type => 'Long',
1077
+ desc => '',
1078
+ plat => 'L'
1079
+ },
1080
+ {
1081
+ name => 'window', type => 'Long',
1082
+ desc => '',
1083
+ plat => 'L'
1084
+ },
1085
+ {
1086
+ name => 'irtt', type => 'Long',
1087
+ desc => '',
1088
+ plat => 'L'
1089
+ },
1090
+ {
1091
+ name => 'ifname', type => 'String',
1092
+ desc => '',
1093
+ plat => 'L'
1094
+ },
1095
+ ],
1096
+ NetInterfaceConfig => [
1097
+ {
1098
+ name => 'name', type => 'String',
1099
+ desc => '',
1100
+ plat => '*'
1101
+ },
1102
+ {
1103
+ name => 'hwaddr', type => 'NetAddress',
1104
+ desc => '',
1105
+ plat => '*'
1106
+ },
1107
+ {
1108
+ name => 'type', type => 'String',
1109
+ desc => '',
1110
+ plat => '*'
1111
+ },
1112
+ {
1113
+ name => 'description', type => 'String',
1114
+ desc => '',
1115
+ plat => '*'
1116
+ },
1117
+ {
1118
+ name => 'address', type => 'NetAddress',
1119
+ desc => '',
1120
+ plat => '*'
1121
+ },
1122
+ {
1123
+ name => 'address6', type => 'NetAddress',
1124
+ desc => '',
1125
+ },
1126
+ {
1127
+ name => 'prefix6_length', type => 'Int',
1128
+ desc => '',
1129
+ },
1130
+ {
1131
+ name => 'scope6', type => 'Int',
1132
+ desc => '',
1133
+ },
1134
+ {
1135
+ name => 'destination', type => 'NetAddress',
1136
+ desc => '',
1137
+ plat => '*'
1138
+ },
1139
+ {
1140
+ name => 'broadcast', type => 'NetAddress',
1141
+ desc => '',
1142
+ plat => '*'
1143
+ },
1144
+ {
1145
+ name => 'netmask', type => 'NetAddress',
1146
+ desc => '',
1147
+ plat => '*'
1148
+ },
1149
+ {
1150
+ name => 'flags', type => 'Long',
1151
+ desc => '',
1152
+ plat => '*'
1153
+ },
1154
+ {
1155
+ name => 'mtu', type => 'Long',
1156
+ desc => '',
1157
+ plat => 'DFL'
1158
+ },
1159
+ {
1160
+ name => 'metric', type => 'Long',
1161
+ desc => '',
1162
+ plat => 'DFL'
1163
+ },
1164
+ {
1165
+ name => 'tx_queue_len', type => 'Int',
1166
+ desc => '',
1167
+ plat => 'L'
1168
+ },
1169
+ ],
1170
+ NetInterfaceStat => [
1171
+ {
1172
+ name => 'rx_bytes', type => 'Long',
1173
+ desc => '',
1174
+ plat => '*'
1175
+ },
1176
+ {
1177
+ name => 'rx_packets', type => 'Long',
1178
+ desc => '',
1179
+ plat => '*'
1180
+ },
1181
+ {
1182
+ name => 'rx_errors', type => 'Long',
1183
+ desc => '',
1184
+ plat => '*'
1185
+ },
1186
+ {
1187
+ name => 'rx_dropped', type => 'Long',
1188
+ desc => '',
1189
+ plat => ''
1190
+ },
1191
+ {
1192
+ name => 'rx_overruns', type => 'Long',
1193
+ desc => '',
1194
+ plat => ''
1195
+ },
1196
+ {
1197
+ name => 'rx_frame', type => 'Long',
1198
+ desc => '',
1199
+ plat => ''
1200
+ },
1201
+ {
1202
+ name => 'tx_bytes', type => 'Long',
1203
+ desc => '',
1204
+ plat => '*'
1205
+ },
1206
+ {
1207
+ name => 'tx_packets', type => 'Long',
1208
+ desc => '',
1209
+ plat => '*'
1210
+ },
1211
+ {
1212
+ name => 'tx_errors', type => 'Long',
1213
+ desc => '*',
1214
+ plat => ''
1215
+ },
1216
+ {
1217
+ name => 'tx_dropped', type => 'Long',
1218
+ desc => '',
1219
+ plat => ''
1220
+ },
1221
+ {
1222
+ name => 'tx_overruns', type => 'Long',
1223
+ desc => '',
1224
+ plat => ''
1225
+ },
1226
+ {
1227
+ name => 'tx_collisions', type => 'Long',
1228
+ desc => '',
1229
+ plat => ''
1230
+ },
1231
+ {
1232
+ name => 'tx_carrier', type => 'Long',
1233
+ desc => '',
1234
+ plat => ''
1235
+ },
1236
+ {
1237
+ name => 'speed', type => 'Long',
1238
+ desc => '',
1239
+ plat => ''
1240
+ },
1241
+ ],
1242
+ NetConnection => [
1243
+ {
1244
+ name => 'local_port', type => 'Long',
1245
+ desc => '',
1246
+ plat => 'LFSW'
1247
+ },
1248
+ {
1249
+ name => 'local_address', type => 'NetAddress',
1250
+ desc => '',
1251
+ plat => 'LFSW'
1252
+ },
1253
+ {
1254
+ name => 'remote_port', type => 'Long',
1255
+ desc => '',
1256
+ plat => 'LFSW'
1257
+ },
1258
+ {
1259
+ name => 'remote_address', type => 'NetAddress',
1260
+ desc => '',
1261
+ plat => 'LFSW'
1262
+ },
1263
+ {
1264
+ name => 'type', type => 'Int',
1265
+ desc => '',
1266
+ plat => 'LFSW'
1267
+ },
1268
+ {
1269
+ name => 'state', type => 'Int',
1270
+ desc => '',
1271
+ plat => 'LFSW'
1272
+ },
1273
+ {
1274
+ name => 'send_queue', type => 'Long',
1275
+ desc => '',
1276
+ plat => 'LFS'
1277
+ },
1278
+ {
1279
+ name => 'receive_queue', type => 'Long',
1280
+ desc => '',
1281
+ plat => 'LFS'
1282
+ },
1283
+ ],
1284
+ #only for jfieldId cache/setters
1285
+ NetStat => [
1286
+ {
1287
+ name => 'tcp_inbound_total', type => 'Int',
1288
+ },
1289
+ {
1290
+ name => 'tcp_outbound_total', type => 'Int',
1291
+ },
1292
+ {
1293
+ name => 'all_inbound_total', type => 'Int',
1294
+ },
1295
+ {
1296
+ name => 'all_outbound_total', type => 'Int',
1297
+ },
1298
+ ],
1299
+ Tcp => [
1300
+ {
1301
+ name => 'active_opens', type => 'Long',
1302
+ desc => '',
1303
+ plat => ''
1304
+ },
1305
+ {
1306
+ name => 'passive_opens', type => 'Long',
1307
+ desc => '',
1308
+ plat => ''
1309
+ },
1310
+ {
1311
+ name => 'attempt_fails', type => 'Long',
1312
+ desc => '',
1313
+ plat => ''
1314
+ },
1315
+ {
1316
+ name => 'estab_resets', type => 'Long',
1317
+ desc => '',
1318
+ plat => ''
1319
+ },
1320
+ {
1321
+ name => 'curr_estab', type => 'Long',
1322
+ desc => '',
1323
+ plat => ''
1324
+ },
1325
+ {
1326
+ name => 'in_segs', type => 'Long',
1327
+ desc => '',
1328
+ plat => ''
1329
+ },
1330
+ {
1331
+ name => 'out_segs', type => 'Long',
1332
+ desc => '',
1333
+ plat => ''
1334
+ },
1335
+ {
1336
+ name => 'retrans_segs', type => 'Long',
1337
+ desc => '',
1338
+ plat => ''
1339
+ },
1340
+ {
1341
+ name => 'in_errs', type => 'Long',
1342
+ desc => '',
1343
+ plat => ''
1344
+ },
1345
+ {
1346
+ name => 'out_rsts', type => 'Long',
1347
+ desc => '',
1348
+ plat => ''
1349
+ },
1350
+ ],
1351
+ NfsClientV2 => $nfs_v2,
1352
+ NfsServerV2 => $nfs_v2,
1353
+ NfsClientV3 => $nfs_v3,
1354
+ NfsServerV3 => $nfs_v3,
1355
+ ResourceLimit => [
1356
+ {
1357
+ name => 'cpu_cur',
1358
+ },
1359
+ {
1360
+ name => 'cpu_max',
1361
+ },
1362
+ {
1363
+ name => 'file_size_cur',
1364
+ },
1365
+ {
1366
+ name => 'file_size_max',
1367
+ },
1368
+ {
1369
+ name => 'pipe_size_max',
1370
+ },
1371
+ {
1372
+ name => 'pipe_size_cur',
1373
+ },
1374
+ {
1375
+ name => 'data_cur',
1376
+ },
1377
+ {
1378
+ name => 'data_max',
1379
+ },
1380
+ {
1381
+ name => 'stack_cur',
1382
+ },
1383
+ {
1384
+ name => 'stack_max',
1385
+ },
1386
+ {
1387
+ name => 'core_cur',
1388
+ },
1389
+ {
1390
+ name => 'core_max',
1391
+ },
1392
+ {
1393
+ name => 'memory_cur',
1394
+ },
1395
+ {
1396
+ name => 'memory_max',
1397
+ },
1398
+ {
1399
+ name => 'processes_cur',
1400
+ },
1401
+ {
1402
+ name => 'processes_max',
1403
+ },
1404
+ {
1405
+ name => 'open_files_cur',
1406
+ },
1407
+ {
1408
+ name => 'open_files_max',
1409
+ },
1410
+ {
1411
+ name => 'virtual_memory_cur',
1412
+ },
1413
+ {
1414
+ name => 'virtual_memory_max',
1415
+ },
1416
+ ],
1417
+ SysInfo => [
1418
+ {
1419
+ name => 'name', type => 'String',
1420
+ desc => '',
1421
+ plat => '*'
1422
+ },
1423
+ {
1424
+ name => 'version', type => 'String',
1425
+ desc => '',
1426
+ plat => '*'
1427
+ },
1428
+ {
1429
+ name => 'arch', type => 'String',
1430
+ desc => '',
1431
+ plat => '*'
1432
+ },
1433
+ {
1434
+ name => 'machine', type => 'String',
1435
+ desc => '',
1436
+ plat => '*'
1437
+ },
1438
+ {
1439
+ name => 'description', type => 'String',
1440
+ desc => '',
1441
+ plat => '*'
1442
+ },
1443
+ {
1444
+ name => 'patch_level', type => 'String',
1445
+ desc => '',
1446
+ plat => 'W'
1447
+ },
1448
+ {
1449
+ name => 'vendor', type => 'String',
1450
+ desc => '',
1451
+ plat => '*'
1452
+ },
1453
+ {
1454
+ name => 'vendor_version', type => 'String',
1455
+ desc => '',
1456
+ plat => '*'
1457
+ },
1458
+ {
1459
+ name => 'vendor_name', type => 'String',
1460
+ desc => '',
1461
+ plat => '*'
1462
+ },
1463
+ {
1464
+ name => 'vendor_code_name', type => 'String',
1465
+ desc => '',
1466
+ plat => '*'
1467
+ },
1468
+ ],
1469
+ Arp => [
1470
+ {
1471
+ name => 'ifname', type => 'String',
1472
+ desc => '',
1473
+ plat => '*'
1474
+ },
1475
+ {
1476
+ name => 'hwaddr', type => 'NetAddress',
1477
+ desc => '',
1478
+ plat => '*'
1479
+ },
1480
+ {
1481
+ name => 'type', type => 'String',
1482
+ desc => '',
1483
+ plat => '*'
1484
+ },
1485
+ {
1486
+ name => 'address', type => 'NetAddress',
1487
+ desc => '',
1488
+ plat => '*'
1489
+ },
1490
+ {
1491
+ name => 'flags', type => 'Long',
1492
+ desc => '',
1493
+ plat => '*'
1494
+ },
1495
+ ],
1496
+ Who => [
1497
+ {
1498
+ name => 'user', type => 'String',
1499
+ desc => '',
1500
+ plat => ''
1501
+ },
1502
+ {
1503
+ name => 'device', type => 'String',
1504
+ desc => '',
1505
+ plat => ''
1506
+ },
1507
+ {
1508
+ name => 'host', type => 'String',
1509
+ desc => '',
1510
+ plat => ''
1511
+ },
1512
+ {
1513
+ name => 'time', type => 'Long',
1514
+ desc => '',
1515
+ plat => ''
1516
+ },
1517
+ ],
1518
+ );
1519
+
1520
+ $classes{DirUsage} = $classes{DirStat};
1521
+
1522
+ my(%extends) = (
1523
+ ProcCpu => 'ProcTime',
1524
+ );
1525
+
1526
+ while (my($subclass, $superclass) = each %extends) {
1527
+ push @{ $classes{$subclass} }, @{ $classes{$superclass} };
1528
+ }
1529
+
1530
+ %cmds = (
1531
+ Mem => {
1532
+ AIX => 'top',
1533
+ Darwin => 'top',
1534
+ FreeBSD => 'top',
1535
+ HPUX => 'top',
1536
+ Linux => 'top',
1537
+ Solaris => 'top',
1538
+ Win32 => 'taskman',
1539
+ },
1540
+ Swap => {
1541
+ AIX => 'top',
1542
+ Darwin => 'top',
1543
+ FreeBSD => 'top',
1544
+ HPUX => 'top',
1545
+ Linux => 'top',
1546
+ Solaris => 'top',
1547
+ Win32 => 'taskman',
1548
+ },
1549
+ Cpu => {
1550
+ AIX => 'top',
1551
+ Darwin => 'top',
1552
+ FreeBSD => 'top',
1553
+ HPUX => 'top',
1554
+ Linux => 'top',
1555
+ Solaris => 'top',
1556
+ Win32 => 'taskman',
1557
+ },
1558
+ CpuInfo => {
1559
+ AIX => 'lsattr -El proc0',
1560
+ Darwin => '',
1561
+ FreeBSD => '',
1562
+ HPUX => '',
1563
+ Linux => 'cat /proc/cpuinfo',
1564
+ Solaris => 'psrinfo -v',
1565
+ Win32 => '',
1566
+ },
1567
+ Uptime => {
1568
+ AIX => 'uptime',
1569
+ Darwin => 'uptime',
1570
+ FreeBSD => 'uptime',
1571
+ HPUX => 'uptime',
1572
+ Linux => 'uptime',
1573
+ Solaris => 'uptime',
1574
+ Win32 => '',
1575
+ },
1576
+ ProcMem => {
1577
+ AIX => 'top, ps',
1578
+ Darwin => 'top, ps',
1579
+ FreeBSD => 'top, ps',
1580
+ HPUX => 'top, ps',
1581
+ Linux => 'top, ps',
1582
+ Solaris => 'top, ps',
1583
+ Win32 => 'taskman',
1584
+ },
1585
+ ProcCred => {
1586
+ AIX => 'top, ps',
1587
+ Darwin => 'top, ps',
1588
+ FreeBSD => 'top, ps',
1589
+ HPUX => 'top, ps',
1590
+ Linux => 'top, ps',
1591
+ Solaris => 'top, ps',
1592
+ Win32 => 'taskman',
1593
+ },
1594
+ ProcTime => {
1595
+ AIX => 'top, ps',
1596
+ Darwin => 'top, ps',
1597
+ FreeBSD => 'top, ps',
1598
+ HPUX => 'top, ps',
1599
+ Linux => 'top, ps',
1600
+ Solaris => 'top, ps',
1601
+ Win32 => 'taskman',
1602
+ },
1603
+ ProcState => {
1604
+ AIX => 'top, ps',
1605
+ Darwin => 'top, ps',
1606
+ FreeBSD => 'top, ps',
1607
+ HPUX => 'top, ps',
1608
+ Linux => 'top, ps',
1609
+ Solaris => 'top, ps',
1610
+ Win32 => 'taskman',
1611
+ },
1612
+ ProcFd => {
1613
+ AIX => 'lsof',
1614
+ Darwin => 'lsof',
1615
+ FreeBSD => 'lsof',
1616
+ HPUX => 'lsof',
1617
+ Linux => 'lsof',
1618
+ Solaris => 'lsof',
1619
+ Win32 => '',
1620
+ },
1621
+ ProcStat => {
1622
+ AIX => 'top, ps',
1623
+ Darwin => 'top, ps',
1624
+ FreeBSD => 'top, ps',
1625
+ HPUX => 'top, ps',
1626
+ Linux => 'top, ps',
1627
+ Solaris => 'top, ps',
1628
+ Win32 => 'taskman',
1629
+ },
1630
+ FileSystemUsage => {
1631
+ AIX => 'df',
1632
+ Darwin => 'df',
1633
+ FreeBSD => 'df',
1634
+ HPUX => 'df',
1635
+ Linux => 'df',
1636
+ Solaris => 'df',
1637
+ Win32 => '',
1638
+ },
1639
+ NetRoute => {
1640
+ AIX => '',
1641
+ Darwin => '',
1642
+ FreeBSD => '',
1643
+ HPUX => '',
1644
+ Linux => 'route -n',
1645
+ Solaris => '',
1646
+ Win32 => '',
1647
+ },
1648
+ NetInterfaceConfig => {
1649
+ AIX => '',
1650
+ Darwin => '',
1651
+ FreeBSD => '',
1652
+ HPUX => '',
1653
+ Linux => 'ifconfig',
1654
+ Solaris => 'ifconfig -a',
1655
+ Win32 => '',
1656
+ },
1657
+ NetInterfaceStat => {
1658
+ AIX => '',
1659
+ Darwin => '',
1660
+ FreeBSD => '',
1661
+ HPUX => '/usr/sbin/lanadmin -g mibstats 0, netstat -i',
1662
+ Linux => 'ifconfig',
1663
+ Solaris => '',
1664
+ Win32 => '',
1665
+ },
1666
+ NetConnection => {
1667
+ AIX => '',
1668
+ Darwin => '',
1669
+ FreeBSD => '',
1670
+ HPUX => '',
1671
+ Linux => 'netstat',
1672
+ Solaris => '',
1673
+ Win32 => '',
1674
+ },
1675
+ Tcp => {
1676
+ Linux => 'cat /proc/net/snmp',
1677
+ Solaris => 'netstat -s -P tcp',
1678
+ },
1679
+ );
1680
+
1681
+ sub warning_comment {
1682
+ my $self = shift;
1683
+
1684
+ return "WARNING: this file was generated by $0
1685
+ on $self->{timestamp}.
1686
+ Any changes made here will be LOST.";
1687
+ }
1688
+
1689
+ sub c_warning_comment {
1690
+ my $self = shift;
1691
+ my $comment = $self->warning_comment;
1692
+ $comment =~ s/^/ * /mg;
1693
+ return <<EOF
1694
+ /*****************************************************
1695
+ $comment
1696
+ *****************************************************/
1697
+ EOF
1698
+ }
1699
+
1700
+ sub erl_warning_comment {
1701
+ my $self = shift;
1702
+ my $comment = $self->warning_comment;
1703
+ $comment =~ s/^/% /mg;
1704
+ "$comment\n";
1705
+ }
1706
+
1707
+ sub generate {
1708
+ my($lang, $dir) = @_ ? @_ : @ARGV;
1709
+
1710
+ my $mtime = (stat __FILE__)[9];
1711
+
1712
+ my $cwd = cwd();
1713
+ unless (-d $dir) {
1714
+ die "Invalid build directory '$dir'";
1715
+ }
1716
+
1717
+ chdir $dir;
1718
+ my(%param) = (
1719
+ build_dir => $dir,
1720
+ mtime => $mtime,
1721
+ );
1722
+
1723
+ my $package = __PACKAGE__ . "::$lang";
1724
+ eval "require $package";
1725
+
1726
+ unless ($package->can('new')) {
1727
+ die "unsupported language: $lang";
1728
+ }
1729
+ $@ = '';
1730
+
1731
+ my $wrapper = $package->new(%param);
1732
+ unless ($wrapper->uptodate($wrapper->sources)) {
1733
+ eval {
1734
+ $wrapper->start();
1735
+
1736
+ my $mappings = $wrapper->get_mappings;
1737
+ for my $func (@$mappings) {
1738
+ $wrapper->generate_class($func);
1739
+ }
1740
+
1741
+ $wrapper->finish;
1742
+ };
1743
+ }
1744
+ die $@ if $@;
1745
+ chdir $cwd;
1746
+ }
1747
+
1748
+ sub new {
1749
+ my $class = shift;
1750
+ return bless {
1751
+ timestamp => scalar localtime,
1752
+ @_
1753
+ }, $class;
1754
+ }
1755
+
1756
+ sub uptodate {
1757
+ my $self = shift;
1758
+ for my $file (@_) {
1759
+ my $mtime = (stat $file)[9];
1760
+ if ($mtime > $self->{mtime}) {
1761
+ print "$file up-to-date\n";
1762
+ }
1763
+ else {
1764
+ print "$file needs update\n";
1765
+ return 0;
1766
+ }
1767
+ }
1768
+ return 1;
1769
+ }
1770
+
1771
+ my(%warning_comment) =
1772
+ ((map { $_ => \&c_warning_comment } qw(c h java)),
1773
+ (map { $_ => \&erl_warning_comment } qw(erl hrl)));
1774
+
1775
+ sub create {
1776
+ my($self, $file) = @_;
1777
+ my $handle = SigarWrapper::File->create($file);
1778
+ if ($file =~ /\.(\w+)$/) {
1779
+ my $comment = $warning_comment{$1};
1780
+ $handle->print($self->$comment()) if $comment;
1781
+ }
1782
+ return $self->{files}->{$file} = $handle;
1783
+ }
1784
+
1785
+ sub start {
1786
+ }
1787
+
1788
+ sub finish {
1789
+ my $self = shift;
1790
+ while (my($file, $handle) = each %{ $self->{files} }) {
1791
+ next unless $handle->opened;
1792
+ if ($handle->close) {
1793
+ #print "closing $file\n";
1794
+ }
1795
+ else {
1796
+ warn "close($file): $!";
1797
+ }
1798
+ }
1799
+ }
1800
+
1801
+ my @mappings;
1802
+
1803
+ sub get_mappings {
1804
+ if (@mappings != 0) {
1805
+ return \@mappings;
1806
+ }
1807
+
1808
+ while (my($name, $fields) = each %classes) {
1809
+ #example: FileSystemUsage -> file_system_usage
1810
+ (my $cname = $name) =~ s/([a-z])([A-Z])/$1_$2/g;
1811
+ $cname = lc $cname;
1812
+
1813
+ my $func = {
1814
+ name => $name,
1815
+ cname => $cname,
1816
+ };
1817
+ push @mappings, $func;
1818
+
1819
+ if (($cname =~ /^proc_(\w+)/ and !$proc_no_arg{$1}) ||
1820
+ ($cname =~ /^thread_cpu/))
1821
+ {
1822
+ $func->{num_args} = 1;
1823
+ $func->{arg_type} = 'sigar_pid_t';
1824
+ $func->{arg} = 'pid';
1825
+ $func->{is_proc} = 1;
1826
+ }
1827
+ elsif ($has_name_arg{$name}) {
1828
+ $func->{num_args} = 1;
1829
+ $func->{arg_type} = 'const char *';
1830
+ $func->{arg} = 'name';
1831
+ }
1832
+ else {
1833
+ $func->{num_args} = 0;
1834
+ }
1835
+
1836
+ if ($get_not_impl{$cname}) {
1837
+ $func->{has_get} = 0;
1838
+ }
1839
+ else {
1840
+ $func->{has_get} = 1;
1841
+ }
1842
+
1843
+ my $sigar_prefix = $func->{sigar_prefix} = join '_', 'sigar', $cname;
1844
+
1845
+ $func->{sigar_function} = join '_', $sigar_prefix, 'get';
1846
+
1847
+ $func->{sigar_type} = join '_', $sigar_prefix, 't';
1848
+
1849
+ $func->{fields} = $fields;
1850
+
1851
+ for my $field (@$fields) {
1852
+ $field->{type} ||= 'Long';
1853
+ }
1854
+ }
1855
+
1856
+ return \@mappings;
1857
+ }
1858
+
1859
+ package SigarWrapper::File;
1860
+
1861
+ use vars qw(@ISA);
1862
+ @ISA = qw(IO::File);
1863
+
1864
+ my $DEVNULL = '/dev/null';
1865
+ my $has_dev_null = -e $DEVNULL;
1866
+
1867
+ sub println {
1868
+ shift->print(@_, "\n");
1869
+ }
1870
+
1871
+ sub create {
1872
+ my($class, $file) = @_;
1873
+
1874
+ my $handle = $class->SUPER::new($file || devnull(), "w") or die "open $file: $!";
1875
+ print "generating $file\n" if $file;
1876
+ return $handle;
1877
+ }
1878
+
1879
+ sub devnull {
1880
+ if ($has_dev_null) {
1881
+ return $DEVNULL;
1882
+ }
1883
+ else {
1884
+ return "./nul"; #win32 /dev/null equiv
1885
+ }
1886
+ }
1887
+
1888
+ package SigarWrapper::Java;
1889
+
1890
+ use vars qw(@ISA);
1891
+ @ISA = qw(SigarWrapper);
1892
+
1893
+ my %field_types = (
1894
+ Long => "J",
1895
+ Double => "D",
1896
+ Int => "I",
1897
+ Char => "C",
1898
+ String => "Ljava/lang/String;",
1899
+ );
1900
+
1901
+ my %init = (
1902
+ String => 'null',
1903
+ );
1904
+
1905
+ my %type = (
1906
+ String => 'String',
1907
+ );
1908
+
1909
+ #alias
1910
+ for my $j (\%field_types, \%init, \%type) {
1911
+ $j->{'NetAddress'} = $j->{'String'};
1912
+ }
1913
+
1914
+ #XXX kinda ugly having this here
1915
+ #will consider moving elsewhere if there
1916
+ #are more cases like this.
1917
+ my %extra_code = (
1918
+ FileSystem => <<'EOF',
1919
+ public static final int TYPE_UNKNOWN = 0;
1920
+ public static final int TYPE_NONE = 1;
1921
+ public static final int TYPE_LOCAL_DISK = 2;
1922
+ public static final int TYPE_NETWORK = 3;
1923
+ public static final int TYPE_RAM_DISK = 4;
1924
+ public static final int TYPE_CDROM = 5;
1925
+ public static final int TYPE_SWAP = 6;
1926
+
1927
+ public String toString() {
1928
+ return this.getDirName();
1929
+ }
1930
+ EOF
1931
+ NetConnection => <<'EOF',
1932
+ public native String getTypeString();
1933
+
1934
+ public native static String getStateString(int state);
1935
+
1936
+ public String getStateString() {
1937
+ return getStateString(this.state);
1938
+ }
1939
+ EOF
1940
+ Mem => <<'EOF',
1941
+ public String toString() {
1942
+ return
1943
+ "Mem: " +
1944
+ (this.total / 1024) + "K av, " +
1945
+ (this.used / 1024) + "K used, " +
1946
+ (this.free / 1024) + "K free";
1947
+ }
1948
+ EOF
1949
+ ResourceLimit => <<'EOF',
1950
+ public static native long INFINITY();
1951
+ EOF
1952
+ Swap => <<'EOF',
1953
+ public String toString() {
1954
+ return
1955
+ "Swap: " +
1956
+ (this.total / 1024) + "K av, " +
1957
+ (this.used / 1024) + "K used, " +
1958
+ (this.free / 1024) + "K free";
1959
+ }
1960
+ EOF
1961
+ ProcState => <<'EOF',
1962
+ public static final char SLEEP = 'S';
1963
+ public static final char RUN = 'R';
1964
+ public static final char STOP = 'T';
1965
+ public static final char ZOMBIE = 'Z';
1966
+ public static final char IDLE = 'D';
1967
+ EOF
1968
+ ProcMem => <<'EOF',
1969
+ /**
1970
+ * @deprecated
1971
+ * @see #getResident()
1972
+ */
1973
+ public long getRss() { return getResident(); }
1974
+ /**
1975
+ * @deprecated
1976
+ * @see #getSize()
1977
+ */
1978
+ public long getVsize() { return getSize(); }
1979
+ EOF
1980
+ );
1981
+
1982
+ sub new {
1983
+ my $class = shift;
1984
+ my $self = $class->SUPER::new(@_);
1985
+ $self->{jsrc} = 'org/hyperic/sigar';
1986
+ return $self;
1987
+ }
1988
+
1989
+ my $jni_file = 'javasigar_generated';
1990
+
1991
+ sub sources {
1992
+ return map { "$jni_file.$_" } qw(c h);
1993
+ }
1994
+
1995
+ sub start {
1996
+ my $self = shift;
1997
+ $self->SUPER::start;
1998
+ my $jsrc = $self->{jsrc};
1999
+ File::Path::mkpath([$jsrc], 0, 0755) unless -d $jsrc;
2000
+ $self->{package} = 'org.hyperic.sigar';
2001
+
2002
+ $self->{cfh} = $self->create("$jni_file.c");
2003
+ my $hfh = $self->{hfh} = $self->create("$jni_file.h");
2004
+
2005
+ my %field_cache;
2006
+ my $i = 0;
2007
+ while (my($class, $fields) = each %SigarWrapper::classes) {
2008
+ next if $field_cache{$class}++;
2009
+ print $hfh "#define JSIGAR_FIELDS_\U$class $i\n";
2010
+ $i++;
2011
+ my $n = 0;
2012
+ for my $field (@$fields) {
2013
+ my $name = $field->{name};
2014
+ print $hfh "# define JSIGAR_FIELDS_\U${class}_${name} $n\n";
2015
+ $n++;
2016
+ }
2017
+ print $hfh "# define JSIGAR_FIELDS_\U${class}_MAX $n\n";
2018
+ }
2019
+ print $hfh "#define JSIGAR_FIELDS_MAX $i\n";
2020
+ }
2021
+
2022
+ sub jname {
2023
+ my $jname = shift;
2024
+ #special case for nfs
2025
+ return $jname eq 'null' ? "_$jname" : $jname;
2026
+ }
2027
+
2028
+ #using mega-method pattern here
2029
+ sub generate_class {
2030
+ my($self, $func) = @_;
2031
+
2032
+ my $cfh = $self->{cfh};
2033
+ my $hfh = $self->{hfh};
2034
+
2035
+ my $class = $func->{name};
2036
+ my $cname = $func->{cname};
2037
+
2038
+ my $java_class = "$self->{package}.$class";
2039
+ (my $jni_prefix = "Java.$java_class") =~ s/\./_/g;
2040
+
2041
+ my $args_proto = "";
2042
+ my $args = "";
2043
+ my $decl_string = "";
2044
+ my $get_string = "";
2045
+ my $release_string = "";
2046
+
2047
+ my $jname = lcfirst $class;
2048
+
2049
+ if ($func->{num_args} == 1) {
2050
+ $args = " $func->{arg}, ";
2051
+ if ($func->{is_proc}) {
2052
+ $args_proto = ", jlong pid";
2053
+ }
2054
+ else {
2055
+ $args_proto = ", jstring jname";
2056
+ $decl_string = "const char *name;";
2057
+ $get_string = "name = jname ? JENV->GetStringUTFChars(env, jname, 0) : NULL;";
2058
+ $release_string = "if (jname) JENV->ReleaseStringUTFChars(env, jname, name);";
2059
+ }
2060
+ }
2061
+
2062
+ my $nativefunc = join '_', $jni_prefix, 'gather';
2063
+
2064
+ my $proto = join "\n",
2065
+ "JNIEXPORT void JNICALL $nativefunc",
2066
+ "(JNIEnv *env, jobject obj, jobject sigar_obj$args_proto)";
2067
+
2068
+ my $jfh = $self->create_jfile($class);
2069
+
2070
+ print $cfh <<EOF if $func->{has_get};
2071
+
2072
+ $proto;
2073
+
2074
+ $proto
2075
+ {
2076
+ $func->{sigar_type} s;
2077
+ int status;
2078
+ jclass cls = JENV->GetObjectClass(env, obj);
2079
+ $decl_string
2080
+ dSIGAR_VOID;
2081
+
2082
+ $get_string
2083
+
2084
+ status = $func->{sigar_function}(sigar,${args}&s);
2085
+
2086
+ $release_string
2087
+
2088
+ if (status != SIGAR_OK) {
2089
+ sigar_throw_error(env, jsigar, status);
2090
+ return;
2091
+ }
2092
+
2093
+ EOF
2094
+
2095
+ my $jargs_proto = 'Sigar sigar';
2096
+ my $jargs = 'sigar';
2097
+
2098
+ if ($func->{is_proc}) {
2099
+ $jargs_proto .= ', long pid';
2100
+ $jargs .= ", pid";
2101
+ }
2102
+ elsif ($func->{num_args} == 1) {
2103
+ $jargs_proto .= ', String name';
2104
+ $jargs .= ", name";
2105
+ }
2106
+
2107
+ my $cache_field_ids = 1;
2108
+
2109
+ my $uid = 0;
2110
+
2111
+ for my $field (@{ $func->{fields} }) {
2112
+ $uid +=
2113
+ SigarWrapper::hash($field->{type}) +
2114
+ SigarWrapper::hash($field->{name});
2115
+ }
2116
+
2117
+ print $jfh <<EOF;
2118
+ package $self->{package};
2119
+
2120
+ import java.util.HashMap;
2121
+ import java.util.Map;
2122
+
2123
+ /**
2124
+ * $class sigar class.
2125
+ */
2126
+ public class $class implements java.io.Serializable {
2127
+
2128
+ private static final long serialVersionUID = ${uid}L;
2129
+
2130
+ public $class() { }
2131
+
2132
+ public native void gather($jargs_proto) throws SigarException;
2133
+
2134
+ /**
2135
+ * This method is not intended to be called directly.
2136
+ * use Sigar.get$class() instead.
2137
+ * \@exception SigarException on failure.
2138
+ * \@see $self->{package}.Sigar#get$class
2139
+ */
2140
+ static $class fetch($jargs_proto) throws SigarException {
2141
+ $class $jname = new $class();
2142
+ $jname.gather($jargs);
2143
+ return $jname;
2144
+ }
2145
+
2146
+ EOF
2147
+
2148
+ my(@copy, @tostring);
2149
+ my $setter = "JAVA_SIGAR_SET_FIELDS_\U$class";
2150
+ my $getter = "JAVA_SIGAR_GET_FIELDS_\U$class";
2151
+ my @setter = ("\#define $setter(cls, obj, s)");
2152
+ my @getter = ("\#define $getter(obj, s)");
2153
+ my $init_define = "JAVA_SIGAR_INIT_FIELDS_\U$class";
2154
+ my $field_class_ix = "JSIGAR_FIELDS_\U$class";
2155
+ my $field_class_ix = "JSIGAR_FIELDS_\U$class";
2156
+ my $field_class_max = $field_class_ix . '_MAX';
2157
+ my $field_class = "jsigar->fields[$field_class_ix]";
2158
+
2159
+ my @init_fields = ("#define $init_define(cls)",
2160
+ " if (!$field_class) {",
2161
+ " $field_class = ",
2162
+ " malloc(sizeof(*$field_class));",
2163
+ " $field_class->classref = ",
2164
+ " (jclass)JENV->NewGlobalRef(env, cls);",
2165
+ " $field_class->ids = ",
2166
+ " malloc($field_class_max *",
2167
+ " sizeof(*$field_class->ids));");
2168
+
2169
+ for my $field (@{ $func->{fields} }) {
2170
+ my $type = $field->{type};
2171
+ my $name = $field->{name};
2172
+ my $member = $field->{member} || $name;
2173
+ my $desc = $field->{desc} || $name;
2174
+ (my $jname = $name) =~ s/_(\w)/\u$1/g;
2175
+ my $getter = "get\u$jname";
2176
+ $jname = jname($jname);
2177
+ my $sig = qq("$field_types{$type}");
2178
+ my $set = "JENV->Set${type}Field";
2179
+ my $get = "JENV->Get${type}Field";
2180
+
2181
+ my $field_ix = $field_class_ix . "_\U$name";
2182
+ my $get_id = qq|JENV->GetFieldID(env, cls, "$jname", $sig)|;
2183
+ my $id_cache = "$field_class->ids[$field_ix]";
2184
+
2185
+ my $id_lookup = $cache_field_ids ?
2186
+ $id_cache : $get_id;
2187
+
2188
+ push @init_fields,
2189
+ " $id_cache = ",
2190
+ " $get_id;";
2191
+
2192
+ push @setter,
2193
+ qq| $set(env, obj, $id_lookup, s.$member);|;
2194
+ push @getter,
2195
+ qq| s.$member = $get(env, obj, $id_lookup);|;
2196
+
2197
+ my $init = $init{$type} || '0';
2198
+ my $jtype = $type{$type} || lcfirst($type);
2199
+ my $platforms = SigarWrapper::supported_platforms($field->{plat});
2200
+
2201
+ print $jfh " $jtype $jname = $init;\n\n";
2202
+ push @copy, " copy.$jname = this.$jname;\n";
2203
+ push @tostring, $jname;
2204
+
2205
+ #documentation
2206
+ print $jfh " /**\n";
2207
+ print $jfh " * Get the $desc.<p>\n";
2208
+ print $jfh " * Supported Platforms: $platforms.\n";
2209
+ print $jfh " * <p>\n";
2210
+ if (my $cmd = ($field->{cmd} || $SigarWrapper::cmds{$class})) {
2211
+ print $jfh " * System equivalent commands:<ul>\n";
2212
+ for my $p (sort keys %$cmd) {
2213
+ print $jfh " * <li> $p: <code>$cmd->{$p}</code><br>\n";
2214
+ }
2215
+ print $jfh " * </ul>\n";
2216
+ }
2217
+ print $jfh " * \@return $desc\n";
2218
+ print $jfh " */\n";
2219
+
2220
+ print $jfh " public $jtype $getter() { return $jname; }\n";
2221
+ }
2222
+
2223
+ print $jfh "\n void copyTo($class copy) {\n", @copy, " }\n";
2224
+
2225
+ my $code = $extra_code{$class};
2226
+ if ($code) {
2227
+ print $jfh $code;
2228
+ }
2229
+
2230
+ my $num_fields = @tostring;
2231
+ print $jfh "\n public Map toMap() {\n";
2232
+ print $jfh " Map map = new HashMap();\n";
2233
+ for (my $i=0; $i<$num_fields; $i++) {
2234
+ my $jfield = $tostring[$i];
2235
+ my $sfield = "str${jfield}";
2236
+ print $jfh " String $sfield = \n";
2237
+ print $jfh " String.valueOf(this.$jfield);\n";
2238
+ print $jfh qq{ if (!"-1".equals($sfield))\n};
2239
+ print $jfh qq{ map.put("\u$jfield", $sfield);\n};
2240
+ }
2241
+ print $jfh " return map;\n";
2242
+ print $jfh " }\n";
2243
+
2244
+ if (!$code or $code !~ /toString/) {
2245
+ print $jfh "\n public String toString() {\n";
2246
+ print $jfh " return toMap().toString();\n";
2247
+ print $jfh " }\n";
2248
+ }
2249
+
2250
+ push @init_fields, " }";
2251
+
2252
+ if ($cache_field_ids) {
2253
+ print $hfh join(' \\' . "\n", @init_fields), "\n\n";
2254
+ print $cfh "\n\n $init_define(cls);\n\n" if $func->{has_get};
2255
+ }
2256
+ else {
2257
+ print $hfh "#define $init_define(cls)\n";
2258
+ }
2259
+
2260
+ print $hfh join(' \\' . "\n", @setter), "\n\n";
2261
+ print $hfh join(' \\' . "\n", @getter), "\n\n";
2262
+ print $cfh "\n\n $setter(cls, obj, s);" if $func->{has_get};
2263
+
2264
+ print $cfh "\n}\n" if $func->{has_get};
2265
+ print $jfh "\n}\n";
2266
+
2267
+ close $jfh;
2268
+ }
2269
+
2270
+ sub finish {
2271
+ my $self = shift;
2272
+ $self->SUPER::finish;
2273
+ }
2274
+
2275
+ sub create_jfile {
2276
+ my($self, $name) = @_;
2277
+ my $jsrc = $self->{jsrc};
2278
+ my $jfile = "$jsrc/$name.java";
2279
+ if (-e "../../src/$jsrc/$name.java") {
2280
+ print "skipping $jfile\n";
2281
+ #dont generate .java if already exists
2282
+ $jfile = undef;
2283
+ }
2284
+ return $self->create($jfile);
2285
+ }
2286
+
2287
+ package SigarWrapper::Perl;
2288
+
2289
+ use vars qw(@ISA);
2290
+ @ISA = qw(SigarWrapper);
2291
+
2292
+ my %field_types = (
2293
+ Long => "sigar_uint64_t",
2294
+ Double => "double",
2295
+ Int => "IV",
2296
+ Char => "char",
2297
+ String => "char *",
2298
+ NetAddress => "Sigar::NetAddress",
2299
+ );
2300
+
2301
+ my $xs_file = 'Sigar_generated.xs';
2302
+
2303
+ sub sources {
2304
+ return $xs_file;
2305
+ }
2306
+
2307
+ sub start {
2308
+ my $self = shift;
2309
+ $self->SUPER::start;
2310
+ $self->{xfh} = $self->create($xs_file);
2311
+ }
2312
+
2313
+ sub generate_class {
2314
+ my($self, $func) = @_;
2315
+
2316
+ my $fh = $self->{xfh};
2317
+ my $class = $func->{name};
2318
+ my $cname = $func->{cname};
2319
+ my $perl_class = "Sigar::$class";
2320
+ my $proto = 'VALUE obj';
2321
+ my $args = 'sigar';
2322
+
2323
+ if ($func->{num_args} == 1) {
2324
+ $args .= ", $func->{arg}";
2325
+ }
2326
+
2327
+ print $fh "\nMODULE = Sigar PACKAGE = Sigar PREFIX = sigar_\n\n";
2328
+
2329
+ print $fh <<EOF if $func->{has_get};
2330
+ $perl_class
2331
+ $cname($args)
2332
+ Sigar sigar
2333
+ EOF
2334
+ if ($func->{arg}) {
2335
+ print $fh " $func->{arg_type} $func->{arg}\n" if $func->{has_get};
2336
+ }
2337
+
2338
+ print $fh <<EOF if $func->{has_get};
2339
+
2340
+ PREINIT:
2341
+ int status;
2342
+
2343
+ CODE:
2344
+ RETVAL = safemalloc(sizeof(*RETVAL));
2345
+ if ((status = $func->{sigar_function}($args, RETVAL)) != SIGAR_OK) {
2346
+ SIGAR_CROAK(sigar, "$cname");
2347
+ }
2348
+
2349
+ OUTPUT:
2350
+ RETVAL
2351
+ EOF
2352
+
2353
+ print $fh <<EOF;
2354
+
2355
+ MODULE = Sigar PACKAGE = $perl_class PREFIX = sigar_
2356
+
2357
+ void
2358
+ DESTROY(obj)
2359
+ $perl_class obj
2360
+
2361
+ CODE:
2362
+ safefree(obj);
2363
+
2364
+ EOF
2365
+
2366
+ for my $field (@{ $func->{fields} }) {
2367
+ my $name = $field->{name};
2368
+ my $type = $field_types{ $field->{type} };
2369
+
2370
+ print $fh <<EOF;
2371
+ $type
2372
+ $name($cname)
2373
+ $perl_class $cname
2374
+
2375
+ CODE:
2376
+ RETVAL = $cname->$name;
2377
+
2378
+ OUTPUT:
2379
+ RETVAL
2380
+
2381
+ EOF
2382
+ }
2383
+ }
2384
+
2385
+ sub finish {
2386
+ my $self = shift;
2387
+ $self->SUPER::finish;
2388
+ }
2389
+
2390
+ package SigarWrapper::Ruby;
2391
+
2392
+ use vars qw(@ISA);
2393
+ @ISA = qw(SigarWrapper);
2394
+
2395
+ my %field_types = (
2396
+ Long => "rb_ll2inum",
2397
+ Double => "rb_float_new",
2398
+ Int => "rb_int2inum",
2399
+ Char => "CHR2FIX",
2400
+ String => "rb_str_new2",
2401
+ NetAddress => "rb_sigar_net_address_to_s",
2402
+ );
2403
+
2404
+ my $rx_file = 'rbsigar_generated.rx';
2405
+
2406
+ sub sources {
2407
+ return $rx_file;
2408
+ }
2409
+
2410
+ sub start {
2411
+ my $self = shift;
2412
+ $self->SUPER::start;
2413
+ $self->{cfh} = $self->create($rx_file);
2414
+ }
2415
+
2416
+ sub add_method {
2417
+ my($self, $class, $name) = @_;
2418
+ push @{ $self->{methods}->{$class} }, $name;
2419
+ }
2420
+
2421
+ sub generate_class {
2422
+ my($self, $func) = @_;
2423
+
2424
+ my $fh = $self->{cfh};
2425
+ my $class = $func->{name};
2426
+ my $cname = $func->{cname};
2427
+ my $ruby_class = "rb_cSigar$class";
2428
+ my $proto = 'VALUE obj';
2429
+ my $args = 'sigar';
2430
+
2431
+ if ($func->{num_args} == 1) {
2432
+ my $arg_type;
2433
+ if ($func->{is_proc}) {
2434
+ $arg_type = 'OBJ2PID';
2435
+ }
2436
+ else {
2437
+ $arg_type = 'StringValuePtr';
2438
+ }
2439
+ $proto .= ", VALUE $func->{arg}";
2440
+ $args .= ", $arg_type($func->{arg})";
2441
+ }
2442
+
2443
+ print $fh <<EOF if $func->{has_get};
2444
+ static VALUE $ruby_class;
2445
+
2446
+ static VALUE rb_sigar_$cname($proto)
2447
+ {
2448
+ SIGAR_GET;
2449
+
2450
+ int status;
2451
+ $func->{sigar_type} *RETVAL = malloc(sizeof(*RETVAL));
2452
+
2453
+ if ((status = $func->{sigar_function}($args, RETVAL)) != SIGAR_OK) {
2454
+ free(RETVAL);
2455
+ rb_raise(rb_eArgError, "%s", sigar_strerror(sigar, status));
2456
+ return Qnil;
2457
+ }
2458
+
2459
+ return Data_Wrap_Struct($ruby_class, 0, rb_sigar_free, RETVAL);
2460
+ }
2461
+ EOF
2462
+
2463
+ for my $field (@{ $func->{fields} }) {
2464
+ my $name = $field->{name};
2465
+ my $type = $field_types{ $field->{type} };
2466
+
2467
+ $self->add_method($class, $name);
2468
+
2469
+ print $fh <<EOF;
2470
+ static VALUE rb_sigar_${class}_${name}(VALUE self)
2471
+ {
2472
+ $func->{sigar_type} *$cname;
2473
+ Data_Get_Struct(self, $func->{sigar_type}, $cname);
2474
+ return $type($cname->$name);
2475
+ }
2476
+ EOF
2477
+ }
2478
+ }
2479
+
2480
+ sub finish {
2481
+ my $self = shift;
2482
+
2483
+ my $fh = $self->{cfh};
2484
+
2485
+ print $fh "static void rb_sigar_define_module_methods(VALUE rclass)\n{\n";
2486
+
2487
+ my $mappings = SigarWrapper::get_mappings();
2488
+
2489
+ for my $func (@$mappings) {
2490
+ my $name = $func->{cname};
2491
+ my $args = $func->{num_args};
2492
+ next unless $func->{has_get};
2493
+ print $fh qq{ rb_define_method(rclass, "$name", rb_sigar_$name, $args);\n};
2494
+ }
2495
+
2496
+ for my $class (sort keys %{ $self->{methods} }) {
2497
+ my $rclass = "rb_cSigar$class";
2498
+ print $fh qq{ $rclass = rb_define_class_under(rclass, "$class", rb_cObject);\n};
2499
+ for my $method (@{ $self->{methods}->{$class} }) {
2500
+ print $fh qq{ rb_define_method($rclass, "$method", rb_sigar_${class}_$method, 0);\n};
2501
+ }
2502
+ }
2503
+
2504
+ print $fh "}\n";
2505
+
2506
+ $self->SUPER::finish;
2507
+ }
2508
+
2509
+ package SigarWrapper::PHP;
2510
+
2511
+ use vars qw(@ISA);
2512
+ @ISA = qw(SigarWrapper);
2513
+
2514
+ my %field_types = (
2515
+ Long => "RETURN_LONG",
2516
+ Double => "RETURN_DOUBLE",
2517
+ Int => "RETURN_LONG",
2518
+ Char => "RETURN_LONG",
2519
+ String => "PHP_SIGAR_RETURN_STRING",
2520
+ NetAddress => "PHP_SIGAR_RETURN_NETADDR",
2521
+ );
2522
+
2523
+ my $php_file = 'php_sigar_generated.c';
2524
+
2525
+ sub sources {
2526
+ return $php_file;
2527
+ }
2528
+
2529
+ sub start {
2530
+ my $self = shift;
2531
+ $self->SUPER::start;
2532
+ $self->{cfh} = $self->create($php_file);
2533
+ }
2534
+
2535
+ sub generate_class {
2536
+ my($self, $func) = @_;
2537
+
2538
+ my $cfh = $self->{cfh};
2539
+ my $class = $func->{name};
2540
+ my $cname = $func->{cname};
2541
+ my $php_class = "Sigar::$class";
2542
+ my $parse_args = "";
2543
+ my $vars = "";
2544
+ my $args = 'sigar';
2545
+ my $arginfo = $args;
2546
+
2547
+ if ($func->{num_args} == 1) {
2548
+ if ($func->{is_proc}) {
2549
+ $parse_args = 'zSIGAR_PARSE_PID;';
2550
+ $arginfo .= '_pid';
2551
+ $vars = "long $func->{arg};\n";
2552
+ }
2553
+ else {
2554
+ $parse_args .= 'zSIGAR_PARSE_NAME;';
2555
+ $arginfo .= '_name';
2556
+ $vars = "char *$func->{arg}; int $func->{arg}_len;\n";
2557
+ }
2558
+ $args .= ", $func->{arg}";
2559
+ }
2560
+
2561
+ my $prefix = "php_$func->{sigar_prefix}_";
2562
+ my $functions = $prefix . 'functions';
2563
+ my $handlers = $prefix . 'object_handlers';
2564
+ my $init = $prefix . 'init';
2565
+
2566
+ my $ctor = $prefix . 'new';
2567
+
2568
+ my(@functions);
2569
+
2570
+ for my $field (@{ $func->{fields} }) {
2571
+ my $name = $field->{name};
2572
+ my $type = $field_types{ $field->{type} };
2573
+ my $method = $prefix . $name;
2574
+
2575
+ push @functions, { name => $name, me => $method };
2576
+ print $cfh <<EOF;
2577
+ static PHP_FUNCTION($method)
2578
+ {
2579
+ $func->{sigar_type} *$cname = ($func->{sigar_type} *)zSIGAR_OBJ;
2580
+ $type($cname->$name);
2581
+ }
2582
+ EOF
2583
+ }
2584
+
2585
+ print $cfh <<EOF;
2586
+ static zend_object_handlers $handlers;
2587
+
2588
+ static zend_object_value $ctor(zend_class_entry *class_type TSRMLS_DC)
2589
+ {
2590
+ return php_sigar_ctor(php_sigar_obj_dtor,
2591
+ &$handlers,
2592
+ NULL,
2593
+ class_type);
2594
+ }
2595
+
2596
+ static zend_function_entry ${functions}[] = {
2597
+ EOF
2598
+
2599
+ for my $func (@functions) {
2600
+ print $cfh " PHP_ME_MAPPING($func->{name}, $func->{me}, NULL)\n";
2601
+ }
2602
+
2603
+ print $cfh <<EOF;
2604
+ {NULL, NULL, NULL}
2605
+ };
2606
+ EOF
2607
+
2608
+ print $cfh <<EOF;
2609
+ static void $init(void)
2610
+ {
2611
+ zend_class_entry ce;
2612
+
2613
+ PHP_SIGAR_INIT_HANDLERS($handlers);
2614
+ INIT_CLASS_ENTRY(ce, "$php_class", $functions);
2615
+ ce.create_object = $ctor;
2616
+ zend_register_internal_class(&ce TSRMLS_CC);
2617
+ }
2618
+ EOF
2619
+
2620
+ print $cfh <<EOF if $func->{has_get};
2621
+ static PHP_FUNCTION($func->{sigar_function})
2622
+ {
2623
+ int status;
2624
+ zSIGAR;
2625
+
2626
+ $func->{sigar_type} *RETVAL = emalloc(sizeof(*RETVAL));
2627
+ $vars
2628
+ $parse_args
2629
+
2630
+ if ((status = $func->{sigar_function}($args, RETVAL)) != SIGAR_OK) {
2631
+ efree(RETVAL);
2632
+ RETURN_FALSE;
2633
+ }
2634
+ else {
2635
+ php_sigar_obj_new("$php_class", return_value)->ptr = RETVAL;
2636
+ }
2637
+ }
2638
+ EOF
2639
+ }
2640
+
2641
+ sub finish {
2642
+ my $self = shift;
2643
+
2644
+ my $mappings = $self->get_mappings;
2645
+ my $cfh = $self->{cfh};
2646
+ my $nl = '\\' . "\n";
2647
+
2648
+ print $cfh "#define PHP_SIGAR_FUNCTIONS $nl";
2649
+ for my $func (@$mappings) {
2650
+ next unless $func->{has_get};
2651
+ #XXX PHP_ME_MAPPING has another arg in 5.2
2652
+ print $cfh " PHP_ME_MAPPING($func->{cname}, $func->{sigar_function}, NULL)";
2653
+ if ($func == $mappings->[-1]) {
2654
+ print $cfh "\n";
2655
+ }
2656
+ else {
2657
+ print $cfh $nl;
2658
+ }
2659
+ }
2660
+
2661
+ print $cfh "#define PHP_SIGAR_INIT $nl";
2662
+ for my $func (@$mappings) {
2663
+ print $cfh " php_$func->{sigar_prefix}_init()";
2664
+ if ($func == $mappings->[-1]) {
2665
+ print $cfh "\n";
2666
+ }
2667
+ else {
2668
+ print $cfh ";$nl";
2669
+ }
2670
+ }
2671
+
2672
+ $self->SUPER::finish;
2673
+ }
2674
+
2675
+ package SigarWrapper::Python;
2676
+
2677
+ use vars qw(@ISA);
2678
+ @ISA = qw(SigarWrapper);
2679
+
2680
+ my %field_types = (
2681
+ Long => "PyLong_FromUnsignedLongLong",
2682
+ Double => "PyFloat_FromDouble",
2683
+ Int => "PyInt_FromLong",
2684
+ Char => "PySigarInt_FromChar",
2685
+ String => "PyString_FromString",
2686
+ NetAddress => "PySigarString_FromNetAddr",
2687
+ );
2688
+
2689
+ my $c_file = '_sigar_generated.c';
2690
+
2691
+ sub sources {
2692
+ return $c_file;
2693
+ }
2694
+
2695
+ sub start {
2696
+ my $self = shift;
2697
+ $self->SUPER::start;
2698
+ $self->{cfh} = $self->create($c_file);
2699
+ }
2700
+
2701
+ sub pyclass {
2702
+ my $class = shift;
2703
+ return "Sigar.$class";
2704
+ }
2705
+
2706
+ sub pytype {
2707
+ my $class = shift;
2708
+ return 'pysigar_PySigar' . $class . 'Type';
2709
+ }
2710
+
2711
+ sub generate_class {
2712
+ my($self, $func) = @_;
2713
+
2714
+ my $cfh = $self->{cfh};
2715
+ my $pyclass = pyclass($func->{name});
2716
+ my $pytype = pytype($func->{name});
2717
+ my $cname = $func->{cname};
2718
+ my $parse_args = "";
2719
+ my $vars = "";
2720
+ my $args = 'sigar';
2721
+
2722
+ if ($func->{num_args} == 1) {
2723
+ if ($func->{is_proc}) {
2724
+ $parse_args = 'PySigar_ParsePID;';
2725
+ $vars = "long $func->{arg};\n";
2726
+ }
2727
+ else {
2728
+ $parse_args .= 'PySigar_ParseName;';
2729
+ $vars = "char *$func->{arg}; int $func->{arg}_len;\n";
2730
+ }
2731
+ $args .= ", $func->{arg}";
2732
+ }
2733
+
2734
+ my $prefix = "py$func->{sigar_prefix}_";
2735
+ my $methods = $prefix . 'methods';
2736
+ my $dtor = 'pysigar_free';
2737
+
2738
+ for my $field (@{ $func->{fields} }) {
2739
+ my $name = $field->{name};
2740
+ my $type = $field_types{ $field->{type} };
2741
+ my $method = $prefix . $name;
2742
+
2743
+ print $cfh <<EOF;
2744
+ static PyObject *$method(PyObject *self, PyObject *args)
2745
+ {
2746
+ $func->{sigar_type} *$cname = ($func->{sigar_type} *)PySIGAR_OBJ->ptr;
2747
+ return $type($cname->$name);
2748
+ }
2749
+ EOF
2750
+ }
2751
+
2752
+ print $cfh "static PyMethodDef $methods [] = {\n";
2753
+ for my $field (@{ $func->{fields} }) {
2754
+ my $name = $field->{name};
2755
+ print $cfh qq( { "$name", ${prefix}$name, METH_NOARGS, "$name" },\n);
2756
+ }
2757
+ print $cfh " {NULL}\n};\n";
2758
+
2759
+ print $cfh <<EOF;
2760
+ static PyTypeObject $pytype = {
2761
+ PyObject_HEAD_INIT(NULL)
2762
+ 0, /*ob_size*/
2763
+ "$pyclass", /*tp_name*/
2764
+ sizeof(PySigarObject), /*tp_basicsize*/
2765
+ 0, /*tp_itemsize*/
2766
+ pysigar_free, /*tp_dealloc*/
2767
+ 0, /*tp_print*/
2768
+ 0, /*tp_getattr*/
2769
+ 0, /*tp_setattr*/
2770
+ 0, /*tp_compare*/
2771
+ 0, /*tp_repr*/
2772
+ 0, /*tp_as_number*/
2773
+ 0, /*tp_as_sequence*/
2774
+ 0, /*tp_as_mapping*/
2775
+ 0, /*tp_hash */
2776
+ 0, /*tp_call*/
2777
+ 0, /*tp_str*/
2778
+ 0, /*tp_getattro*/
2779
+ 0, /*tp_setattro*/
2780
+ 0, /*tp_as_buffer*/
2781
+ PySigar_TPFLAGS, /*tp_flags*/
2782
+ 0, /*tp_doc*/
2783
+ 0, /*tp_traverse*/
2784
+ 0, /*tp_clear*/
2785
+ 0, /*tp_richcompare*/
2786
+ 0, /*tp_weaklistoffset*/
2787
+ 0, /*tp_iter*/
2788
+ 0, /*tp_iternext*/
2789
+ $methods, /*tp_methods*/
2790
+ 0, /*tp_members*/
2791
+ 0, /*tp_getset*/
2792
+ 0, /*tp_base*/
2793
+ 0, /*tp_dict*/
2794
+ 0, /*tp_descr_get*/
2795
+ 0, /*tp_descr_set*/
2796
+ 0, /*tp_dictoffset*/
2797
+ 0, /*tp_init*/
2798
+ 0, /*tp_alloc*/
2799
+ 0 /*tp_new*/
2800
+ };
2801
+ EOF
2802
+
2803
+ print $cfh <<EOF if $func->{has_get};
2804
+ static PyObject *py$func->{sigar_function}(PyObject *self, PyObject *args)
2805
+ {
2806
+ int status;
2807
+ sigar_t *sigar = PySIGAR;
2808
+ $func->{sigar_type} *RETVAL = malloc(sizeof(*RETVAL));
2809
+ $vars
2810
+ $parse_args
2811
+
2812
+ if ((status = $func->{sigar_function}($args, RETVAL)) != SIGAR_OK) {
2813
+ free(RETVAL);
2814
+ PySigar_Croak();
2815
+ return NULL;
2816
+ }
2817
+ else {
2818
+ PyObject *self = PySigar_new($pytype);
2819
+ PySIGAR_OBJ->ptr = RETVAL;
2820
+ return self;
2821
+ }
2822
+ }
2823
+ EOF
2824
+ }
2825
+
2826
+ sub finish {
2827
+ my $self = shift;
2828
+
2829
+ my $mappings = $self->get_mappings;
2830
+ my $cfh = $self->{cfh};
2831
+ my $nl = '\\' . "\n";
2832
+
2833
+ print $cfh "#define PY_SIGAR_METHODS $nl";
2834
+ for my $func (@$mappings) {
2835
+ next unless $func->{has_get};
2836
+ my $arginfo = $func->{num_args} ? 'METH_VARARGS' : 'METH_NOARGS';
2837
+ print $cfh qq( {"$func->{cname}", py$func->{sigar_function}, $arginfo, NULL},);
2838
+ if ($func == $mappings->[-1]) {
2839
+ print $cfh "\n";
2840
+ }
2841
+ else {
2842
+ print $cfh $nl;
2843
+ }
2844
+ }
2845
+
2846
+ print $cfh "#define PY_SIGAR_ADD_TYPES $nl";
2847
+ for my $func (@$mappings) {
2848
+ my $pyclass = pyclass($func->{name});
2849
+ my $pytype = pytype($func->{name});
2850
+ print $cfh qq{ PySigar_AddType("$pyclass", $pytype)};
2851
+ if ($func == $mappings->[-1]) {
2852
+ print $cfh "\n";
2853
+ }
2854
+ else {
2855
+ print $cfh ";$nl";
2856
+ }
2857
+ }
2858
+
2859
+ $self->SUPER::finish;
2860
+ }
2861
+
2862
+ package SigarWrapper::Erlang;
2863
+
2864
+ use vars qw(@ISA);
2865
+ @ISA = qw(SigarWrapper);
2866
+
2867
+ my %field_types = (
2868
+ Long => "esigar_encode_ulonglong",
2869
+ Double => "esigar_encode_double",
2870
+ Int => "esigar_encode_long",
2871
+ Char => "esigar_encode_char",
2872
+ String => "esigar_encode_string",
2873
+ NetAddress => "esigar_encode_netaddr",
2874
+ );
2875
+
2876
+ my $c_file = 'priv/gen/sigar_drv_gen.c';
2877
+ my $h_file = 'priv/gen/sigar.hrl';
2878
+ my $g_file = 'priv/gen/sigar_gen.hrl';
2879
+
2880
+ sub sources {
2881
+ return $c_file;
2882
+ }
2883
+
2884
+ sub start {
2885
+ my $self = shift;
2886
+ $self->SUPER::start;
2887
+ $self->{cfh} = $self->create($c_file);
2888
+ $self->{hfh} = $self->create($h_file);
2889
+ $self->{gfh} = $self->create($g_file);
2890
+ }
2891
+
2892
+ sub generate_class {
2893
+ my($self, $func) = @_;
2894
+
2895
+ my $cfh = $self->{cfh};
2896
+ my $cname = $func->{cname};
2897
+ my $parse_args = "";
2898
+ my $vars = "";
2899
+ my $args = 'sigar';
2900
+
2901
+ if ($func->{num_args} == 1) {
2902
+ if ($func->{is_proc}) {
2903
+ $parse_args = 'pid = esigar_pid_get(sigar, bytes);';
2904
+ $vars = "long $func->{arg};\n";
2905
+ }
2906
+ else {
2907
+ $parse_args .= 'name = bytes;';
2908
+ $vars = "char *$func->{arg};\n";
2909
+ }
2910
+ $args .= ", $func->{arg}";
2911
+ }
2912
+
2913
+ my $encoder = "esigar_encode_$cname";
2914
+ my $n = scalar @{ $func->{fields} };
2915
+
2916
+ print $cfh <<EOF;
2917
+ static void $encoder(ei_x_buff *x,
2918
+ $func->{sigar_type} *$cname)
2919
+ {
2920
+ ei_x_encode_list_header(x, $n);
2921
+ EOF
2922
+
2923
+ for my $field (@{ $func->{fields} }) {
2924
+ my $name = $field->{name};
2925
+ my $type = $field_types{ $field->{type} };
2926
+
2927
+ print $cfh qq{ $type(x, "$name", $cname->$name);\n};
2928
+ }
2929
+
2930
+ print $cfh " ei_x_encode_empty_list(x);\n}\n\n";
2931
+
2932
+ print $cfh <<EOF if $func->{has_get};
2933
+ static int e$func->{sigar_function}(ErlDrvPort port, sigar_t *sigar, char *bytes)
2934
+ {
2935
+ int status;
2936
+ ei_x_buff x;
2937
+ $func->{sigar_type} $cname;
2938
+ $vars
2939
+ $parse_args
2940
+
2941
+ ESIGAR_NEW(&x);
2942
+ if ((status = $func->{sigar_function}($args, &$cname)) == SIGAR_OK) {
2943
+ ESIGAR_OK(&x);
2944
+
2945
+ $encoder(&x, &$cname);
2946
+
2947
+ ESIGAR_SEND(port, &x);
2948
+ }
2949
+ else {
2950
+ ESIGAR_ERROR(&x, sigar, status);
2951
+ }
2952
+ return status;
2953
+ }
2954
+ EOF
2955
+ }
2956
+
2957
+ my(@nongens) =
2958
+ qw{net_interface_list net_route_list net_connection_list
2959
+ file_system_list cpu_info_list arp_list who_list
2960
+ loadavg};
2961
+
2962
+ sub finish {
2963
+ my $self = shift;
2964
+
2965
+ my $mappings = $self->get_mappings;
2966
+ my $cfh = $self->{cfh};
2967
+ my $hfh = $self->{hfh};
2968
+ my $gfh = $self->{gfh};
2969
+ my $ncmd = 1;
2970
+
2971
+ for my $ngen (@nongens) {
2972
+ my $cmd = uc $ngen;
2973
+ print $cfh "#define ESIGAR_$cmd $ncmd\n";
2974
+ print $hfh "-define($cmd, $ncmd).\n";
2975
+ $ncmd++;
2976
+ }
2977
+
2978
+ for my $func (@$mappings) {
2979
+ next unless $func->{has_get};
2980
+ my $name = $func->{cname};
2981
+ my $cmd = uc $name;
2982
+ my $nargs = 1 + $func->{num_args};
2983
+ print $cfh "#define ESIGAR_$cmd $ncmd\n";
2984
+ print $hfh "-define($cmd, $ncmd).\n";
2985
+ print $hfh "-export([$name/$nargs]).\n";
2986
+ $ncmd++;
2987
+ }
2988
+
2989
+ print $cfh <<EOF;
2990
+
2991
+ static int esigar_dispatch(ErlDrvPort port, sigar_t *sigar, int cmd, char *bytes) {
2992
+ switch (cmd) {
2993
+ EOF
2994
+ for my $func (@$mappings) {
2995
+ next unless $func->{has_get};
2996
+ my $name = $func->{cname};
2997
+ my $cmd = uc $name;
2998
+ my $arg = "";
2999
+ if ($func->{num_args}) {
3000
+ $arg = ", Arg";
3001
+ }
3002
+
3003
+ print $gfh <<EOF;
3004
+ $name({sigar, S}$arg) ->
3005
+ do_command(S, ?$cmd$arg).
3006
+
3007
+ EOF
3008
+ print $cfh <<EOF
3009
+ case ESIGAR_$cmd:
3010
+ return e$func->{sigar_function}(port, sigar, bytes);
3011
+ EOF
3012
+ }
3013
+ print $cfh <<EOF;
3014
+ default:
3015
+ esigar_notimpl(port, sigar, cmd);
3016
+ return SIGAR_ENOTIMPL;
3017
+ }
3018
+ }
3019
+ EOF
3020
+
3021
+ $self->SUPER::finish;
3022
+ }
3023
+
3024
+ 1;
3025
+ __END__