ruby-libgtop2 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +30 -0
- data/History.txt +6 -0
- data/INSTALL.txt +19 -0
- data/Manifest.txt +53 -0
- data/README.txt +21 -0
- data/Rakefile +59 -0
- data/TODO +4 -0
- data/TUTORIAL.txt +28 -0
- data/examples/README +1 -0
- data/examples/first.rb +220 -0
- data/examples/mountlist.rb +30 -0
- data/examples/netload.rb +50 -0
- data/examples/procmap.rb +41 -0
- data/examples/second.rb +207 -0
- data/examples/smp.rb +76 -0
- data/examples/sysdeps.rb +86 -0
- data/ext/libgtop/MANIFEST +30 -0
- data/ext/libgtop/Makefile +149 -0
- data/ext/libgtop/extconf.rb +9 -0
- data/ext/libgtop/mkmf.log +27 -0
- data/ext/libgtop/rb_glibtop.c +61 -0
- data/ext/libgtop/rb_glibtop.h +15 -0
- data/ext/libgtop/rb_glibtop_cpu.c +69 -0
- data/ext/libgtop/rb_glibtop_fsusage.c +43 -0
- data/ext/libgtop/rb_glibtop_init.c +25 -0
- data/ext/libgtop/rb_glibtop_loadavg.c +42 -0
- data/ext/libgtop/rb_glibtop_mem.c +39 -0
- data/ext/libgtop/rb_glibtop_mountlist.c +53 -0
- data/ext/libgtop/rb_glibtop_msg_limits.c +37 -0
- data/ext/libgtop/rb_glibtop_netlist.c +36 -0
- data/ext/libgtop/rb_glibtop_netload.c +82 -0
- data/ext/libgtop/rb_glibtop_ppp.c +39 -0
- data/ext/libgtop/rb_glibtop_proc_args.c +39 -0
- data/ext/libgtop/rb_glibtop_proc_kernel.c +50 -0
- data/ext/libgtop/rb_glibtop_proc_map.c +69 -0
- data/ext/libgtop/rb_glibtop_proc_mem.c +37 -0
- data/ext/libgtop/rb_glibtop_proc_open_files.c +65 -0
- data/ext/libgtop/rb_glibtop_proc_segment.c +39 -0
- data/ext/libgtop/rb_glibtop_proc_signal.c +48 -0
- data/ext/libgtop/rb_glibtop_proc_state.c +46 -0
- data/ext/libgtop/rb_glibtop_proc_time.c +54 -0
- data/ext/libgtop/rb_glibtop_proc_uid.c +58 -0
- data/ext/libgtop/rb_glibtop_proclist.c +56 -0
- data/ext/libgtop/rb_glibtop_sem_limits.c +40 -0
- data/ext/libgtop/rb_glibtop_shm_limits.c +35 -0
- data/ext/libgtop/rb_glibtop_swap.c +36 -0
- data/ext/libgtop/rb_glibtop_sysdeps.c +78 -0
- data/ext/libgtop/rb_glibtop_uptime.c +36 -0
- data/lib/libgtop.rb +3 -0
- data/lib/libgtop/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/ruby-libgtop2_test.rb +11 -0
- data/test/test_helper.rb +4 -0
- metadata +98 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'libgtop'
|
5
|
+
|
6
|
+
gtop = LibGTop.new
|
7
|
+
|
8
|
+
gtop.init
|
9
|
+
|
10
|
+
mount_list = gtop.mountlist(1)
|
11
|
+
|
12
|
+
exit if mount_list["mount_entries"].empty?
|
13
|
+
|
14
|
+
mount_list["mount_entries"].each do |mount|
|
15
|
+
printf "Mount_Entry: %-30s %-10s %-20s\n",
|
16
|
+
mount["mountdir"], mount["type"], mount["devname"]
|
17
|
+
end
|
18
|
+
|
19
|
+
printf "\n\n%-16s %9s %9s %9s %9s %9s %9s\n",
|
20
|
+
"Mount", "Blocks", "Free", "Avail", "Files", "Free", "BlockSz"
|
21
|
+
|
22
|
+
mount_list["mount_entries"].each do |mount|
|
23
|
+
fsusage = gtop.fsusage(mount["mountdir"])
|
24
|
+
|
25
|
+
printf "%-16s %9u %9u %9u %9u %9u %9d\n",
|
26
|
+
mount["mountdir"],
|
27
|
+
fsusage["blocks"], fsusage["bfree"],
|
28
|
+
fsusage["bavail"], fsusage["files"],
|
29
|
+
fsusage["ffree"], fsusage["block_size"]
|
30
|
+
end
|
data/examples/netload.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'socket'
|
5
|
+
require 'libgtop'
|
6
|
+
|
7
|
+
gtop = LibGTop.new
|
8
|
+
|
9
|
+
unless iface = ARGV.shift
|
10
|
+
puts "Usage: #{$0} interface"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
gtop.init
|
15
|
+
|
16
|
+
netload = gtop.netload(iface)
|
17
|
+
|
18
|
+
address_string = TCPSocket.gethostbyname(netload["address"]).last.split('.').reverse.join('.')
|
19
|
+
subnet_string = TCPSocket.gethostbyname(netload["subnet"]).last.split('.').reverse.join('.')
|
20
|
+
|
21
|
+
printf "Network Load (0x%08x):\n\n" +
|
22
|
+
"\tInterface Flags:\t0x%08x\n" +
|
23
|
+
"\tAddress:\t\t0x%08x - %s\n" +
|
24
|
+
"\tSubnet:\t\t\t0x%08x - %s\n\n" +
|
25
|
+
"\tMTU:\t\t\t%d\n" +
|
26
|
+
"\tCollisions:\t\t%d\n\n" +
|
27
|
+
"\tPackets In:\t\t%d\n" +
|
28
|
+
"\tPackets Out:\t\t%d\n" +
|
29
|
+
"\tPackets Total:\t\t%d\n\n" +
|
30
|
+
"\tBytes In:\t\t%d\n" +
|
31
|
+
"\tBytes Out:\t\t%d\n" +
|
32
|
+
"\tBytes Total:\t\t%d\n\n" +
|
33
|
+
"\tErrors In:\t\t%d\n" +
|
34
|
+
"\tErrors Out:\t\t%d\n" +
|
35
|
+
"\tErrors Total:\t\t%d\n\n",
|
36
|
+
netload["flags"],
|
37
|
+
netload["if_flags"],
|
38
|
+
netload["address"], address_string,
|
39
|
+
netload["subnet"], subnet_string,
|
40
|
+
netload["mtu"],
|
41
|
+
netload["collisions"],
|
42
|
+
netload["packets_in"],
|
43
|
+
netload["packets_out"],
|
44
|
+
netload["packets_total"],
|
45
|
+
netload["bytes_in"],
|
46
|
+
netload["bytes_out"],
|
47
|
+
netload["bytes_total"],
|
48
|
+
netload["errors_in"],
|
49
|
+
netload["errors_out"],
|
50
|
+
netload["errors_total"]
|
data/examples/procmap.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'libgtop'
|
5
|
+
|
6
|
+
gtop = LibGTop.new
|
7
|
+
|
8
|
+
gtop.init
|
9
|
+
|
10
|
+
unless pid = ARGV.shift
|
11
|
+
puts "Usage: #{$0} pid"
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
STDERR.printf "Getting memory maps for pid %d.\n\n", pid
|
16
|
+
|
17
|
+
proc_map = gtop.proc_map(pid.to_i)
|
18
|
+
|
19
|
+
proc_map["map_entries"].each do |map|
|
20
|
+
filename = ''
|
21
|
+
if map["flags"] & (1 << LibGTop::MAP_ENTRY_FILENAME)
|
22
|
+
filename = map["filename"]
|
23
|
+
end
|
24
|
+
|
25
|
+
perm = ''
|
26
|
+
perm << ( map["perm"] & LibGTop::MAP_PERM_READ != 0 ? 'r' : '-' )
|
27
|
+
perm << ( map["perm"] & LibGTop::MAP_PERM_WRITE != 0 ? 'w' : '-' )
|
28
|
+
perm << ( map["perm"] & LibGTop::MAP_PERM_EXECUTE != 0 ? 'x' : '-' )
|
29
|
+
perm << ( map["perm"] & LibGTop::MAP_PERM_SHARED != 0 ? 's' : '-' )
|
30
|
+
perm << ( map["perm"] & LibGTop::MAP_PERM_PRIVATE != 0 ? 'p' : '-' )
|
31
|
+
|
32
|
+
device = map["device"]
|
33
|
+
device_minor = device & 255;
|
34
|
+
device_major = (device >> 8) & 255
|
35
|
+
|
36
|
+
format = "%08x-%08x %08x - %02x:%02x %08u - %4s - %s\n"
|
37
|
+
STDERR.printf format,
|
38
|
+
map["start"], map["end"], map["offset"],
|
39
|
+
device_major, device_minor,
|
40
|
+
map["inode"], perm, filename
|
41
|
+
end
|
data/examples/second.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'libgtop'
|
5
|
+
|
6
|
+
def output(gtop, pid)
|
7
|
+
print "\n"
|
8
|
+
|
9
|
+
proc_state = gtop.proc_state(pid)
|
10
|
+
printf "Proc_State PID %5d (0x%08x): " +
|
11
|
+
"'%s', %s, %u, %u\n", pid,
|
12
|
+
proc_state["flags"],
|
13
|
+
proc_state["cmd"], proc_state["state"],
|
14
|
+
proc_state["uid"], proc_state["gid"]
|
15
|
+
|
16
|
+
proc_uid = gtop.proc_uid(pid)
|
17
|
+
printf "Proc_Uid PID %5d (0x%08x): " +
|
18
|
+
"%d %d %d %d %d %d %d %d %d %d %d %d\n", pid,
|
19
|
+
proc_uid["flags"],
|
20
|
+
proc_uid["uid"], proc_uid["euid"],
|
21
|
+
proc_uid["gid"], proc_uid["egid"],
|
22
|
+
proc_uid["pid"], proc_uid["ppid"],
|
23
|
+
proc_uid["pgrp"], proc_uid["session"],
|
24
|
+
proc_uid["tty"], proc_uid["tpgid"],
|
25
|
+
proc_uid["priority"], proc_uid["nice"]
|
26
|
+
|
27
|
+
proc_mem = gtop.proc_mem(pid)
|
28
|
+
printf "Proc_Mem PID %5d (0x%08x): " +
|
29
|
+
"%u %u %u %u %u %u\n", pid,
|
30
|
+
proc_mem["flags"],
|
31
|
+
proc_mem["size"],
|
32
|
+
proc_mem["vsize"],
|
33
|
+
proc_mem["resident"],
|
34
|
+
proc_mem["share"],
|
35
|
+
proc_mem["rss"],
|
36
|
+
proc_mem["rss_rlim"]
|
37
|
+
|
38
|
+
proc_segment = gtop.proc_segment(pid)
|
39
|
+
printf "Proc_Segment PID %5d (0x%08x): " +
|
40
|
+
"%u %u %u %u %u %u %u %u\n", pid,
|
41
|
+
proc_segment["flags"],
|
42
|
+
proc_segment["text_rss"],
|
43
|
+
proc_segment["shlib_rss"],
|
44
|
+
proc_segment["rss"],
|
45
|
+
proc_segment["stack_rss"],
|
46
|
+
proc_segment["dirty_size"],
|
47
|
+
proc_segment["start_code"],
|
48
|
+
proc_segment["end_code"],
|
49
|
+
proc_segment["start_stack"]
|
50
|
+
|
51
|
+
proc_time = gtop.proc_time(pid)
|
52
|
+
printf "Proc_Time PID %5d (0x%08x): " +
|
53
|
+
"%u %u %u %u %u %u %u %u %u\n", pid,
|
54
|
+
proc_time["flags"],
|
55
|
+
proc_time["start_time"],
|
56
|
+
proc_time["rtime"],
|
57
|
+
proc_time["utime"],
|
58
|
+
proc_time["stime"],
|
59
|
+
proc_time["cutime"],
|
60
|
+
proc_time["cstime"],
|
61
|
+
proc_time["timeout"],
|
62
|
+
proc_time["it_real_value"],
|
63
|
+
proc_time["frequency"]
|
64
|
+
|
65
|
+
proc_signal = gtop.proc_signal(pid)
|
66
|
+
printf "Proc_Signal PID %5d (0x%08x): " +
|
67
|
+
"%s %s %s %s\n", pid,
|
68
|
+
proc_signal["flags"],
|
69
|
+
proc_signal["signal"].to_s,
|
70
|
+
proc_signal["blocked"].to_s,
|
71
|
+
proc_signal["sigignore"].to_s,
|
72
|
+
proc_signal["sigcatch"].to_s
|
73
|
+
|
74
|
+
proc_kernel = gtop.proc_kernel(pid)
|
75
|
+
printf "Proc_Kernel PID %5d (0x%08x): " +
|
76
|
+
"%u %u %u %u %u 0x%x 0x%x 0x%x (%s)\n", pid,
|
77
|
+
proc_kernel["flags"],
|
78
|
+
proc_kernel["k_flags"],
|
79
|
+
proc_kernel["min_flt"],
|
80
|
+
proc_kernel["maj_flt"],
|
81
|
+
proc_kernel["cmin_flt"],
|
82
|
+
proc_kernel["cmaj_flt"],
|
83
|
+
proc_kernel["kstk_esp"],
|
84
|
+
proc_kernel["kstk_eip"],
|
85
|
+
proc_kernel["nwchan"],
|
86
|
+
proc_kernel["wchan"]
|
87
|
+
|
88
|
+
print "\n"
|
89
|
+
|
90
|
+
proc_args = gtop.proc_args(pid)
|
91
|
+
args = proc_args["args"].split(/\000/, -1).join('|')
|
92
|
+
printf "Proc_Args PID %5d (0x%08x): %u - '%s'\n", pid,
|
93
|
+
proc_args["flags"],
|
94
|
+
proc_args["size"],
|
95
|
+
args
|
96
|
+
|
97
|
+
# SMP
|
98
|
+
ncpu = LibGTop.ncpu
|
99
|
+
|
100
|
+
proc_tome = gtop.proc_time(pid)
|
101
|
+
|
102
|
+
total = proc_time["utime"] + proc_time["stime"]
|
103
|
+
|
104
|
+
p_total = total > 0 ? total.to_f : 1.0
|
105
|
+
|
106
|
+
p_utime = proc_time["utime"] * 100.0 / p_total
|
107
|
+
p_stime = proc_time["stime"] * 100.0 / p_total
|
108
|
+
|
109
|
+
b_total = p_total / ncpu
|
110
|
+
b_utime = proc_time["utime"].to_f / ncpu
|
111
|
+
b_stime = proc_time["stime"].to_f / ncpu
|
112
|
+
|
113
|
+
s_total = s_utime = s_stime = 0
|
114
|
+
|
115
|
+
printf "Proc_Time PID %5d (0x%08x): %12u %12u %12u\n", pid,
|
116
|
+
proc_time["flags"], total,
|
117
|
+
proc_time["utime"],
|
118
|
+
proc_time["stime"]
|
119
|
+
|
120
|
+
xcpu = proc_time["xcpu"]
|
121
|
+
xcpu.each_with_index do |cpu, i|
|
122
|
+
this_total = cpu["utime"] + cpu["stime"]
|
123
|
+
printf "CPU %3d PID %5d (0x%08x): %12u %12u %12u\n", i,
|
124
|
+
pid, proc_time["flags"], this_total,
|
125
|
+
cpu["utime"],
|
126
|
+
cpu["stime"]
|
127
|
+
|
128
|
+
s_total += (this_total - b_total).abs
|
129
|
+
s_utime += (cpu["utime"] - b_utime).abs
|
130
|
+
s_stime += (cpu["stime"] - b_stime).abs
|
131
|
+
end
|
132
|
+
|
133
|
+
print "\n"
|
134
|
+
|
135
|
+
printf "Proc_Time PID %5d (0x%08x): %12.3f %12.3f %12.3f\n", pid,
|
136
|
+
proc_time["flags"], 100.0, p_utime, p_stime
|
137
|
+
|
138
|
+
xcpu.each_with_index do |cpu, i|
|
139
|
+
this_total = cpu["utime"] + cpu["stime"]
|
140
|
+
this_p_total = this_total * 100.0 / p_total
|
141
|
+
this_p_utime = cpu["utime"] * 100.0 / p_total
|
142
|
+
this_p_stime = cpu["stime"] * 100.0 / p_total
|
143
|
+
|
144
|
+
printf "CPU %3d PID %5d (0x%08x): %12.3f %12.3f %12.3f\n", i,
|
145
|
+
pid, proc_time["flags"],
|
146
|
+
this_p_total, this_p_utime, this_p_stime
|
147
|
+
end
|
148
|
+
|
149
|
+
print "\n"
|
150
|
+
|
151
|
+
my_utime = proc_time["utime"] > 0 ? proc_time["utime"] : 1.0
|
152
|
+
my_stime = proc_time["stime"] > 0 ? proc_time["stime"] : 1.0
|
153
|
+
|
154
|
+
printf "SPIN: %31s %12.3f %12.3f %12.3f\n", "", s_total * 100.0 / p_total,
|
155
|
+
s_utime * 100.0 / my_utime, s_stime * 100.0 / my_stime
|
156
|
+
|
157
|
+
print "\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
gtop = LibGTop.new
|
162
|
+
|
163
|
+
gtop.init
|
164
|
+
|
165
|
+
sysdeps = gtop.sysdeps
|
166
|
+
|
167
|
+
printf "Sysdeps (0x%08x): %u, %u, %u, %u, %u, " +
|
168
|
+
"%u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u\n",
|
169
|
+
sysdeps["flags"],
|
170
|
+
sysdeps["cpu"],
|
171
|
+
sysdeps["mem"],
|
172
|
+
sysdeps["swap"],
|
173
|
+
sysdeps["uptime"],
|
174
|
+
sysdeps["loadavg"],
|
175
|
+
sysdeps["shm_limits"],
|
176
|
+
sysdeps["msg_limits"],
|
177
|
+
sysdeps["sem_limits"],
|
178
|
+
sysdeps["proclist"],
|
179
|
+
sysdeps["proc_state"],
|
180
|
+
sysdeps["proc_uid"],
|
181
|
+
sysdeps["proc_mem"],
|
182
|
+
sysdeps["proc_time"],
|
183
|
+
sysdeps["proc_signal"],
|
184
|
+
sysdeps["proc_kernel"],
|
185
|
+
sysdeps["proc_segment"]
|
186
|
+
|
187
|
+
if pid = ARGV.shift
|
188
|
+
output(gtop, pid.to_i)
|
189
|
+
exit
|
190
|
+
end
|
191
|
+
|
192
|
+
print "\n"
|
193
|
+
|
194
|
+
proclist = gtop.proclist(0, 0)
|
195
|
+
pids = proclist["pids"]
|
196
|
+
|
197
|
+
printf "Proclist (0x%08x): %u, %u, %u\n",
|
198
|
+
proclist["flags"],
|
199
|
+
proclist["number"],
|
200
|
+
proclist["size"],
|
201
|
+
proclist["total"]
|
202
|
+
|
203
|
+
exit if pids.empty?
|
204
|
+
|
205
|
+
pids.each do |pid|
|
206
|
+
output(gtop, pid)
|
207
|
+
end
|
data/examples/smp.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'libgtop'
|
5
|
+
|
6
|
+
gtop = LibGTop.new
|
7
|
+
|
8
|
+
gtop.init
|
9
|
+
|
10
|
+
cpu = gtop.cpu
|
11
|
+
|
12
|
+
ncpu = LibGTop.ncpu
|
13
|
+
|
14
|
+
frequency = cpu["frequency"]
|
15
|
+
|
16
|
+
total = cpu["total"] > 0 ? cpu["total"].to_f : 1.0
|
17
|
+
user = cpu["user"] > 0 ? cpu["user"].to_f : 1.0
|
18
|
+
nice = cpu["nice"] > 0 ? cpu["nice"].to_f : 1.0
|
19
|
+
sys = cpu["sys"] > 0 ? cpu["sys"].to_f : 1.0
|
20
|
+
idle = cpu["idle"] > 0 ? cpu["idle"].to_f : 1.0
|
21
|
+
|
22
|
+
s_total = s_user = s_nice = s_sys = s_idle = 0
|
23
|
+
|
24
|
+
b_total = total / ncpu
|
25
|
+
b_user = user / ncpu
|
26
|
+
b_nice = nice / ncpu
|
27
|
+
b_sys = sys / ncpu
|
28
|
+
b_idle = idle / ncpu
|
29
|
+
|
30
|
+
separator = '-' * 91
|
31
|
+
buffer = sprintf "Ticks (%d per second):", frequency
|
32
|
+
|
33
|
+
printf "\n\n%-26s %12s %12s %12s %12s %12s\n%s\n", buffer,
|
34
|
+
"Total", "User", "Nice", "Sys", "Idle", separator
|
35
|
+
|
36
|
+
printf "CPU (0x%08x): %12.0f %12.0f %12.0f %12.0f %12.0f\n\n",
|
37
|
+
cpu["flags"], cpu["total"], cpu["user"],
|
38
|
+
cpu["nice"], cpu["sys"], cpu["idle"]
|
39
|
+
|
40
|
+
cpu["xcpu"].each_with_index do |xcpu, i|
|
41
|
+
printf "CPU %3d (0x%08x): %12u %12u %12u %12u %12u\n", i,
|
42
|
+
cpu["flags"], xcpu["total"], xcpu["user"],
|
43
|
+
xcpu["nice"], xcpu["sys"], xcpu["idle"]
|
44
|
+
|
45
|
+
s_total += (xcpu["total"].to_f - b_total).abs
|
46
|
+
s_user += (xcpu["user"].to_f - b_user).abs
|
47
|
+
s_nice += (xcpu["nice"].to_f - b_nice).abs
|
48
|
+
s_sys += (xcpu["sys"].to_f - b_sys).abs
|
49
|
+
s_idle += (xcpu["idle"].to_f - b_idle).abs
|
50
|
+
end
|
51
|
+
|
52
|
+
printf "%s\n\n\n", separator
|
53
|
+
|
54
|
+
printf "%-26s %12s %12s %12s %12s %12s\n%s\n", "Percent:",
|
55
|
+
"Total (%)", "User (%)", "Nice (%)", "Sys (%)",
|
56
|
+
"Idle (%)", separator
|
57
|
+
|
58
|
+
printf "CPU (0x%08x): %12.3f %12.3f %12.3f %12.3f %12.3f\n\n",
|
59
|
+
cpu["flags"], total * 100.0 / total,
|
60
|
+
user * 100.0 / total, nice * 100.0 / total,
|
61
|
+
sys * 100.0 / total, idle * 100.0 / total
|
62
|
+
|
63
|
+
cpu["xcpu"].each_with_index do |xcpu, i|
|
64
|
+
p_total = xcpu["total"] * 100.0 / total
|
65
|
+
p_user = xcpu["user"] * 100.0 / user
|
66
|
+
p_nice = xcpu["nice"] * 100.0 / nice
|
67
|
+
p_sys = xcpu["sys"] * 100.0 / sys
|
68
|
+
p_idle = xcpu["idle"] * 100.0 / idle
|
69
|
+
|
70
|
+
printf "CPU %3d (0x%08x): %12.3f %12.3f %12.3f %12.3f %12.3f\n", i,
|
71
|
+
cpu["flags"], p_total, p_user, p_nice, p_sys, p_idle
|
72
|
+
end
|
73
|
+
|
74
|
+
printf "%s\n%-26s %12.3f %12.3f %12.3f %12.3f %12.3f\n\n", separator,
|
75
|
+
"Spin:", s_total * 100.0 / total, s_user * 100.0 / user,
|
76
|
+
s_nice * 100.0 / nice, s_sys * 100.0 / sys, s_idle * 100.0 / idle
|
data/examples/sysdeps.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift('../ext/')
|
4
|
+
require 'libgtop'
|
5
|
+
|
6
|
+
def feature_check(sysdeps, f)
|
7
|
+
const = eval "LibGTop::SYSDEPS_#{f}"
|
8
|
+
sysdeps['feature'] & (1 << const) != 0 ? 1 : 0
|
9
|
+
end
|
10
|
+
|
11
|
+
gtop = LibGTop.new
|
12
|
+
|
13
|
+
gtop.init
|
14
|
+
|
15
|
+
sysdeps = gtop.sysdeps
|
16
|
+
|
17
|
+
printf "Sysdeps (0x%08x):\n\n" +
|
18
|
+
"\tfeature:\t\t0x%08x\n\n" +
|
19
|
+
"\tcpu:\t\t%d\t0x%08x\n" +
|
20
|
+
"\tmem:\t\t%d\t0x%08x\n" +
|
21
|
+
"\tswap:\t\t%d\t0x%08x\n\n" +
|
22
|
+
"\tuptime:\t\t%d\t0x%08x\n" +
|
23
|
+
"\tloadavg:\t%d\t0x%08x\n\n" +
|
24
|
+
"\tshm_limits:\t%d\t0x%08x\n" +
|
25
|
+
"\tmsg_limits:\t%d\t0x%08x\n" +
|
26
|
+
"\tsem_limits:\t%d\t0x%08x\n\n" +
|
27
|
+
"\tproclist:\t%d\t0x%08x\n\n" +
|
28
|
+
"\tproc_state:\t%d\t0x%08x\n" +
|
29
|
+
"\tproc_uid:\t%d\t0x%08x\n" +
|
30
|
+
"\tproc_mem:\t%d\t0x%08x\n" +
|
31
|
+
"\tproc_time:\t%d\t0x%08x\n" +
|
32
|
+
"\tproc_signal:\t%d\t0x%08x\n" +
|
33
|
+
"\tproc_kernel:\t%d\t0x%08x\n" +
|
34
|
+
"\tproc_segment:\t%d\t0x%08x\n\n" +
|
35
|
+
"\tproc_args:\t%d\t0x%08x\n" +
|
36
|
+
"\tproc_map:\t%d\t0x%08x\n\n" +
|
37
|
+
"\tmountlist:\t%d\t0x%08x\n" +
|
38
|
+
"\tfsusage:\t%d\t0x%08x\n\n" +
|
39
|
+
"\tnetload:\t%d\t0x%08x\n" +
|
40
|
+
"\tppp:\t\t%d\t0x%08x\n\n",
|
41
|
+
sysdeps["flags"],
|
42
|
+
sysdeps["feature"],
|
43
|
+
feature_check(sysdeps, "CPU"),
|
44
|
+
sysdeps["cpu"],
|
45
|
+
feature_check(sysdeps, "MEM"),
|
46
|
+
sysdeps["mem"],
|
47
|
+
feature_check(sysdeps, "SWAP"),
|
48
|
+
sysdeps["swap"],
|
49
|
+
feature_check(sysdeps, "UPTIME"),
|
50
|
+
sysdeps["uptime"],
|
51
|
+
feature_check(sysdeps, "LOADAVG"),
|
52
|
+
sysdeps["loadavg"],
|
53
|
+
feature_check(sysdeps, "SHM_LIMITS"),
|
54
|
+
sysdeps["shm_limits"],
|
55
|
+
feature_check(sysdeps, "MSG_LIMITS"),
|
56
|
+
sysdeps["msg_limits"],
|
57
|
+
feature_check(sysdeps, "SEM_LIMITS"),
|
58
|
+
sysdeps["sem_limits"],
|
59
|
+
feature_check(sysdeps, "PROCLIST"),
|
60
|
+
sysdeps["proclist"],
|
61
|
+
feature_check(sysdeps, "PROC_STATE"),
|
62
|
+
sysdeps["proc_state"],
|
63
|
+
feature_check(sysdeps, "PROC_UID"),
|
64
|
+
sysdeps["proc_uid"],
|
65
|
+
feature_check(sysdeps, "PROC_MEM"),
|
66
|
+
sysdeps["proc_mem"],
|
67
|
+
feature_check(sysdeps, "PROC_TIME"),
|
68
|
+
sysdeps["proc_time"],
|
69
|
+
feature_check(sysdeps, "PROC_SIGNAL"),
|
70
|
+
sysdeps["proc_signal"],
|
71
|
+
feature_check(sysdeps, "PROC_KERNEL"),
|
72
|
+
sysdeps["proc_kernel"],
|
73
|
+
feature_check(sysdeps, "PROC_SEGMENT"),
|
74
|
+
sysdeps["proc_segment"],
|
75
|
+
feature_check(sysdeps, "PROC_ARGS"),
|
76
|
+
sysdeps["proc_args"],
|
77
|
+
feature_check(sysdeps, "PROC_MAP"),
|
78
|
+
sysdeps["proc_map"],
|
79
|
+
feature_check(sysdeps, "MOUNTLIST"),
|
80
|
+
sysdeps["mountlist"],
|
81
|
+
feature_check(sysdeps, "FSUSAGE"),
|
82
|
+
sysdeps["fsusage"],
|
83
|
+
feature_check(sysdeps, "NETLOAD"),
|
84
|
+
sysdeps["netload"],
|
85
|
+
feature_check(sysdeps, "PPP"),
|
86
|
+
sysdeps["ppp"]
|