From 6f3e57d1c0a46e6f4b06494d391bd7d78a84dbeb Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 12 Feb 2018 17:58:59 +0000 Subject: 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. --- tools/eos-profile-tool/eos-profile-utils.c | 51 ++++++++++++++++++++++++++++++ tools/eos-profile-tool/eos-profile-utils.h | 14 ++++++++ 2 files changed, 65 insertions(+) (limited to 'tools') 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 #include #include @@ -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 +#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); -- cgit v1.2.3