diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2018-01-18 16:40:00 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2018-01-18 16:40:00 +0000 |
commit | eadb00a03d4fe599f3dccd6d3330bee598b4464a (patch) | |
tree | 445b223b1ce42a336d10057fbdfe7313310e9bfb /endless | |
parent | 4274db0fa786a4ec8508c001589313619aed2956 (diff) |
Add more metadata in the profile state
We want to have access to more metadata, including the application id,
when capturing profiling data for later review, as the immediate
association between a process and its profiling data is not available in
that case.
Diffstat (limited to 'endless')
-rw-r--r-- | endless/eosprofile-private.h | 11 | ||||
-rw-r--r-- | endless/eosprofile.c | 53 |
2 files changed, 59 insertions, 5 deletions
diff --git a/endless/eosprofile-private.h b/endless/eosprofile-private.h index a07de0e..5a58233 100644 --- a/endless/eosprofile-private.h +++ b/endless/eosprofile-private.h @@ -11,12 +11,23 @@ G_BEGIN_DECLS #define PROBE_DB_META_BASE_KEY "/com/endlessm/Sdk/meta" #define PROBE_DB_META_VERSION_KEY PROBE_DB_META_BASE_KEY "/db_version" +#define PROBE_DB_META_APPID_KEY PROBE_DB_META_BASE_KEY "/app_id" +#define PROBE_DB_META_START_KEY PROBE_DB_META_BASE_KEY "/start_time" +#define PROBE_DB_META_PROFILE_KEY PROBE_DB_META_BASE_KEY "/profile_time" typedef struct { + /* element-type (key utf8) (value EosProfileProbe) */ GHashTable *probes; gboolean capture; char *capture_file; + + /* Wallclock time */ + gint64 start_time; + + /* Monotonic time */ + gint64 profile_start; + gint64 profile_end; } ProfileState; G_LOCK_DEFINE_STATIC (profile_state); diff --git a/endless/eosprofile.c b/endless/eosprofile.c index 3cf0881..1bf55f1 100644 --- a/endless/eosprofile.c +++ b/endless/eosprofile.c @@ -329,6 +329,12 @@ eos_profile_state_init (void) g_get_prgname ()); } } + + GTimeVal now; + g_get_current_time (&now); + profile_state->start_time = now.tv_sec; + + profile_state->profile_start = g_get_monotonic_time (); } } @@ -526,12 +532,53 @@ get_parent (GHashTable *table, return parent; } +static void +add_metadata (GHashTable *table) +{ + /* version */ + g_autofree char *version_key = g_strdup (PROBE_DB_META_VERSION_KEY); + gsize version_key_len = strlen (version_key); + GvdbItem *key_meta = gvdb_hash_table_insert (table, PROBE_DB_META_VERSION_KEY); + gvdb_item_set_parent (key_meta, get_parent (table, version_key, version_key_len)); + gvdb_item_set_value (key_meta, g_variant_new_int32 (PROBE_DB_VERSION)); + + /* application id */ + GApplication *app = g_application_get_default (); + if (app != NULL) + { + const char *appid = g_application_get_application_id (app); + + g_autofree char *appid_key = g_strdup (PROBE_DB_META_APPID_KEY); + gsize appid_key_len = strlen (appid_key); + GvdbItem *appid_meta = gvdb_hash_table_insert (table, PROBE_DB_META_APPID_KEY); + gvdb_item_set_parent (appid_meta, get_parent (table, appid_key, appid_key_len)); + gvdb_item_set_value (appid_meta, g_variant_new_string (appid)); + } + + /* start time */ + g_autofree char *start_key = g_strdup (PROBE_DB_META_START_KEY); + gsize start_key_len = strlen (start_key); + GvdbItem *start_meta = gvdb_hash_table_insert (table, PROBE_DB_META_START_KEY); + gvdb_item_set_parent (start_meta, get_parent (table, start_key, start_key_len)); + gvdb_item_set_value (start_meta, g_variant_new_int64 (profile_state->start_time)); + + /* profile time */ + g_autofree char *profile_key = g_strdup (PROBE_DB_META_PROFILE_KEY); + gsize profile_key_len = strlen (profile_key); + GvdbItem *profile_meta = gvdb_hash_table_insert (table, PROBE_DB_META_PROFILE_KEY); + gvdb_item_set_parent (profile_meta, get_parent (table, profile_key, profile_key_len)); + gint64 profile_time = profile_state->profile_end - profile_state->profile_start; + gvdb_item_set_value (profile_meta, g_variant_new_int64 (profile_time)); +} + void eos_profile_state_dump (void) { if (profile_state == NULL) return; + profile_state->profile_end = g_get_monotonic_time (); + if (!profile_state->capture) { profile_state_dump_to_console (); @@ -541,11 +588,7 @@ eos_profile_state_dump (void) g_autoptr(GHashTable) db_table = gvdb_hash_table_new (NULL, NULL); /* Metadata for the DB */ - g_autofree char *version_key = g_strdup (PROBE_DB_META_VERSION_KEY); - gsize version_key_len = strlen (version_key); - GvdbItem *meta = gvdb_hash_table_insert (db_table, PROBE_DB_META_VERSION_KEY); - gvdb_item_set_parent (meta, get_parent (db_table, version_key, version_key_len)); - gvdb_item_set_value (meta, g_variant_new_int32 (PROBE_DB_VERSION)); + add_metadata (db_table); /* Iterate over the probes */ GHashTableIter iter; |