ruby-libgtop2 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/CHANGELOG.txt +30 -0
  2. data/History.txt +6 -0
  3. data/INSTALL.txt +19 -0
  4. data/Manifest.txt +53 -0
  5. data/README.txt +21 -0
  6. data/Rakefile +59 -0
  7. data/TODO +4 -0
  8. data/TUTORIAL.txt +28 -0
  9. data/examples/README +1 -0
  10. data/examples/first.rb +220 -0
  11. data/examples/mountlist.rb +30 -0
  12. data/examples/netload.rb +50 -0
  13. data/examples/procmap.rb +41 -0
  14. data/examples/second.rb +207 -0
  15. data/examples/smp.rb +76 -0
  16. data/examples/sysdeps.rb +86 -0
  17. data/ext/libgtop/MANIFEST +30 -0
  18. data/ext/libgtop/Makefile +149 -0
  19. data/ext/libgtop/extconf.rb +9 -0
  20. data/ext/libgtop/mkmf.log +27 -0
  21. data/ext/libgtop/rb_glibtop.c +61 -0
  22. data/ext/libgtop/rb_glibtop.h +15 -0
  23. data/ext/libgtop/rb_glibtop_cpu.c +69 -0
  24. data/ext/libgtop/rb_glibtop_fsusage.c +43 -0
  25. data/ext/libgtop/rb_glibtop_init.c +25 -0
  26. data/ext/libgtop/rb_glibtop_loadavg.c +42 -0
  27. data/ext/libgtop/rb_glibtop_mem.c +39 -0
  28. data/ext/libgtop/rb_glibtop_mountlist.c +53 -0
  29. data/ext/libgtop/rb_glibtop_msg_limits.c +37 -0
  30. data/ext/libgtop/rb_glibtop_netlist.c +36 -0
  31. data/ext/libgtop/rb_glibtop_netload.c +82 -0
  32. data/ext/libgtop/rb_glibtop_ppp.c +39 -0
  33. data/ext/libgtop/rb_glibtop_proc_args.c +39 -0
  34. data/ext/libgtop/rb_glibtop_proc_kernel.c +50 -0
  35. data/ext/libgtop/rb_glibtop_proc_map.c +69 -0
  36. data/ext/libgtop/rb_glibtop_proc_mem.c +37 -0
  37. data/ext/libgtop/rb_glibtop_proc_open_files.c +65 -0
  38. data/ext/libgtop/rb_glibtop_proc_segment.c +39 -0
  39. data/ext/libgtop/rb_glibtop_proc_signal.c +48 -0
  40. data/ext/libgtop/rb_glibtop_proc_state.c +46 -0
  41. data/ext/libgtop/rb_glibtop_proc_time.c +54 -0
  42. data/ext/libgtop/rb_glibtop_proc_uid.c +58 -0
  43. data/ext/libgtop/rb_glibtop_proclist.c +56 -0
  44. data/ext/libgtop/rb_glibtop_sem_limits.c +40 -0
  45. data/ext/libgtop/rb_glibtop_shm_limits.c +35 -0
  46. data/ext/libgtop/rb_glibtop_swap.c +36 -0
  47. data/ext/libgtop/rb_glibtop_sysdeps.c +78 -0
  48. data/ext/libgtop/rb_glibtop_uptime.c +36 -0
  49. data/lib/libgtop.rb +3 -0
  50. data/lib/libgtop/version.rb +9 -0
  51. data/setup.rb +1585 -0
  52. data/test/ruby-libgtop2_test.rb +11 -0
  53. data/test/test_helper.rb +4 -0
  54. metadata +98 -0
