summaryrefslogtreecommitdiff
path: root/src/systemd-analyze
blob: 43023297ffbbc7512365dce6c41537da9023f1b6 (plain)
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
#!/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

data = acquire_time_data()

if len(sys.argv) <= 1 or sys.argv[1] == 'blame':

        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("%lums\t %s\n" % ((i[2] - i[1]) / 1000, i[0]))