[sysprof/wip/chergert/sysprof-3] tools: add option to list files in capture



commit 7a5746c276751a8bbecace05ffe5024c1de57f4b
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 27 17:17:03 2019 -0700

    tools: add option to list files in capture

 src/tools/sysprof-dump.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/tools/sysprof-dump.c b/src/tools/sysprof-dump.c
index 513f993..719e38c 100644
--- a/src/tools/sysprof-dump.c
+++ b/src/tools/sysprof-dump.c
@@ -18,23 +18,39 @@
  * SPDX-License-Identifier: GPL-3.0-or-later
  */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sysprof-capture.h>
 
 #define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
 
+static gboolean list_files = FALSE;
+static const GOptionEntry main_entries[] = {
+  { "list-files", 'l', 0, G_OPTION_ARG_NONE, &list_files, "List files within the capture" },
+  { 0 }
+};
+
 gint
 main (gint argc,
       gchar *argv[])
 {
+  g_autoptr(GOptionContext) context = g_option_context_new ("- dump capture data");
+  g_autoptr(GError) error = NULL;
   SysprofCaptureReader *reader;
   SysprofCaptureFrameType type;
   GHashTable *ctrtypes;
-  GError *error = NULL;
   gint64 begin_time;
   gint64 end_time;
 
+  g_option_context_add_main_entries (context, main_entries, NULL);
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      return EXIT_FAILURE;
+    }
+
   if (argc != 2)
     {
       g_printerr ("usage: %s FILENAME\n", argv[0]);
@@ -42,6 +58,17 @@ main (gint argc,
     }
 
   reader = sysprof_capture_reader_new (argv[1], &error);
+
+  if (list_files)
+    {
+      g_auto(GStrv) files = sysprof_capture_reader_list_files (reader);
+
+      for (guint i = 0; files[i]; i++)
+        g_print ("%s\n", files[i]);
+
+      return EXIT_SUCCESS;
+    }
+
   ctrtypes = g_hash_table_new (NULL, NULL);
 
   begin_time = sysprof_capture_reader_get_start_time (reader);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]