ruby-libgtop2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/CHANGELOG.txt ADDED
@@ -0,0 +1,30 @@
1
+ 2007-04-12 DATE Ken <itacchi@gmail.com>
2
+
3
+ * check & merge new features (libgtop 2.0.0 - 2.14.8)
4
+ * implement rb_glibtop_proc_open.c
5
+ * implement rb_glibtop_netlist.c
6
+
7
+ 2007-03-13 DATE Ken <itacchi@gmail.com>
8
+
9
+ * Licence re-changed (GPL to Ruby's)
10
+
11
+ 2004-09-27 DATE Ken <itacchi@gmail.com>
12
+
13
+ * setup.rb: updated 3.3.0
14
+ * Licence changed (Ruby's to GPL)
15
+
16
+ 2004-09-25 DATE Ken <itacchi@gmail.com>
17
+
18
+ * rb_glibtop_time.c: added xcpu_flags
19
+
20
+ 2004-09-21 DATE Ken <itacchi@gmail.com>
21
+
22
+ * rb_glibtop_cpu.c: remove debug statement
23
+
24
+ 2004-09-20 DATE Ken <itacchi@gmail.com>
25
+
26
+ * first release
27
+
28
+ 2004-09-19 DATE Ken <itacchi@gmail.com>
29
+
30
+ * just started
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ 2007-04-12
2
+
3
+ * 0.1.0
4
+ * gem ready
5
+ * first version on rubyforge
6
+ * add LibGTop#proc_open_files and LibGTop#netlist
data/INSTALL.txt ADDED
@@ -0,0 +1,19 @@
1
+ Ruby/LibGTop2 installation
2
+
3
+ Requirements:
4
+ - Ruby-1.8.x
5
+ - libgtop-2.6 or later(*1)
6
+ - pkg-config (*2)
7
+
8
+ Installaion:
9
+ $ ruby setup.rb config
10
+ $ ruby setup.rb setup
11
+ # ruby setup.rb install
12
+
13
+ or
14
+
15
+ # gem install ruby-libgtop2
16
+
17
+ ---
18
+ *1 It possibly works with 2.0 (even 1.9?), but I tested only 2.6.
19
+ *2 extconf.rb use it.
data/Manifest.txt ADDED
@@ -0,0 +1,53 @@
1
+ CHANGELOG.txt
2
+ History.txt
3
+ INSTALL.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ TODO
8
+ TUTORIAL.txt
9
+ examples/README
10
+ examples/first.rb
11
+ examples/mountlist.rb
12
+ examples/netload.rb
13
+ examples/procmap.rb
14
+ examples/second.rb
15
+ examples/smp.rb
16
+ examples/sysdeps.rb
17
+ ext/libgtop/MANIFEST
18
+ ext/libgtop/Makefile
19
+ ext/libgtop/extconf.rb
20
+ ext/libgtop/mkmf.log
21
+ ext/libgtop/rb_glibtop.c
22
+ ext/libgtop/rb_glibtop.h
23
+ ext/libgtop/rb_glibtop_cpu.c
24
+ ext/libgtop/rb_glibtop_fsusage.c
25
+ ext/libgtop/rb_glibtop_init.c
26
+ ext/libgtop/rb_glibtop_loadavg.c
27
+ ext/libgtop/rb_glibtop_mem.c
28
+ ext/libgtop/rb_glibtop_mountlist.c
29
+ ext/libgtop/rb_glibtop_msg_limits.c
30
+ ext/libgtop/rb_glibtop_netlist.c
31
+ ext/libgtop/rb_glibtop_netload.c
32
+ ext/libgtop/rb_glibtop_ppp.c
33
+ ext/libgtop/rb_glibtop_proc_args.c
34
+ ext/libgtop/rb_glibtop_proc_kernel.c
35
+ ext/libgtop/rb_glibtop_proc_map.c
36
+ ext/libgtop/rb_glibtop_proc_mem.c
37
+ ext/libgtop/rb_glibtop_proc_open_files.c
38
+ ext/libgtop/rb_glibtop_proc_segment.c
39
+ ext/libgtop/rb_glibtop_proc_signal.c
40
+ ext/libgtop/rb_glibtop_proc_state.c
41
+ ext/libgtop/rb_glibtop_proc_time.c
42
+ ext/libgtop/rb_glibtop_proc_uid.c
43
+ ext/libgtop/rb_glibtop_proclist.c
44
+ ext/libgtop/rb_glibtop_sem_limits.c
45
+ ext/libgtop/rb_glibtop_shm_limits.c
46
+ ext/libgtop/rb_glibtop_swap.c
47
+ ext/libgtop/rb_glibtop_sysdeps.c
48
+ ext/libgtop/rb_glibtop_uptime.c
49
+ lib/libgtop.rb
50
+ lib/libgtop/version.rb
51
+ setup.rb
52
+ test/ruby-libgtop2_test.rb
53
+ test/test_helper.rb
data/README.txt ADDED
@@ -0,0 +1,21 @@
1
+ Ruby/LibGTop2 README
2
+
3
+ What is:
4
+ Ruby/LibGtop2 is a wrapper library of a GNOME libgtop version2.x for Ruby.
5
+
6
+ Requirements:
7
+ - ruby-1.8.x: http://www.ruby-lang.org/
8
+ - libgtop-2.x: http://ftp.gnome.org/pub/gnome/sources/libgtop/
9
+ - pkg-config: http://www.freedesktop.org/Software/pkgconfig
10
+
11
+ Installation:
12
+ see INSTALL.*
13
+
14
+ Documentations:
15
+ see libgtop's info...
16
+
17
+ License:
18
+ Ruby's
19
+
20
+ References:
21
+ - ruby_libgtop: http://raa.ruby-lang.org/project/ruby_libgtop/
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ include FileUtils
12
+ require File.join(File.dirname(__FILE__), 'lib', 'libgtop', 'version')
13
+
14
+ AUTHOR = "date" # can also be an array of Authors
15
+ EMAIL = "itacchi@gmail.com"
16
+ DESCRIPTION = "Ruby bindings for GNOME libgtop version2.x. "
17
+ GEM_NAME = "ruby-libgtop2" # what ppl will type to install your gem
18
+ RUBYFORGE_PROJECT = "ruby-libgtop2" # The unix name for your project
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+
21
+
22
+ NAME = "ruby-libgtop2"
23
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ VERS = ENV['VERSION'] || (LibGTop::VERSION::STRING + (REV ? ".#{REV}" : ""))
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
26
+ RDOC_OPTS = ['--quiet', '--title', "ruby-libgtop2 documentation",
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ class Hoe
33
+ def extra_deps
34
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
35
+ end
36
+ end
37
+
38
+ # Generate all the Rake tasks
39
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
40
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
+ p.author = AUTHOR
42
+ p.description = DESCRIPTION
43
+ p.email = EMAIL
44
+ p.summary = DESCRIPTION
45
+ p.url = HOMEPATH
46
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
+ p.test_globs = ["test/**/*_test.rb"]
48
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
49
+
50
+ # == Optional
51
+ #p.changes - A description of the release's latest changes.
52
+ #p.extra_deps - An array of rubygem dependencies.
53
+ #p.spec_extras - A hash of extra values to set in the gemspec.
54
+
55
+ p.rdoc_pattern = /^(lib|bin|ext)|txt$/
56
+ p.spec_extras = {
57
+ :extensions => ['ext/libgtop/extconf.rb']
58
+ }
59
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ * use Struct instead of Hash
2
+ * documents
3
+ * tests
4
+ * add examples
data/TUTORIAL.txt ADDED
@@ -0,0 +1,28 @@
1
+ Ruby/LibGTop2 tutorial
2
+
3
+ 1. install Ruby
4
+ You install Ruby the Object-Oriented Scripting Language.
5
+ Go http://www.ruby-lang.org/en/.
6
+
7
+ 2. install libgtop 2.x and pkg-config
8
+ * http://ftp.gnome.org/pub/gnome/sources/libgtop/
9
+ * http://pkgconfig.freedesktop.org/releases/
10
+
11
+ 2. install Ruby/LibGTop2 and other requirements
12
+ see INSTALL.*
13
+
14
+ 3. write code
15
+
16
+ # example code
17
+ # show mem info like as top(1)
18
+ require 'libgtop'
19
+ gtop = LibGTop.new
20
+ gtop.init
21
+ # get mem info
22
+ mem = gtop.mem
23
+ # all of results are Hash object
24
+ printf "Mem: %uk total, %uk used, %uk free, %uk buffers\n",
25
+ mem["total"] / 1024, mem["used"] / 1024,
26
+ mem["free"] / 1024, mem["buffer"] / 1024
27
+
28
+ See examples/ for more detail.
data/examples/README ADDED
@@ -0,0 +1 @@
1
+ port of libgtop's example directory
data/examples/first.rb ADDED
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift('../ext/')
4
+ require 'libgtop'
5
+
6
+ def format(i)
7
+ "%u" % i
8
+ end
9
+
10
+ def data2str(data, ary, delimiter = ", ")
11
+ str =
12
+ ary.collect do |i|
13
+ Array(data[i]).flatten.join(delimiter)
14
+ end.join(delimiter)
15
+ sprintf "(0x%08x): #{str}", data["flags"]
16
+ end
17
+
18
+ def print_result(label, data, columns)
19
+ result = data2str(data, columns)
20
+ print "#{label}" + " " * (13 - label.size) + "#{result}\n"
21
+ end
22
+
23
+ def print_result_with_pid(label, pid, data, columns)
24
+ result = data2str(data, columns, " ")
25
+ print "#{label}" + " " * (13 - label.size) + "PID #{pid} #{result}\n"
26
+ end
27
+
28
+ def print_result_with_ppid(label, ppid, data, columns)
29
+ result = data2str(data, columns, " ")
30
+ print "#{label}" + " " * (13 - label.size) + "PPID #{ppid} #{result}\n"
31
+ end
32
+
33
+ def print_result_with_init(label, data, columns)
34
+ result = data2str(data, columns, " ")
35
+ print "#{label}" + " " * (13 - label.size) + "INIT #{1} #{result}\n"
36
+ end
37
+
38
+
39
+ gtop = LibGTop.new
40
+
41
+ gtop.init
42
+
43
+ cpu = gtop.cpu
44
+ ary = ["total", "user", "nice", "sys", "idle", "frequency"]
45
+ print_result("CPU", cpu, ary)
46
+
47
+ mem = gtop.mem
48
+ ary = ["total", "used", "free", "shared", "buffer", "cached", "user", "locked"]
49
+ print_result("Memory", mem, ary)
50
+
51
+
52
+ swap = gtop.swap
53
+ ary = ["total", "used", "free", "pagein", "pageout"]
54
+ print_result("Swap", swap, ary)
55
+
56
+ uptime = gtop.uptime
57
+ ary = ["uptime", "idletime"]
58
+ print_result("Uptime", uptime, ary)
59
+
60
+ loadavg = gtop.loadavg
61
+ ary = ["loadavg", "nr_running", "nr_tasks", "last_pid"]
62
+ print_result("Loadavg", loadavg, ary)
63
+
64
+ shm_limits = gtop.shm_limits
65
+ ary = ["shmmax", "shmmin", "shmmni", "shmseg", "shmall"]
66
+ print_result("Shm Limits", shm_limits, ary)
67
+
68
+ msg_limits = gtop.msg_limits
69
+ ary = ["msgpool", "msgmap", "msgmax", "msgmnb", "msgmni", "msgssz", "msgtql"]
70
+ print_result("Msg Limits", msg_limits, ary)
71
+
72
+ sem_limits = gtop.sem_limits
73
+ ary = ["semmap", "semmni", "semmns", "semmnu", "semmsl", "semopm", "semume", "semusz", "semvmx", "semaem"]
74
+ print_result("Sem Limits", sem_limits, ary)
75
+
76
+ puts ""
77
+
78
+ ppp = gtop.ppp(0)
79
+ ary = ["state", "bytes_in", "bytes_out"]
80
+ print_result("PPP", ppp, ary)
81
+
82
+ puts ""
83
+
84
+ sysdeps = gtop.sysdeps
85
+ ary = ["cpu", "mem", "swap", "uptime", "loadavg", "shm_limits", "msg_limits",
86
+ "sem_limits", "proclist", "proc_state", "proc_uid", "proc_mem", "proc_time",
87
+ "proc_signal", "proc_kernel", "proc_segment", "proc_args", "proc_map",
88
+ "mountlist", "fsusage", "netload", "ppp"]
89
+ print_result("Sysdeps", sysdeps, ary)
90
+
91
+ puts ""
92
+
93
+ proclist = gtop.proclist(0, 0)
94
+ ary = ["number", "size", "total"]
95
+ print_result("Proclist", proclist, ary)
96
+ unless proclist["pids"].empty?
97
+ print "\nProcess: "
98
+ print proclist["pids"].join(", ")
99
+ puts ""
100
+ end
101
+
102
+ pid = Process.pid
103
+ ppid = Process.ppid
104
+
105
+ puts ""
106
+
107
+ proc_state = gtop.proc_state(pid)
108
+ ary = ["cmd", "state", "uid", "gid"]
109
+ print_result_with_pid("Proc_State", pid, proc_state, ary)
110
+
111
+ proc_uid = gtop.proc_uid(pid)
112
+ ary = ["uid", "euid", "gid", "egid", "pid", "ppid", "pgrp", "session",
113
+ "tty", "tpgid", "priority", "nice"]
114
+ print_result_with_pid("Proc_Uid", pid, proc_uid, ary)
115
+
116
+ proc_mem = gtop.proc_mem(pid)
117
+ ary = ["size", "vsize", "resident", "share", "rss", "rss_rlim"]
118
+ print_result_with_pid("Proc_Mem", pid, proc_mem, ary)
119
+
120
+ proc_segment = gtop.proc_segment(pid)
121
+ ary = ["text_rss", "shlib_rss", "data_rss", "stack_rss", "dirty_size",
122
+ "start_code", "end_code", "start_stack"]
123
+ print_result_with_pid("Prco_Segment", pid, proc_segment, ary)
124
+
125
+ proc_time = gtop.proc_time(pid)
126
+ ary = ["start_time", "rtime", "utime", "stime", "cutime", "cstime",
127
+ "timeout", "it_real_value", "frequency"]
128
+ print_result_with_pid("Proc_Time", pid, proc_time, ary)
129
+
130
+ proc_signal = gtop.proc_signal(pid)
131
+ ary = ["signal", "blocked", "sigignore", "sigcatch"]
132
+ print_result_with_pid("Proc_Signal", pid, proc_signal, ary)
133
+
134
+ proc_kernel = gtop.proc_kernel(pid)
135
+ ary = ["k_flags", "min_flt", "maj_flt", "cmin_flt", "cmaj_flt",
136
+ "kstk_esp", "kstk_eip", "nwchan", "wchan"]
137
+ print_result_with_pid("Proc_Kernel", pid, proc_kernel, ary)
138
+
139
+ proc_args = gtop.proc_args(pid)
140
+ ary = ["size", "args"]
141
+ proc_args["args"] = proc_args["args"].split(/\000/, -1).join('|')
142
+ print_result_with_ppid("Proc_Args", pid, proc_args, ary)
143
+
144
+ puts ""
145
+
146
+ proc_state = gtop.proc_state(ppid)
147
+ ary = ["cmd", "state", "uid", "gid"]
148
+ print_result_with_ppid("Proc_State", ppid, proc_state, ary)
149
+
150
+ proc_uid = gtop.proc_uid(ppid)
151
+ ary = ["uid", "euid", "gid", "egid", "pid", "ppid", "pgrp", "session",
152
+ "tty", "tpgid", "priority", "nice"]
153
+ print_result_with_ppid("Proc_Uid", ppid, proc_uid, ary)
154
+
155
+ proc_mem = gtop.proc_mem(ppid)
156
+ ary = ["size", "vsize", "resident", "share", "rss", "rss_rlim"]
157
+ print_result_with_ppid("Proc_Mem", ppid, proc_mem, ary)
158
+
159
+ proc_segment = gtop.proc_segment(ppid)
160
+ ary = ["text_rss", "shlib_rss", "data_rss", "stack_rss", "dirty_size",
161
+ "start_code", "end_code", "start_stack"]
162
+ print_result_with_ppid("Prco_Segment", ppid, proc_segment, ary)
163
+
164
+ proc_time = gtop.proc_time(ppid)
165
+ ary = ["start_time", "rtime", "utime", "stime", "cutime", "cstime",
166
+ "timeout", "it_real_value", "frequency"]
167
+ print_result_with_ppid("Proc_Time", ppid, proc_time, ary)
168
+
169
+ proc_signal = gtop.proc_signal(ppid)
170
+ ary = ["signal", "blocked", "sigignore", "sigcatch"]
171
+ print_result_with_ppid("Proc_Signal", ppid, proc_signal, ary)
172
+
173
+ proc_kernel = gtop.proc_kernel(ppid)
174
+ ary = ["k_flags", "min_flt", "maj_flt", "cmin_flt", "cmaj_flt",
175
+ "kstk_esp", "kstk_eip", "nwchan", "wchan"]
176
+ print_result_with_ppid("Proc_Kernel", ppid, proc_kernel, ary)
177
+
178
+ proc_args = gtop.proc_args(ppid)
179
+ ary = ["size", "args"]
180
+ proc_args["args"] = proc_args["args"].split(/\000/, -1).join('|')
181
+ print_result_with_ppid("Proc_Args", ppid, proc_args, ary)
182
+
183
+ puts ""
184
+
185
+ proc_state = gtop.proc_state(1)
186
+ ary = ["cmd", "state", "uid", "gid"]
187
+ print_result_with_init("Proc_State", proc_state, ary)
188
+
189
+ proc_uid = gtop.proc_uid(1)
190
+ ary = ["uid", "euid", "gid", "egid", "pid", "ppid", "pgrp", "session",
191
+ "tty", "tpgid", "priority", "nice"]
192
+ print_result_with_init("Proc_Uid", proc_uid, ary)
193
+
194
+ proc_mem = gtop.proc_mem(1)
195
+ ary = ["size", "vsize", "resident", "share", "rss", "rss_rlim"]
196
+ print_result_with_init("Proc_Mem", proc_mem, ary)
197
+
198
+ proc_segment = gtop.proc_segment(1)
199
+ ary = ["text_rss", "shlib_rss", "data_rss", "stack_rss", "dirty_size",
200
+ "start_code", "end_code", "start_stack"]
201
+ print_result_with_init("Prco_Segment", proc_segment, ary)
202
+
203
+ proc_time = gtop.proc_time(1)
204
+ ary = ["start_time", "rtime", "utime", "stime", "cutime", "cstime",
205
+ "timeout", "it_real_value", "frequency"]
206
+ print_result_with_init("Proc_Time", proc_time, ary)
207
+
208
+ proc_signal = gtop.proc_signal(1)
209
+ ary = ["signal", "blocked", "sigignore", "sigcatch"]
210
+ print_result_with_init("Proc_Signal", proc_signal, ary)
211
+
212
+ proc_kernel = gtop.proc_kernel(1)
213
+ ary = ["k_flags", "min_flt", "maj_flt", "cmin_flt", "cmaj_flt",
214
+ "kstk_esp", "kstk_eip", "nwchan", "wchan"]
215
+ print_result_with_init("Proc_Kernel", proc_kernel, ary)
216
+
217
+ proc_args = gtop.proc_args(1)
218
+ ary = ["size", "args"]
219
+ proc_args["args"] = proc_args["args"].split(/\000/, -1).join('|')
220
+ print_result_with_init("Proc_Args", proc_args, ary)