[systemd-commits] 2 commits - Makefile.am src/analyze src/core src/journal src/shared src/systemd-analyze

Lennart Poettering lennart at kemper.freedesktop.org
Fri Apr 13 05:09:34 PDT 2012


 Makefile.am                         |    2 
 src/analyze/systemd-analyze         |  276 ++++++++++++++++++++++++++++++++++++
 src/core/manager.c                  |    2 
 src/journal/journal-file.c          |    2 
 src/journal/journald.c              |    2 
 src/shared/logs-show.c              |    2 
 src/systemd-analyze/systemd-analyze |  276 ------------------------------------
 7 files changed, 281 insertions(+), 281 deletions(-)

New commits:
commit 7ea07dcddafe573c699fc48171b57b912897e7e2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Apr 13 13:58:50 2012 +0200

    fix a couple of things found with the llvm static analyzer

diff --git a/src/core/manager.c b/src/core/manager.c
index 6be8e8f..2801500 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -3015,7 +3015,7 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) {
 
 void manager_check_finished(Manager *m) {
         char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
-        usec_t kernel_usec = 0, initrd_usec = 0, userspace_usec = 0, total_usec = 0;
+        usec_t kernel_usec, initrd_usec, userspace_usec, total_usec;
 
         assert(m);
 
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 973c51f..a60a896 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1977,7 +1977,7 @@ int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t m
                 size_t q;
                 struct stat st;
                 char *p;
-                unsigned long long seqnum, realtime;
+                unsigned long long seqnum = 0, realtime;
                 sd_id128_t seqnum_id;
                 bool have_seqnum;
 
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 2e2d30f..97d2ec0 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -1148,7 +1148,7 @@ static void process_native_message(
         char *identifier = NULL, *message = NULL;
 
         assert(s);
-        assert(buffer || n == 0);
+        assert(buffer || buffer_size == 0);
 
         p = buffer;
         remaining = buffer_size;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index fedb453..4c59ca3 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -554,7 +554,7 @@ int show_journal_by_unit(
                 bool follow) {
 
         char *m = NULL;
-        sd_journal *j;
+        sd_journal *j = NULL;
         int r;
         int fd;
         unsigned line = 0;

commit 64695e53a0f425b831ba90d467f0e7a668c1b33c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Apr 13 13:34:09 2012 +0200

    build-sys: drop systemd- prefix from analyze dir

diff --git a/Makefile.am b/Makefile.am
index 8a29c15..57a149e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -211,7 +211,7 @@ bin_PROGRAMS = \
 	systemd-detect-virt
 
 dist_bin_SCRIPTS = \
-	src/systemd-analyze/systemd-analyze
+	src/analyze/systemd-analyze
 
 rootlibexec_PROGRAMS = \
 	systemd \
diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
new file mode 100755
index 0000000..a49fbb7
--- /dev/null
+++ b/src/analyze/systemd-analyze
@@ -0,0 +1,276 @@
+#!/usr/bin/python
+
+import dbus, sys
+
+def acquire_time_data():
+
+        manager = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.systemd1.Manager')
+        units = manager.ListUnits()
+
+        l = []
+
+        for i in units:
+                if i[5] != "":
+                        continue
+
+                properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', i[6]), 'org.freedesktop.DBus.Properties')
+
+                ixt = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveExitTimestampMonotonic'))
+                aet = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveEnterTimestampMonotonic'))
+                axt = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveExitTimestampMonotonic'))
+                iet = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveEnterTimestampMonotonic'))
+
+                l.append((str(i[0]), ixt, aet, axt, iet))
+
+        return l
+
+def acquire_start_time():
+        properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.DBus.Properties')
+
+        initrd_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'InitRDTimestampMonotonic'))
+        startup_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'StartupTimestampMonotonic'))
+        finish_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'FinishTimestampMonotonic'))
+
+        if finish_time == 0:
+                sys.stderr.write("Bootup is not yet finished. Please try again later.\n")
+                sys.exit(1)
+
+        assert initrd_time <= startup_time
+        assert startup_time <= finish_time
+
+        return initrd_time, startup_time, finish_time
+
+def draw_box(context, j, k, l, m, r = 0, g = 0, b = 0):
+        context.save()
+        context.set_source_rgb(r, g, b)
+        context.rectangle(j, k, l, m)
+        context.fill()
+        context.restore()
+
+def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b = 0, vcenter = 0.5, hcenter = 0.5):
+        context.save()
+
+        context.set_source_rgb(r, g, b)
+        context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
+        context.set_font_size(size)
+
+        if vcenter or hcenter:
+                x_bearing, y_bearing, width, height = context.text_extents(text)[:4]
+
+                if hcenter:
+                        x = x - width*hcenter - x_bearing
+
+                if vcenter:
+                        y = y - height*vcenter - y_bearing
+
+        context.move_to(x, y)
+        context.show_text(text)
+
+        context.restore()
+
+def help():
+        sys.stdout.write("""systemd-analyze time
+systemd-analyze blame
+systemd-analyze plot
+
+Process systemd profiling information
+
+  -h --help         Show this help
+""")
+
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) <= 1 or sys.argv[1] == 'time':
+
+        initrd_time, start_time, finish_time = acquire_start_time()
+
+        if initrd_time > 0:
+                print "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
+                        initrd_time/1000, \
+                        (start_time - initrd_time)/1000, \
+                        (finish_time - start_time)/1000, \
+                        finish_time/1000)
+        else:
+                print "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
+                        start_time/1000, \
+                        (finish_time - start_time)/1000, \
+                        finish_time/1000)
+
+
+elif sys.argv[1] == 'blame':
+
+        data = acquire_time_data()
+        s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
+
+        for name, ixt, aet, axt, iet in s:
+
+                if ixt <= 0 or aet <= 0:
+                        continue
+
+                if aet <= ixt:
+                        continue
+
+                sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
+
+elif sys.argv[1] == 'plot':
+        import cairo, os
+
+        initrd_time, start_time, finish_time = acquire_start_time()
+        data = acquire_time_data()
+        s = sorted(data, key = lambda i: i[1])
+
+        # Account for kernel and initramfs bars if they exist
+        if initrd_time > 0:
+                count = 3
+        else:
+                count = 2
+
+        for name, ixt, aet, axt, iet in s:
+
+                if (ixt >= start_time and ixt <= finish_time) or \
+                                (aet >= start_time and aet <= finish_time) or \
+                                (axt >= start_time and axt <= finish_time):
+                        count += 1
+
+        border = 100
+        bar_height = 20
+        bar_space = bar_height * 0.1
+
+        # 1000px = 10s, 1px = 10ms
+        width = finish_time/10000 + border*2
+        height = count * (bar_height + bar_space) + border * 2
+
+        if width < 1000:
+                width = 1000
+
+        surface = cairo.SVGSurface(sys.stdout, width, height)
+        context = cairo.Context(surface)
+
+        draw_box(context, 0, 0, width, height, 1, 1, 1)
+
+        context.translate(border + 0.5, border + 0.5)
+
+        context.save()
+        context.set_line_width(1)
+        context.set_source_rgb(0.7, 0.7, 0.7)
+
+        for x in range(0, finish_time/10000 + 100, 100):
+                context.move_to(x, 0)
+                context.line_to(x, height-border*2)
+
+        context.move_to(0, 0)
+        context.line_to(width-border*2, 0)
+
+        context.move_to(0, height-border*2)
+        context.line_to(width-border*2, height-border*2)
+
+        context.stroke()
+        context.restore()
+
+        osrel = "Linux"
+        if os.path.exists("/etc/os-release"):
+                for line in open("/etc/os-release"):
+                        if line.startswith('PRETTY_NAME='):
+                                osrel = line[12:]
+                                osrel = osrel.strip('\"\n')
+                                break
+
+        banner = "{} {} ({} {}) {}".format(osrel, *(os.uname()[1:5]))
+        draw_text(context, 0, -15, banner, hcenter = 0, vcenter = 1)
+
+        for x in range(0, finish_time/10000 + 100, 100):
+                draw_text(context, x, -5, "%lus" % (x/100), vcenter = 0, hcenter = 0)
+
+        y = 0
+
+        # draw boxes for kernel and initramfs boot time
+        if initrd_time > 0:
+                draw_box(context, 0, y, initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
+                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
+                y += bar_height + bar_space
+
+                draw_box(context, initrd_time/10000, y, start_time/10000-initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
+                draw_text(context, initrd_time/10000 + 10, y + bar_height/2, "initramfs", hcenter = 0)
+                y += bar_height + bar_space
+
+        else:
+                draw_box(context, 0, y, start_time/10000, bar_height, 0.6, 0.6, 0.6)
+                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
+                y += bar_height + bar_space
+
+        draw_box(context, start_time/10000, y, finish_time/10000-start_time/10000, bar_height, 0.7, 0.7, 0.7)
+        draw_text(context, start_time/10000 + 10, y + bar_height/2, "userspace", hcenter = 0)
+        y += bar_height + bar_space
+
+        for name, ixt, aet, axt, iet in s:
+
+                drawn = False
+                left = -1
+
+                if ixt >= start_time and ixt <= finish_time:
+
+                        # Activating
+                        a = ixt
+                        b = min(filter(lambda x: x >= ixt, (aet, axt, iet, finish_time))) - ixt
+
+                        draw_box(context, a/10000, y, b/10000, bar_height, 1, 0, 0)
+                        drawn = True
+
+                        if left < 0:
+                                left = a
+
+                if aet >= start_time and aet <= finish_time:
+
+                        # Active
+                        a = aet
+                        b = min(filter(lambda x: x >= aet, (axt, iet, finish_time))) - aet
+
+                        draw_box(context, a/10000, y, b/10000, bar_height, .8, .6, .6)
+                        drawn = True
+
+                        if left < 0:
+                                left = a
+
+                if axt >= start_time and axt <= finish_time:
+
+                        # Deactivating
+                        a = axt
+                        b = min(filter(lambda x: x >= axt, (iet, finish_time))) - axt
+
+                        draw_box(context, a/10000, y, b/10000, bar_height, .6, .4, .4)
+                        drawn = True
+
+                        if left < 0:
+                                left = a
+
+                if drawn:
+                        x = left/10000
+
+                        if x < width/2-border:
+                                draw_text(context, x + 10, y + bar_height/2, name, hcenter = 0)
+                        else:
+                                draw_text(context, x - 10, y + bar_height/2, name, hcenter = 1)
+
+                        y += bar_height + bar_space
+
+        draw_text(context, 0, height-border*2, "Legend: Red = Activating; Pink = Active; Dark Pink = Deactivating", hcenter = 0, vcenter = -1)
+
+        if initrd_time > 0:
+                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
+                        initrd_time/1000, \
+                        (start_time - initrd_time)/1000, \
+                        (finish_time - start_time)/1000, \
+                        finish_time/1000), hcenter = 0, vcenter = -1)
+        else:
+                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
+                        start_time/1000, \
+                        (finish_time - start_time)/1000, \
+                        finish_time/1000), hcenter = 0, vcenter = -1)
+
+        surface.finish()
+elif sys.argv[1] in ("help", "--help", "-h"):
+        help()
+else:
+        sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[1])
+        sys.exit(1)
diff --git a/src/systemd-analyze/systemd-analyze b/src/systemd-analyze/systemd-analyze
deleted file mode 100755
index a49fbb7..0000000
--- a/src/systemd-analyze/systemd-analyze
+++ /dev/null
@@ -1,276 +0,0 @@
-#!/usr/bin/python
-
-import dbus, sys
-
-def acquire_time_data():
-
-        manager = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.systemd1.Manager')
-        units = manager.ListUnits()
-
-        l = []
-
-        for i in units:
-                if i[5] != "":
-                        continue
-
-                properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', i[6]), 'org.freedesktop.DBus.Properties')
-
-                ixt = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveExitTimestampMonotonic'))
-                aet = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveEnterTimestampMonotonic'))
-                axt = int(properties.Get('org.freedesktop.systemd1.Unit', 'ActiveExitTimestampMonotonic'))
-                iet = int(properties.Get('org.freedesktop.systemd1.Unit', 'InactiveEnterTimestampMonotonic'))
-
-                l.append((str(i[0]), ixt, aet, axt, iet))
-
-        return l
-
-def acquire_start_time():
-        properties = dbus.Interface(bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1'), 'org.freedesktop.DBus.Properties')
-
-        initrd_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'InitRDTimestampMonotonic'))
-        startup_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'StartupTimestampMonotonic'))
-        finish_time = int(properties.Get('org.freedesktop.systemd1.Manager', 'FinishTimestampMonotonic'))
-
-        if finish_time == 0:
-                sys.stderr.write("Bootup is not yet finished. Please try again later.\n")
-                sys.exit(1)
-
-        assert initrd_time <= startup_time
-        assert startup_time <= finish_time
-
-        return initrd_time, startup_time, finish_time
-
-def draw_box(context, j, k, l, m, r = 0, g = 0, b = 0):
-        context.save()
-        context.set_source_rgb(r, g, b)
-        context.rectangle(j, k, l, m)
-        context.fill()
-        context.restore()
-
-def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b = 0, vcenter = 0.5, hcenter = 0.5):
-        context.save()
-
-        context.set_source_rgb(r, g, b)
-        context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-        context.set_font_size(size)
-
-        if vcenter or hcenter:
-                x_bearing, y_bearing, width, height = context.text_extents(text)[:4]
-
-                if hcenter:
-                        x = x - width*hcenter - x_bearing
-
-                if vcenter:
-                        y = y - height*vcenter - y_bearing
-
-        context.move_to(x, y)
-        context.show_text(text)
-
-        context.restore()
-
-def help():
-        sys.stdout.write("""systemd-analyze time
-systemd-analyze blame
-systemd-analyze plot
-
-Process systemd profiling information
-
-  -h --help         Show this help
-""")
-
-
-bus = dbus.SystemBus()
-
-if len(sys.argv) <= 1 or sys.argv[1] == 'time':
-
-        initrd_time, start_time, finish_time = acquire_start_time()
-
-        if initrd_time > 0:
-                print "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
-                        initrd_time/1000, \
-                        (start_time - initrd_time)/1000, \
-                        (finish_time - start_time)/1000, \
-                        finish_time/1000)
-        else:
-                print "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
-                        start_time/1000, \
-                        (finish_time - start_time)/1000, \
-                        finish_time/1000)
-
-
-elif sys.argv[1] == 'blame':
-
-        data = acquire_time_data()
-        s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
-
-        for name, ixt, aet, axt, iet in s:
-
-                if ixt <= 0 or aet <= 0:
-                        continue
-
-                if aet <= ixt:
-                        continue
-
-                sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
-
-elif sys.argv[1] == 'plot':
-        import cairo, os
-
-        initrd_time, start_time, finish_time = acquire_start_time()
-        data = acquire_time_data()
-        s = sorted(data, key = lambda i: i[1])
-
-        # Account for kernel and initramfs bars if they exist
-        if initrd_time > 0:
-                count = 3
-        else:
-                count = 2
-
-        for name, ixt, aet, axt, iet in s:
-
-                if (ixt >= start_time and ixt <= finish_time) or \
-                                (aet >= start_time and aet <= finish_time) or \
-                                (axt >= start_time and axt <= finish_time):
-                        count += 1
-
-        border = 100
-        bar_height = 20
-        bar_space = bar_height * 0.1
-
-        # 1000px = 10s, 1px = 10ms
-        width = finish_time/10000 + border*2
-        height = count * (bar_height + bar_space) + border * 2
-
-        if width < 1000:
-                width = 1000
-
-        surface = cairo.SVGSurface(sys.stdout, width, height)
-        context = cairo.Context(surface)
-
-        draw_box(context, 0, 0, width, height, 1, 1, 1)
-
-        context.translate(border + 0.5, border + 0.5)
-
-        context.save()
-        context.set_line_width(1)
-        context.set_source_rgb(0.7, 0.7, 0.7)
-
-        for x in range(0, finish_time/10000 + 100, 100):
-                context.move_to(x, 0)
-                context.line_to(x, height-border*2)
-
-        context.move_to(0, 0)
-        context.line_to(width-border*2, 0)
-
-        context.move_to(0, height-border*2)
-        context.line_to(width-border*2, height-border*2)
-
-        context.stroke()
-        context.restore()
-
-        osrel = "Linux"
-        if os.path.exists("/etc/os-release"):
-                for line in open("/etc/os-release"):
-                        if line.startswith('PRETTY_NAME='):
-                                osrel = line[12:]
-                                osrel = osrel.strip('\"\n')
-                                break
-
-        banner = "{} {} ({} {}) {}".format(osrel, *(os.uname()[1:5]))
-        draw_text(context, 0, -15, banner, hcenter = 0, vcenter = 1)
-
-        for x in range(0, finish_time/10000 + 100, 100):
-                draw_text(context, x, -5, "%lus" % (x/100), vcenter = 0, hcenter = 0)
-
-        y = 0
-
-        # draw boxes for kernel and initramfs boot time
-        if initrd_time > 0:
-                draw_box(context, 0, y, initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
-                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
-                y += bar_height + bar_space
-
-                draw_box(context, initrd_time/10000, y, start_time/10000-initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
-                draw_text(context, initrd_time/10000 + 10, y + bar_height/2, "initramfs", hcenter = 0)
-                y += bar_height + bar_space
-
-        else:
-                draw_box(context, 0, y, start_time/10000, bar_height, 0.6, 0.6, 0.6)
-                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
-                y += bar_height + bar_space
-
-        draw_box(context, start_time/10000, y, finish_time/10000-start_time/10000, bar_height, 0.7, 0.7, 0.7)
-        draw_text(context, start_time/10000 + 10, y + bar_height/2, "userspace", hcenter = 0)
-        y += bar_height + bar_space
-
-        for name, ixt, aet, axt, iet in s:
-
-                drawn = False
-                left = -1
-
-                if ixt >= start_time and ixt <= finish_time:
-
-                        # Activating
-                        a = ixt
-                        b = min(filter(lambda x: x >= ixt, (aet, axt, iet, finish_time))) - ixt
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, 1, 0, 0)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if aet >= start_time and aet <= finish_time:
-
-                        # Active
-                        a = aet
-                        b = min(filter(lambda x: x >= aet, (axt, iet, finish_time))) - aet
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, .8, .6, .6)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if axt >= start_time and axt <= finish_time:
-
-                        # Deactivating
-                        a = axt
-                        b = min(filter(lambda x: x >= axt, (iet, finish_time))) - axt
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, .6, .4, .4)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if drawn:
-                        x = left/10000
-
-                        if x < width/2-border:
-                                draw_text(context, x + 10, y + bar_height/2, name, hcenter = 0)
-                        else:
-                                draw_text(context, x - 10, y + bar_height/2, name, hcenter = 1)
-
-                        y += bar_height + bar_space
-
-        draw_text(context, 0, height-border*2, "Legend: Red = Activating; Pink = Active; Dark Pink = Deactivating", hcenter = 0, vcenter = -1)
-
-        if initrd_time > 0:
-                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
-                        initrd_time/1000, \
-                        (start_time - initrd_time)/1000, \
-                        (finish_time - start_time)/1000, \
-                        finish_time/1000), hcenter = 0, vcenter = -1)
-        else:
-                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
-                        start_time/1000, \
-                        (finish_time - start_time)/1000, \
-                        finish_time/1000), hcenter = 0, vcenter = -1)
-
-        surface.finish()
-elif sys.argv[1] in ("help", "--help", "-h"):
-        help()
-else:
-        sys.stderr.write("Unknown verb '%s'.\n" % sys.argv[1])
-        sys.exit(1)



More information about the systemd-commits mailing list