diff options
author | Martin Abente Lahaye <martin.abente.lahaye@gmail.com> | 2018-01-22 13:53:01 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-22 13:53:01 -0300 |
commit | 90342f56a3dd5afa7825f00001562843eebcb749 (patch) | |
tree | a76df910270c651b8232aa50e6566f06e5763c18 /endless | |
parent | 12ead3785058adecd32fa302855758035817fe29 (diff) | |
parent | eb46fb93d851295dfffbb290382eaa1cd7426303 (diff) |
Merge pull request #4179 from endlessm/T20694
T20694
Diffstat (limited to 'endless')
-rw-r--r-- | endless/eosprofile-private.h | 25 | ||||
-rw-r--r-- | endless/eosprofile.c | 84 |
2 files changed, 81 insertions, 28 deletions
diff --git a/endless/eosprofile-private.h b/endless/eosprofile-private.h index a07de0e..7c367bd 100644 --- a/endless/eosprofile-private.h +++ b/endless/eosprofile-private.h @@ -11,17 +11,42 @@ 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" + +#define PROBE_DB_META_PROBE_TYPE "(sssuua(xx))" 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); static ProfileState *profile_state; +struct _EosProfileProbe { + char *file; + gint32 line; + char *function; + char *name; + + /* element-type ProfileSample */ + GArray *samples; + + GMutex probe_lock; +}; + typedef struct { gint64 start_time; gint64 end_time; diff --git a/endless/eosprofile.c b/endless/eosprofile.c index 23959b3..732da79 100644 --- a/endless/eosprofile.c +++ b/endless/eosprofile.c @@ -110,19 +110,6 @@ sample_compare (gconstpointer a, #define N_SAMPLES 64 -struct _EosProfileProbe { - volatile int ref_count; - - char *file; - gint32 line; - char *function; - char *name; - - GArray *samples; - - GMutex probe_lock; -}; - static EosProfileProbe eos_profile_dummy_probe; static EosProfileProbe * @@ -133,8 +120,6 @@ eos_profile_probe_new (const char *file, { EosProfileProbe *res = g_new0 (EosProfileProbe, 1); - res->ref_count = 1; - res->name = g_strdup (name); res->function = g_strdup (function); res->file = g_strdup (file); @@ -152,9 +137,9 @@ eos_profile_probe_destroy (gpointer data) { EosProfileProbe *probe = data; - g_hash_table_remove (profile_state->probes, probe->name); + if (probe->samples != NULL) + g_array_unref (probe->samples); - g_array_unref (probe->samples); g_free (probe->name); g_free (probe->function); g_free (probe->file); @@ -333,6 +318,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 (); } } @@ -530,12 +521,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 (); @@ -545,11 +577,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; @@ -567,7 +595,7 @@ eos_profile_state_dump (void) GVariantBuilder builder; - g_variant_builder_init (&builder, G_VARIANT_TYPE ("(sssuua(xx))")); + g_variant_builder_init (&builder, G_VARIANT_TYPE (PROBE_DB_META_PROBE_TYPE)); g_variant_builder_add (&builder, "s", probe->name); g_variant_builder_add (&builder, "s", probe->function); @@ -602,11 +630,6 @@ eos_profile_state_dump (void) gvdb_item_set_value (item, g_variant_builder_end (&builder)); } - /* Clean up */ - g_hash_table_unref (profile_state->probes); - g_free (profile_state->capture_file); - g_free (profile_state); - g_autoptr(GError) error = NULL; gvdb_table_write_contents (db_table, profile_state->capture_file, G_BYTE_ORDER != G_LITTLE_ENDIAN, @@ -614,4 +637,9 @@ eos_profile_state_dump (void) if (error != NULL) g_printerr ("PROFILE: %s\n", error->message); + + /* Clean up */ + g_hash_table_unref (profile_state->probes); + g_free (profile_state->capture_file); + g_free (profile_state); } |