Blame SOURCES/0076-tests-qemu-boot-analysis-Display-libvirt-as-distinct.patch

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