-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathait-get-sysinfo
executable file
·231 lines (195 loc) · 6.18 KB
/
ait-get-sysinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
import ethtool, os, procfs, re, schedutils, sys, subprocess as sp
def glibc_uses_priv_futex():
p = sp.Popen("strace -e trace=futex ls /", shell=True, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE, close_fds=True)
line = p.stderr.readline()
if line:
if re.match("^futex\(.+FUTEX_.+_PRIVATE,.+\)", line):
return True
if re.match("/bin/sh: strace: command not found", line):
raise SystemError, "strace failed, is it installed?"
return False
def get_tso_state():
state=""
for iface in ethtool.get_devices():
try:
state += "%s=%d," % (iface, ethtool.get_tso(iface))
except:
pass
state = state.strip(",")
return state
def get_coalesce_interface(interface, metric):
try:
coal = ethtool.get_coalesce(interface)
except IOError:
return "NA"
return coal[metric]
def get_coalesce(metric):
return ",".join("%s=%s" % \
(iface,
get_coalesce_interface(iface, metric)) \
for iface in ethtool.get_devices())
def get_ufo_state():
state=""
# UFO may not be present on this kernel and then we get an exception
try:
for iface in ethtool.get_devices():
state += "%s=%d," % (iface, ethtool.get_ufo(iface))
except:
pass
state = state.strip(",")
return state
def get_nic_kthread_affinities(irqs):
state=""
for iface in ethtool.get_devices():
irq = irqs.find_by_user(iface)
if not irq:
continue
# affinity comes from /proc/irq/N/smp_affinities, that
# needs root priviledges
try:
state += "%s=%s;" % (iface,
",".join(str(a) for a in procfs.hexbitmask(irqs[irq]["affinity"],
irqs.nr_cpus)))
except:
pass
state = state.strip(";")
return state
def get_nic_kthread_rtprios(irqs, ps):
state=""
for iface in ethtool.get_devices():
irq = irqs.find_by_user(iface)
if not irq:
continue
pids = ps.find_by_regex(re.compile("(irq/%s-%s|IRQ-%s)" % (irq, iface, irq)))
if not pids:
continue
state += "%s=%s;" % (iface, ps[pids[0]]["stat"]["rt_priority"])
state = state.strip(";")
return state
def get_clocksource():
try:
f = file("/sys/devices/system/clocksource/clocksource0/current_clocksource")
clocksource = f.readline().strip()
f.close()
return clocksource
except:
return "unknown"
def get_loadavg():
try:
f = file("/proc/loadavg")
loadavg = f.readline().strip()
f.close()
return loadavg
except:
return "unknown"
if __name__ == '__main__':
if len(sys.argv) > 1:
app_process_name = sys.argv[1]
else:
app_process_name = None
sysinfo = {}
pfs = procfs.pidstats()
kcmd = procfs.cmdline()
irqs = procfs.interrupts()
cpuinfo = procfs.cpuinfo()
uname = os.uname()
sysctl = procfs.sysctl()
# arch, vendor, cpu_model, nr_cpus
sysinfo["nodename"] = uname[1]
sysinfo["arch"] = uname[4]
sysinfo["kernel_release"] = uname[2]
sysinfo["vendor_id"] = cpuinfo["vendor_id"]
sysinfo["cpu_model"] = cpuinfo["model name"]
sysinfo["nr_cpus"] = cpuinfo.nr_cpus
sysinfo["tso"] = get_tso_state()
sysinfo["coalesce_rx_frames"] = get_coalesce("rx_max_coalesced_frames")
sysinfo["coalesce_tx_frames"] = get_coalesce("tx_max_coalesced_frames")
sysinfo["ufo"] = get_ufo_state()
sysinfo["glibc_priv_futex"] = glibc_uses_priv_futex()
sysinfo["softirq_net_tx_prio"] = pfs.get_per_cpu_rtprios("sirq-net-tx")
if not sysinfo["softirq_net_tx_prio"]:
sysinfo["softirq_net_tx_prio"] = pfs.get_per_cpu_rtprios("softirq-net-tx")
sysinfo["softirq_net_rx_prio"] = pfs.get_per_cpu_rtprios("sirq-net-rx")
if not sysinfo["softirq_net_rx_prio"]:
sysinfo["softirq_net_rx_prio"] = pfs.get_per_cpu_rtprios("softirq-net-rx")
sysinfo["irqbalance"] = False
if pfs.find_by_name("irqbalance"):
sysinfo["irqbalance"] = True
sysinfo["oprofile"] = False
if pfs.find_by_name("oprofiled"):
sysinfo["oprofile"] = True
sysinfo["systemtap"] = False
if pfs.find_by_name("staprun"):
sysinfo["systemtap"] = True
if kcmd.options.has_key("isolcpus"):
sysinfo["kcmd_isolcpus"] = kcmd.options["isolcpus"]
elif kcmd.options.has_key("default_affinity"):
sysinfo["kcmd_isolcpus"] = "da:%s" % kcmd.options["default_affinity"]
else:
sysinfo["kcmd_isolcpus"] = None
sysinfo["kcmd_maxcpus"] = None
if kcmd.options.has_key("maxcpus"):
sysinfo["kcmd_maxcpus"] = kcmd.options["maxcpus"]
sysinfo["nic_kthread_affinities"] = get_nic_kthread_affinities(irqs)
sysinfo["nic_kthread_rtprios"] = get_nic_kthread_rtprios(irqs, pfs)
sysinfo["vsyscall64"] = None
try:
f = file("/proc/sys/kernel/vsyscall64")
sysinfo["vsyscall64"] = int(f.readline())
f.close()
except:
pass
sysinfo["futex_performance_hack"] = None
try:
f = file("/proc/sys/kernel/futex_performance_hack")
sysinfo["futex_performance_hack"] = int(f.readline())
f.close()
except:
pass
sysinfo["sched_min_granularity_ns"] = None
try:
f = file("/proc/sys/kernel/sched_min_granularity_ns")
sysinfo["sched_min_granularity_ns"] = int(f.readline())
f.close()
except:
pass
sysinfo["kcmd_idle"] = None
if kcmd.options.has_key("idle"):
sysinfo["kcmd_idle"] = kcmd.options["idle"]
sysinfo["kcmd_nohz"] = None
if kcmd.options.has_key("nohz"):
sysinfo["kcmd_nohz"] = kcmd.options["nohz"]
sysinfo["lock_stat"] = os.access("/proc/lock_stat", os.F_OK)
sysinfo["clocksource"] = get_clocksource()
sysinfo["loadavg"] = get_loadavg()
if app_process_name:
app = pfs.find_by_name(app_process_name)
if app:
sysinfo["app_rtprio"] = pfs.get_rtprios(app_process_name)
sysinfo["app_affinity"] = ",".join("%x" % a for a in procfs.hexbitmask(schedutils.get_affinity(app[0]),
int(sysinfo["nr_cpus"])))
sysinfo["app_sched"] = schedutils.schedstr(schedutils.get_scheduler(app[0]))
# Default: libc statically linked
sysinfo["libc"] = None
# Discover which libc is being used by the application
smaps = procfs.smaps(app[0])
if smaps:
libc = smaps.find_by_name_fragment("/libc-")
if libc:
sysinfo["libc"] = libc[0].name
else:
sysinfo["app_rtprio"] = None
sysinfo["app_affinity"] = None
sysinfo["app_sched"] = None
for tcpknob in [ "tcp_congestion_control",
"tcp_dsack",
"tcp_sack",
"tcp_window_scaling" ]:
sysinfo[tcpknob] = sysctl["net.ipv4.%s" % tcpknob]
keys = sysinfo.keys()
keys.sort()
for key in keys:
print "%s: %s" % ( key, sysinfo[key] )