summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2018-02-12 17:58:59 +0000
committerP. F. Chimento <philip.chimento@gmail.com>2018-03-21 12:14:59 -0700
commit6f3e57d1c0a46e6f4b06494d391bd7d78a84dbeb (patch)
treea9db30dc3e648e5750739083842803248fc87f05 /tools
parent1cec67ba646c13a037829147790dbc5570473909 (diff)
Extract the probe parsing function
Both the convert and the show sub-commands for eos-profile have code to turn a GVariant into a profile probe for the v1 of the format. Let's move it out into its own internal utility function.
Diffstat (limited to 'tools')
-rw-r--r--tools/eos-profile-tool/eos-profile-utils.c51
-rw-r--r--tools/eos-profile-tool/eos-profile-utils.h14
2 files changed, 65 insertions, 0 deletions
diff --git a/tools/eos-profile-tool/eos-profile-utils.c b/tools/eos-profile-tool/eos-profile-utils.c
index 2d63804..483f375 100644
--- a/tools/eos-profile-tool/eos-profile-utils.c
+++ b/tools/eos-profile-tool/eos-profile-utils.c
@@ -2,6 +2,8 @@
#include "eos-profile-utils.h"
+#include "endless/eosprofile-private.h"
+
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
@@ -91,3 +93,52 @@ eos_profile_util_print_warning (const char *fmt,
g_printerr ("%s\n", msg);
}
+
+void
+eos_profile_util_foreach_probe_v1 (GvdbTable *db,
+ EosProfileProbeCallback callback,
+ gpointer callback_data)
+{
+ int names_len = 0;
+ g_auto(GStrv) names = gvdb_table_get_names (db, &names_len);
+
+ const char * const meta_keys[] = {
+ PROBE_DB_META_VERSION_KEY,
+ PROBE_DB_META_APPID_KEY,
+ PROBE_DB_META_PROFILE_KEY,
+ PROBE_DB_META_START_KEY,
+ NULL,
+ };
+
+ for (int i = 0; i < names_len; i++)
+ {
+ const char *key_name = names[i];
+
+ if (g_strv_contains (meta_keys, key_name))
+ continue;
+
+ if (!gvdb_table_has_value (db, key_name))
+ continue;
+
+ g_autoptr(GVariant) value = gvdb_table_get_raw_value (db, key_name);
+ if (value == NULL)
+ continue;
+
+ const char *file = NULL;
+ const char *function = NULL;
+ const char *probe_name = NULL;
+ g_autoptr(GVariant) samples = NULL;
+ gint32 line, n_samples;
+
+ g_variant_get (value, "(&s&s&suu@a(xx))",
+ &probe_name,
+ &function,
+ &file,
+ &line,
+ &n_samples,
+ &samples);
+
+ if (!callback (probe_name, function, file, line, n_samples, samples, callback_data))
+ break;
+ }
+}
diff --git a/tools/eos-profile-tool/eos-profile-utils.h b/tools/eos-profile-tool/eos-profile-utils.h
index b6030c2..44d69f0 100644
--- a/tools/eos-profile-tool/eos-profile-utils.h
+++ b/tools/eos-profile-tool/eos-profile-utils.h
@@ -2,6 +2,8 @@
#include <glib.h>
+#include "endless/gvdb/gvdb-reader.h"
+
typedef enum {
EOS_PRINT_COLOR_GREEN,
EOS_PRINT_COLOR_BLUE,
@@ -21,3 +23,15 @@ void eos_profile_util_print_error (const char *msg,
void eos_profile_util_print_warning (const char *msg,
...) G_GNUC_PRINTF (1, 2);
+
+typedef gboolean (* EosProfileProbeCallback) (const char *probe_name,
+ const char *function,
+ const char *file,
+ gint32 line,
+ gint32 n_samples,
+ GVariant *samples,
+ gpointer user_data);
+
+void eos_profile_util_foreach_probe_v1 (GvdbTable *db,
+ EosProfileProbeCallback callback,
+ gpointer callback_data);