[sysprof/wip/chergert/sysprof-3] libsysprof: allow creating model item from gvariant info
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/sysprof-3] libsysprof: allow creating model item from gvariant info
- Date: Sat, 11 May 2019 03:30:23 +0000 (UTC)
commit 096ce0f4333b3ad1a9dc1173f6cda344a2283836
Author: Christian Hergert <chergert redhat com>
Date: Fri May 10 20:29:37 2019 -0700
libsysprof: allow creating model item from gvariant info
src/libsysprof/sysprof-process-model-item.c | 34 ++++++++++++++++++++++++++++-
src/libsysprof/sysprof-process-model-item.h | 2 ++
2 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/src/libsysprof/sysprof-process-model-item.c b/src/libsysprof/sysprof-process-model-item.c
index 6575528..bdad212 100644
--- a/src/libsysprof/sysprof-process-model-item.c
+++ b/src/libsysprof/sysprof-process-model-item.c
@@ -140,6 +140,38 @@ sysprof_process_model_item_init (SysprofProcessModelItem *self)
{
}
+SysprofProcessModelItem *
+sysprof_process_model_item_new_from_variant (GVariant *info)
+{
+ SysprofProcessModelItem *ret;
+ GVariantDict dict;
+ const gchar *cmdline;
+
+ g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (g_variant_is_of_type (info, G_VARIANT_TYPE_VARDICT), NULL);
+
+ ret = g_object_new (SYSPROF_TYPE_PROCESS_MODEL_ITEM, NULL);
+
+ g_variant_dict_init (&dict, info);
+
+ if (g_variant_dict_lookup (&dict, "cmdline", "&s", &cmdline) && *cmdline)
+ {
+ if (g_shell_parse_argv (cmdline, NULL, &ret->argv, NULL))
+ ret->command_line = g_strdup (ret->argv[0]);
+ }
+ else if (g_variant_dict_lookup (&dict, "comm", "&s", &cmdline))
+ {
+ ret->argv = g_new0 (gchar *, 2);
+ ret->argv[0] = g_strdup (cmdline);
+ ret->is_kernel = TRUE;
+ }
+
+ g_variant_dict_lookup (&dict, "pid", "i", &ret->pid);
+ g_variant_dict_clear (&dict);
+
+ return g_steal_pointer (&ret);
+}
+
SysprofProcessModelItem *
sysprof_process_model_item_new (GPid pid)
{
@@ -170,7 +202,7 @@ sysprof_process_model_item_hash (SysprofProcessModelItem *self)
gboolean
sysprof_process_model_item_equal (SysprofProcessModelItem *self,
- SysprofProcessModelItem *other)
+ SysprofProcessModelItem *other)
{
g_assert (SYSPROF_IS_PROCESS_MODEL_ITEM (self));
g_assert (SYSPROF_IS_PROCESS_MODEL_ITEM (other));
diff --git a/src/libsysprof/sysprof-process-model-item.h b/src/libsysprof/sysprof-process-model-item.h
index 5a175ae..bfff6bb 100644
--- a/src/libsysprof/sysprof-process-model-item.h
+++ b/src/libsysprof/sysprof-process-model-item.h
@@ -38,6 +38,8 @@ G_DECLARE_FINAL_TYPE (SysprofProcessModelItem, sysprof_process_model_item, SYSPR
SYSPROF_AVAILABLE_IN_ALL
SysprofProcessModelItem *sysprof_process_model_item_new (GPid pid);
SYSPROF_AVAILABLE_IN_ALL
+SysprofProcessModelItem *sysprof_process_model_item_new_from_variant (GVariant *info);
+SYSPROF_AVAILABLE_IN_ALL
guint sysprof_process_model_item_hash (SysprofProcessModelItem *self);
SYSPROF_AVAILABLE_IN_ALL
gboolean sysprof_process_model_item_equal (SysprofProcessModelItem *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]