From 3c45504da7143d54820cf2b375ed151553c06a4c Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 30 Apr 2016 16:41:31 +0100
Subject: [PATCH] tests/qemu: boot-analysis: Display libvirt as distinct
source.
Don't display libvirt events as '[library]', but as '[libvirt]'.
(cherry picked from commit 9cd00805b06528f99c9a986195cc46b787541d11)
---
tests/qemu/boot-analysis.c | 27 +++++++++++++++++++++++----
tests/qemu/boot-analysis.h | 8 ++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/tests/qemu/boot-analysis.c b/tests/qemu/boot-analysis.c
index a203f94..2067dfc 100644
--- a/tests/qemu/boot-analysis.c
+++ b/tests/qemu/boot-analysis.c
@@ -781,7 +781,7 @@ libvirt_log_thread (void *arg)
pthread_mutex_lock (&pass_data_lock);
if (libvirt_pass == -1) goto discard;
event =
- add_event_unlocked (&pass_data[libvirt_pass], GUESTFS_EVENT_LIBRARY);
+ add_event_unlocked (&pass_data[libvirt_pass], SOURCE_LIBVIRT);
event->message = strndup (buf, r);
if (event->message == NULL)
error (EXIT_FAILURE, errno, "strndup");
@@ -864,23 +864,42 @@ dump_pass_data (void)
printf (" elapsed time %" PRIi64 " ns\n", pass_data[i].elapsed_ns);
for (j = 0; j < pass_data[i].nr_events; ++j) {
int64_t ns, diff_ns;
- CLEANUP_FREE char *event_str = NULL;
+ CLEANUP_FREE char *source_str = NULL;
ns = timespec_diff (&pass_data[i].start_t, &pass_data[i].events[j].t);
- event_str = guestfs_event_to_string (pass_data[i].events[j].source);
+ source_str = source_to_string (pass_data[i].events[j].source);
printf (" %.1fms ", ns / 1000000.0);
if (j > 0) {
diff_ns = timespec_diff (&pass_data[i].events[j-1].t,
&pass_data[i].events[j].t);
printf ("(+%.1f) ", diff_ns / 1000000.0);
}
- printf ("[%s] \"", event_str);
+ printf ("[%s] \"", source_str);
print_escaped_string (pass_data[i].events[j].message);
printf ("\"\n");
}
}
}
+/* Convert source to a printable string. The caller must free the
+ * returned string.
+ */
+char *
+source_to_string (uint64_t source)
+{
+ char *ret;
+
+ if (source == SOURCE_LIBVIRT) {
+ ret = strdup ("libvirt");
+ if (ret == NULL)
+ error (EXIT_FAILURE, errno, "strdup");
+ }
+ else
+ ret = guestfs_event_to_string (source);
+
+ return ret; /* caller frees */
+}
+
int
activity_exists (const char *name)
{
diff --git a/tests/qemu/boot-analysis.h b/tests/qemu/boot-analysis.h
index 86d403e..a07f12e 100644
--- a/tests/qemu/boot-analysis.h
+++ b/tests/qemu/boot-analysis.h
@@ -46,6 +46,14 @@ struct pass_data {
int seen_launch;
};
+/* The 'source' field in the event is a guestfs event
+ * (GUESTFS_EVENT_*). We also wish to encode libvirt as a source, so
+ * we use a magic/impossible value for that here. Note that events
+ * are bitmasks, and normally no more than one bit may be set.
+ */
+#define SOURCE_LIBVIRT ((uint64_t)~0)
+extern char *source_to_string (uint64_t source);
+
struct event {
struct timespec t;
uint64_t source;
--
1.8.3.1