@@ -0,0 +1,39 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/mem.h>
11
+
12
+
13
+ static VALUE rb_glibtop_mem(VALUE self)
14
+ {
15
+ glibtop_mem buf;
16
+ VALUE hash;
17
+
18
+ glibtop_get_mem(&buf);
19
+
20
+ hash = rb_hash_new();
21
+
22
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
23
+ rb_hash_aset(hash, rb_str_new2("total"), rb_uint2inum(buf.total));
24
+ rb_hash_aset(hash, rb_str_new2("used"), rb_uint2inum(buf.used));
25
+ rb_hash_aset(hash, rb_str_new2("free"), rb_uint2inum(buf.free));
26
+ rb_hash_aset(hash, rb_str_new2("shared"), rb_uint2inum(buf.shared));
27
+ rb_hash_aset(hash, rb_str_new2("buffer"), rb_uint2inum(buf.buffer));
28
+ rb_hash_aset(hash, rb_str_new2("cached"), rb_uint2inum(buf.cached));
29
+ rb_hash_aset(hash, rb_str_new2("user"), rb_uint2inum(buf.user));
30
+ rb_hash_aset(hash, rb_str_new2("locked"), rb_uint2inum(buf.locked));
31
+
32
+ return hash;
33
+ }
34
+
35
+
36
+ void Init_glibtop_mem()
37
+ {
38
+ rb_define_method(cLibGTop, "mem", rb_glibtop_mem, 0);
39
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/mountlist.h>
11
+
12
+
13
+ static VALUE rb_glibtop_mountlist(VALUE self, VALUE all_fs)
14
+ {
15
+ glibtop_mountlist buf;
16
+ glibtop_mountentry* mount_entries_buf;
17
+ VALUE hash, mount_entries, mount;
18
+ int i;
19
+
20
+ Check_Type(all_fs, T_FIXNUM);
21
+ mount_entries_buf = glibtop_get_mountlist(&buf, FIX2INT(all_fs));
22
+
23
+ hash = rb_hash_new();
24
+
25
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
26
+ rb_hash_aset(hash, rb_str_new2("number"), rb_uint2inum(buf.number));
27
+ rb_hash_aset(hash, rb_str_new2("total"), rb_uint2inum(buf.total));
28
+ rb_hash_aset(hash, rb_str_new2("size"), rb_uint2inum(buf.size));
29
+
30
+ mount_entries = rb_ary_new2(buf.number);
31
+ for (i = 0; i < buf.number; i++){
32
+ mount = rb_hash_new();
33
+
34
+ rb_hash_aset(mount, rb_str_new2("dev"), rb_uint2inum(mount_entries_buf[i].dev));
35
+ rb_hash_aset(mount, rb_str_new2("devname"), rb_str_new2(mount_entries_buf[i].devname));
36
+ rb_hash_aset(mount, rb_str_new2("mountdir"), rb_str_new2(mount_entries_buf[i].mountdir));
37
+ rb_hash_aset(mount, rb_str_new2("type"), rb_str_new2(mount_entries_buf[i].type));
38
+
39
+ rb_ary_push(mount_entries, mount);
40
+ }
41
+
42
+ rb_hash_aset(hash, rb_str_new2("mount_entries"), mount_entries);
43
+
44
+ g_free(mount_entries_buf);
45
+
46
+ return hash;
47
+ }
48
+
49
+
50
+ void Init_glibtop_mountlist()
51
+ {
52
+ rb_define_method(cLibGTop, "mountlist", rb_glibtop_mountlist, 1);
53
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+
11
+
12
+ static VALUE rb_glibtop_msg_limits(VALUE self)
13
+ {
14
+ glibtop_msg_limits buf;
15
+ VALUE hash;
16
+
17
+ glibtop_get_msg_limits(&buf);
18
+
19
+ hash = rb_hash_new();
20
+
21
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
22
+ rb_hash_aset(hash, rb_str_new2("msgpool"), rb_uint2inum(buf.msgpool));
23
+ rb_hash_aset(hash, rb_str_new2("msgmap"), rb_uint2inum(buf.msgmap));
24
+ rb_hash_aset(hash, rb_str_new2("msgmax"), rb_uint2inum(buf.msgmax));
25
+ rb_hash_aset(hash, rb_str_new2("msgmnb"), rb_uint2inum(buf.msgmnb));
26
+ rb_hash_aset(hash, rb_str_new2("msgmni"), rb_uint2inum(buf.msgmni));
27
+ rb_hash_aset(hash, rb_str_new2("msgssz"), rb_uint2inum(buf.msgssz));
28
+ rb_hash_aset(hash, rb_str_new2("msgtql"), rb_uint2inum(buf.msgtql));
29
+
30
+ return hash;
31
+ }
32
+
33
+
34
+ void Init_glibtop_msg_limits()
35
+ {
36
+ rb_define_method(cLibGTop, "msg_limits", rb_glibtop_msg_limits, 0);
37
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #if (LIBGTOP_CHECK_VERSION(2, 9, 0))
11
+ #include <glibtop/netlist.h>
12
+
13
+ static VALUE rb_glibtop_netlist(VALUE self)
14
+ {
15
+ glibtop_netlist buf;
16
+ char** devices;
17
+ VALUE array;
18
+ guint32 i;
19
+
20
+ array = rb_ary_new();
21
+
22
+ devices = glibtop_get_netlist(&buf);
23
+ for ( i = 0; i < buf.number; ++i) {
24
+ rb_ary_push(array, rb_str_new2(devices[i]));
25
+ }
26
+
27
+ g_free(devices);
28
+
29
+ return array;
30
+ }
31
+
32
+ void Init_glibtop_netlist()
33
+ {
34
+ rb_define_method(cLibGTop, "netlist", rb_glibtop_netlist, 0);
35
+ }
36
+ #endif
@@ -0,0 +1,82 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/netload.h>
11
+
12
+
13
+ static VALUE rb_glibtop_netload(VALUE self, VALUE interface)
14
+ {
15
+ glibtop_netload buf;
16
+ pid_t _pid;
17
+ VALUE hash, ary;
18
+ int i;
19
+
20
+ glibtop_get_netload(&buf, StringValuePtr(interface));
21
+
22
+ hash = rb_hash_new();
23
+
24
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
25
+ rb_hash_aset(hash, rb_str_new2("if_flags"), rb_uint2inum(buf.if_flags));
26
+ rb_hash_aset(hash, rb_str_new2("mtu"), rb_uint2inum(buf.mtu));
27
+ rb_hash_aset(hash, rb_str_new2("subnet"), rb_uint2inum(buf.subnet));
28
+ rb_hash_aset(hash, rb_str_new2("address"), rb_uint2inum(buf.address));
29
+ rb_hash_aset(hash, rb_str_new2("packets_in"), rb_uint2inum(buf.packets_in));
30
+ rb_hash_aset(hash, rb_str_new2("packets_out"), rb_uint2inum(buf.packets_out));
31
+ rb_hash_aset(hash, rb_str_new2("packets_total"), rb_uint2inum(buf.packets_total));
32
+ rb_hash_aset(hash, rb_str_new2("bytes_in"), rb_uint2inum(buf.bytes_in));
33
+ rb_hash_aset(hash, rb_str_new2("bytes_out"), rb_uint2inum(buf.bytes_out));
34
+ rb_hash_aset(hash, rb_str_new2("bytes_total"), rb_uint2inum(buf.bytes_total));
35
+ rb_hash_aset(hash, rb_str_new2("errors_in"), rb_uint2inum(buf.errors_in));
36
+ rb_hash_aset(hash, rb_str_new2("errors_out"), rb_uint2inum(buf.errors_out));
37
+ rb_hash_aset(hash, rb_str_new2("errors_total"), rb_uint2inum(buf.errors_total));
38
+ rb_hash_aset(hash, rb_str_new2("collisions"), rb_uint2inum(buf.collisions));
39
+ #if (LIBGTOP_CHECK_VERSION(2, 7, 4))
40
+ ary = rb_ary_new();
41
+ for (i = 0; i < sizeof(buf.address6); i++) {
42
+ rb_ary_push(ary, INT2FIX(buf.address6[i]));
43
+ }
44
+ rb_hash_aset(hash, rb_str_new2("address6"), ary);
45
+ ary = rb_ary_new();
46
+ for (i = 0; i < sizeof(buf.prefix6); i++) {
47
+ rb_ary_push(ary, INT2FIX(buf.prefix6[i]));
48
+ }
49
+ rb_hash_aset(hash, rb_str_new2("prefix6"), ary);
50
+ rb_hash_aset(hash, rb_str_new2("scope6"), rb_uint2inum(buf.scope6));
51
+ ary = rb_ary_new();
52
+ for (i = 0; i < sizeof(buf.hwaddress); i++) {
53
+ rb_ary_push(ary, INT2FIX(buf.hwaddress[i]));
54
+ }
55
+ rb_hash_aset(hash, rb_str_new2("hwaddress"), ary);
56
+ #endif
57
+
58
+ return hash;
59
+ }
60
+
61
+
62
+ void Init_glibtop_netload()
63
+ {
64
+ rb_define_const(cLibGTop, "IF_FLAGS_UP", INT2FIX(GLIBTOP_IF_FLAGS_UP));
65
+ rb_define_const(cLibGTop, "IF_FLAGS_BROADCAS", INT2FIX(GLIBTOP_IF_FLAGS_BROADCAST));
66
+ rb_define_const(cLibGTop, "IF_FLAGS_DEBUG", INT2FIX(GLIBTOP_IF_FLAGS_DEBUG));
67
+ rb_define_const(cLibGTop, "IF_FLAGS_LOOPBACK", INT2FIX(GLIBTOP_IF_FLAGS_LOOPBACK));
68
+ rb_define_const(cLibGTop, "IF_FLAGS_POINTOPOINT", INT2FIX(GLIBTOP_IF_FLAGS_POINTOPOINT));
69
+ rb_define_const(cLibGTop, "IF_FLAGS_RUNNING", INT2FIX(GLIBTOP_IF_FLAGS_RUNNING));
70
+ rb_define_const(cLibGTop, "IF_FLAGS_NOARP", INT2FIX(GLIBTOP_IF_FLAGS_NOARP));
71
+ rb_define_const(cLibGTop, "IF_FLAGS_PROMISC", INT2FIX(GLIBTOP_IF_FLAGS_PROMISC));
72
+ rb_define_const(cLibGTop, "IF_FLAGS_ALLMULTI", INT2FIX(GLIBTOP_IF_FLAGS_ALLMULTI));
73
+ rb_define_const(cLibGTop, "IF_FLAGS_OACTIVE", INT2FIX(GLIBTOP_IF_FLAGS_OACTIVE));
74
+ rb_define_const(cLibGTop, "IF_FLAGS_SIMPLEX", INT2FIX(GLIBTOP_IF_FLAGS_SIMPLEX));
75
+ rb_define_const(cLibGTop, "IF_FLAGS_LINK0", INT2FIX(GLIBTOP_IF_FLAGS_LINK0));
76
+ rb_define_const(cLibGTop, "IF_FLAGS_LINK1", INT2FIX(GLIBTOP_IF_FLAGS_LINK1));
77
+ rb_define_const(cLibGTop, "IF_FLAGS_LINK2", INT2FIX(GLIBTOP_IF_FLAGS_LINK2));
78
+ rb_define_const(cLibGTop, "IF_FLAGS_ALTPHYS", INT2FIX(GLIBTOP_IF_FLAGS_ALTPHYS));
79
+ rb_define_const(cLibGTop, "IF_FLAGS_MULTICAST", INT2FIX(GLIBTOP_IF_FLAGS_MULTICAST));
80
+
81
+ rb_define_method(cLibGTop, "netload", rb_glibtop_netload, 1);
82
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/ppp.h>
11
+
12
+
13
+ static VALUE rb_glibtop_ppp(VALUE self, VALUE device)
14
+ {
15
+ glibtop_ppp buf;
16
+ VALUE hash;
17
+
18
+ Check_Type(device, T_FIXNUM);
19
+ glibtop_get_ppp(&buf, FIX2INT(device));
20
+
21
+ hash = rb_hash_new();
22
+
23
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
24
+ rb_hash_aset(hash, rb_str_new2("state"), rb_uint2inum(buf.state));
25
+ rb_hash_aset(hash, rb_str_new2("bytes_in"), rb_uint2inum(buf.bytes_in));
26
+ rb_hash_aset(hash, rb_str_new2("bytes_out"), rb_uint2inum(buf.bytes_out));
27
+
28
+ return hash;
29
+ }
30
+
31
+
32
+ void Init_glibtop_ppp()
33
+ {
34
+ rb_define_const(cLibGTop, "PPP_STATE_UNKNOWN", INT2FIX(GLIBTOP_PPP_STATE_UNKNOWN));
35
+ rb_define_const(cLibGTop, "PPP_STATE_HANGUP", INT2FIX(GLIBTOP_PPP_STATE_HANGUP));
36
+ rb_define_const(cLibGTop, "PPP_STATE_ONLINE", INT2FIX(GLIBTOP_PPP_STATE_ONLINE));
37
+
38
+ rb_define_method(cLibGTop, "ppp", rb_glibtop_ppp, 1);
39
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/procargs.h>
11
+
12
+
13
+ static VALUE rb_glibtop_proc_args(VALUE self, VALUE pid)
14
+ {
15
+ glibtop_proc_args buf;
16
+ VALUE hash, str;
17
+ char *args;
18
+ int size;
19
+
20
+ args = glibtop_get_proc_args(&buf, NUM2LONG(pid), 0);
21
+
22
+ hash = rb_hash_new();
23
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
24
+ rb_hash_aset(hash, rb_str_new2("size"), rb_uint2inum(buf.size));
25
+
26
+ size = buf.size;
27
+ str = rb_str_new(args, size);
28
+ rb_hash_aset(hash, rb_str_new2("args"), str);
29
+
30
+ g_free(args);
31
+
32
+ return hash;
33
+ }
34
+
35
+
36
+ void Init_glibtop_proc_args()
37
+ {
38
+ rb_define_method(cLibGTop, "proc_args", rb_glibtop_proc_args, 1);
39
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/prockernel.h>
11
+
12
+
13
+ static VALUE rb_glibtop_proc_kernel(VALUE self, VALUE pid)
14
+ {
15
+ glibtop_proc_kernel buf;
16
+ VALUE hash;
17
+
18
+ glibtop_get_proc_kernel(&buf, NUM2LONG(pid));
19
+
20
+ hash = rb_hash_new();
21
+
22
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
23
+ rb_hash_aset(hash, rb_str_new2("k_flags"), rb_uint2inum(buf.k_flags));
24
+ rb_hash_aset(hash, rb_str_new2("min_flt"), rb_uint2inum(buf.min_flt));
25
+ rb_hash_aset(hash, rb_str_new2("maj_flt"), rb_uint2inum(buf.maj_flt));
26
+ rb_hash_aset(hash, rb_str_new2("cmin_flt"), rb_uint2inum(buf.cmin_flt));
27
+ rb_hash_aset(hash, rb_str_new2("cmaj_flt"), rb_uint2inum(buf.cmaj_flt));
28
+ rb_hash_aset(hash, rb_str_new2("kstk_esp"), rb_uint2inum(buf.kstk_esp));
29
+ rb_hash_aset(hash, rb_str_new2("kstk_eip"), rb_uint2inum(buf.kstk_eip));
30
+ rb_hash_aset(hash, rb_str_new2("nwchan"), rb_uint2inum(buf.nwchan));
31
+ rb_hash_aset(hash, rb_str_new2("wchan"), rb_str_new2(buf.wchan));
32
+
33
+ return hash;
34
+ }
35
+
36
+
37
+ void Init_glibtop_proc_kernel()
38
+ {
39
+ /* mumumu, these constants were not found under the include/libgtop-2.0/ */
40
+ rb_define_const(cLibGTop, "KFLAGS_STARTING", INT2FIX(1));
41
+ rb_define_const(cLibGTop, "KFLAGS_EXITING", INT2FIX(2));
42
+ rb_define_const(cLibGTop, "KFLAGS_PTRACED", INT2FIX(4));
43
+ rb_define_const(cLibGTop, "KFLAGS_TRACESYS", INT2FIX(8));
44
+ rb_define_const(cLibGTop, "KFLAGS_FORKNOEXEC", INT2FIX(16));
45
+ rb_define_const(cLibGTop, "KFLAGS_SUPERPRIV", INT2FIX(32));
46
+ rb_define_const(cLibGTop, "KFLAGS_DUMPEDCORE", INT2FIX(64));
47
+ rb_define_const(cLibGTop, "KFLAGS_SIGNALED", INT2FIX(128));
48
+
49
+ rb_define_method(cLibGTop, "proc_kernel", rb_glibtop_proc_kernel, 1);
50
+ }
@@ -0,0 +1,69 @@
1
+ /*
2
+ * GLibTop is a wrapper library of a libgtop-2.x
3
+ *
4
+ * @author DATE Ken <itacchi@gmail.com>
5
+ * @see http://rubyforge.org/projects/ruby-libgtop2/
6
+ */
7
+
8
+ #include <ruby.h>
9
+ #include <rb_glibtop.h>
10
+ #include <glibtop/procmap.h>
11
+
12
+
13
+ static VALUE rb_glibtop_proc_map(VALUE self, VALUE pid)
14
+ {
15
+ glibtop_proc_map buf;
16
+ glibtop_map_entry* map_entries_buf;
17
+ VALUE hash, map_entries, map_entry;
18
+ int i;
19
+
20
+ map_entries_buf = glibtop_get_proc_map(&buf, NUM2LONG(pid));
21
+
22
+ hash = rb_hash_new();
23
+
24
+ rb_hash_aset(hash, rb_str_new2("flags"), rb_uint2inum(buf.flags));
25
+ rb_hash_aset(hash, rb_str_new2("number"), rb_uint2inum(buf.number));
26
+ rb_hash_aset(hash, rb_str_new2("total"), rb_uint2inum(buf.total));
27
+ rb_hash_aset(hash, rb_str_new2("size"), rb_uint2inum(buf.size));
28
+
29
+ map_entries = rb_ary_new2(buf.number);
30
+ for (i = 0; i < buf.number; i++){
31
+ map_entry = rb_hash_new();
32
+
33
+ rb_hash_aset(map_entry, rb_str_new2("flags"), rb_uint2inum(map_entries_buf[i].flags));
34
+ rb_hash_aset(map_entry, rb_str_new2("start"), rb_uint2inum(map_entries_buf[i].start));
35
+ rb_hash_aset(map_entry, rb_str_new2("end"), rb_uint2inum(map_entries_buf[i].end));
36
+ rb_hash_aset(map_entry, rb_str_new2("offset"), rb_uint2inum(map_entries_buf[i].offset));
37
+ rb_hash_aset(map_entry, rb_str_new2("perm"), rb_uint2inum(map_entries_buf[i].perm));
38
+ rb_hash_aset(map_entry, rb_str_new2("inode"), rb_uint2inum(map_entries_buf[i].inode));
39
+ rb_hash_aset(map_entry, rb_str_new2("device"), rb_uint2inum(map_entries_buf[i].device));
40
+ rb_hash_aset(map_entry, rb_str_new2("filename"), rb_str_new2(map_entries_buf[i].filename));
41
+
42
+ rb_ary_push(map_entries, map_entry);
43
+ }
44
+ rb_hash_aset(hash, rb_str_new2("map_entries"), map_entries);
45
+
46
+ g_free(map_entries_buf);
47
+
48
+ return hash;
49
+ }
50
+
51
+
52
+ void Init_glibtop_proc_map()
53
+ {
54
+ rb_define_const(cLibGTop, "MAP_ENTRY_START", INT2FIX(GLIBTOP_MAP_ENTRY_START));
55
+ rb_define_const(cLibGTop, "MAP_ENTRY_END", INT2FIX(GLIBTOP_MAP_ENTRY_END));
56
+ rb_define_const(cLibGTop, "MAP_ENTRY_OFFSET", INT2FIX(GLIBTOP_MAP_ENTRY_OFFSET));
57
+ rb_define_const(cLibGTop, "MAP_ENTRY_PERM", INT2FIX(GLIBTOP_MAP_ENTRY_PERM));
58
+ rb_define_const(cLibGTop, "MAP_ENTRY_INODE", INT2FIX(GLIBTOP_MAP_ENTRY_INODE));
59
+ rb_define_const(cLibGTop, "MAP_ENTRY_DEVICE", INT2FIX(GLIBTOP_MAP_ENTRY_DEVICE));
60
+ rb_define_const(cLibGTop, "MAP_ENTRY_FILENAME", INT2FIX(GLIBTOP_MAP_ENTRY_FILENAME));
61
+
62
+ rb_define_const(cLibGTop, "MAP_PERM_READ", INT2FIX(GLIBTOP_MAP_PERM_READ));
63
+ rb_define_const(cLibGTop, "MAP_PERM_WRITE", INT2FIX(GLIBTOP_MAP_PERM_WRITE));
64
+ rb_define_const(cLibGTop, "MAP_PERM_EXECUTE", INT2FIX(GLIBTOP_MAP_PERM_EXECUTE));
65
+ rb_define_const(cLibGTop, "MAP_PERM_SHARED", INT2FIX(GLIBTOP_MAP_PERM_SHARED));
66
+ rb_define_const(cLibGTop, "MAP_PERM_PRIVATE", INT2FIX(GLIBTOP_MAP_PERM_PRIVATE));
67
+
68
+ rb_define_method(cLibGTop, "proc_map", rb_glibtop_proc_map, 1);
69
+ }