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
|
#!/usr/bin/python
import dbus, sys
def acquire_time_data():
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.systemd1.Manager')
units = manager.ListUnits()
l = []
for i in units:
properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', i[6]), 'org.freedesktop.DBus.Properties')
ixt = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveExitTimestamp'))
aet = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveEnterTimestamp'))
axt = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveExitTimestamp'))
iet = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveEnterTimestamp'))
l.append((str(i[0]), ixt, aet, axt, iet))
return l
if len(sys.argv) <= 1 or sys.argv[1] == 'blame':
data = acquire_time_data()
s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
for i in s:
if i[1] <= 0 or i[2] <= 0:
continue
if i[2] <= i[1]:
continue
sys.stdout.write("%6lums %s\n" % ((i[2] - i[1]) / 1000, i[0]))
else:
sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[1])
|