From 7a3f90e8f515880291c5b95350bf3c3646c5b975 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 28 Apr 2023 16:49:52 -0700 Subject: [PATCH] libsysprof-analyze: add process list model This is not yet functional, but gets the scaffolding in place that we'll use to filter out processes and turn them into something more useful such as their execution lifetime. --- src/libsysprof-analyze/meson.build | 2 + src/libsysprof-analyze/sysprof-analyze.h | 1 + .../sysprof-document-process-list.c | 170 ++++++++++++++++++ .../sysprof-document-process-list.h | 42 +++++ 4 files changed, 215 insertions(+) create mode 100644 src/libsysprof-analyze/sysprof-document-process-list.c create mode 100644 src/libsysprof-analyze/sysprof-document-process-list.h diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index 76388006..05ad05d3 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -9,6 +9,7 @@ libsysprof_analyze_public_sources = [ 'sysprof-document-metadata.c', 'sysprof-document-mmap.c', 'sysprof-document-process.c', + 'sysprof-document-process-list.c', 'sysprof-document-sample.c', 'sysprof-document-traceable.c', ] @@ -25,6 +26,7 @@ libsysprof_analyze_public_headers = [ 'sysprof-document-metadata.h', 'sysprof-document-mmap.h', 'sysprof-document-process.h', + 'sysprof-document-process-list.h', 'sysprof-document-sample.h', 'sysprof-document-traceable.h', ] diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index ed3f9bd3..133bcb60 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -35,6 +35,7 @@ G_BEGIN_DECLS # include "sysprof-document-metadata.h" # include "sysprof-document-mmap.h" # include "sysprof-document-process.h" +# include "sysprof-document-process-list.h" # include "sysprof-document-sample.h" # include "sysprof-document-traceable.h" #undef SYSPROF_ANALYZE_INSIDE diff --git a/src/libsysprof-analyze/sysprof-document-process-list.c b/src/libsysprof-analyze/sysprof-document-process-list.c new file mode 100644 index 00000000..e43f8284 --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-process-list.c @@ -0,0 +1,170 @@ +/* + * sysprof-document-process-list.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-document-process-list.h" + +struct _SysprofDocumentProcessList +{ + GObject parent_instance; + GListModel *model; +}; + +static void list_model_iface_init (GListModelInterface *iface); + +G_DEFINE_FINAL_TYPE_WITH_CODE (SysprofDocumentProcessList, sysprof_document_process_list, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init)) + +enum { + PROP_0, + PROP_MODEL, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +/** + * sysprof_document_process_list_new: + * @model: a #GListModel or %NULL + * + * Creates a new #SysprofDocumentProcessList. + * + * The resulting process list can be used to determine the lifetime of + * processes that were found within the document. + * + * Returns: (transfer full): a new #SysprofDocumentProcessList + */ +SysprofDocumentProcessList * +sysprof_document_process_list_new (GListModel *model) +{ + g_return_val_if_fail (!model || G_IS_LIST_MODEL (model), NULL); + + return g_object_new (SYSPROF_TYPE_DOCUMENT_PROCESS_LIST, + "model", model, + NULL); +} + +static void +sysprof_document_process_list_finalize (GObject *object) +{ + SysprofDocumentProcessList *self = (SysprofDocumentProcessList *)object; + + g_clear_object (&self->model); + + G_OBJECT_CLASS (sysprof_document_process_list_parent_class)->finalize (object); +} + +static void +sysprof_document_process_list_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofDocumentProcessList *self = SYSPROF_DOCUMENT_PROCESS_LIST (object); + + switch (prop_id) + { + case PROP_MODEL: + g_value_set_object (value, sysprof_document_process_list_get_model (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_document_process_list_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SysprofDocumentProcessList *self = SYSPROF_DOCUMENT_PROCESS_LIST (object); + + switch (prop_id) + { + case PROP_MODEL: + sysprof_document_process_list_set_model (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_document_process_list_class_init (SysprofDocumentProcessListClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_document_process_list_finalize; + object_class->get_property = sysprof_document_process_list_get_property; + object_class->set_property = sysprof_document_process_list_set_property; + + properties [PROP_MODEL] = + g_param_spec_object ("model", NULL, NULL, + G_TYPE_OBJECT, + (G_PARAM_READWRITE | + G_PARAM_EXPLICIT_NOTIFY | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_document_process_list_init (SysprofDocumentProcessList *self) +{ +} + +static void +list_model_iface_init (GListModelInterface *iface) +{ +} + +/** + * sysprof_document_process_list_get_model: + * @self: a #SysprofDocumentProcessList + * + * Gets the underlying model containing processes to extract. + * + * Returns: (transfer none) (nullable): a #GListModel or %NULL + */ +GListModel * +sysprof_document_process_list_get_model (SysprofDocumentProcessList *self) +{ + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_PROCESS_LIST (self), NULL); + + return self->model; +} + +void +sysprof_document_process_list_set_model (SysprofDocumentProcessList *self, + GListModel *model) +{ + g_return_if_fail (SYSPROF_IS_DOCUMENT_PROCESS_LIST (self)); + g_return_if_fail (!model || G_IS_LIST_MODEL (model)); + + if (g_set_object (&self->model, model)) + { + g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MODEL]); + } +} diff --git a/src/libsysprof-analyze/sysprof-document-process-list.h b/src/libsysprof-analyze/sysprof-document-process-list.h new file mode 100644 index 00000000..72309bae --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-process-list.h @@ -0,0 +1,42 @@ +/* sysprof-document-process-list.h + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +#include + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_DOCUMENT_PROCESS_LIST (sysprof_document_process_list_get_type()) + +SYSPROF_AVAILABLE_IN_ALL +G_DECLARE_FINAL_TYPE (SysprofDocumentProcessList, sysprof_document_process_list, SYSPROF, DOCUMENT_PROCESS_LIST, GObject) + +SYSPROF_AVAILABLE_IN_ALL +SysprofDocumentProcessList *sysprof_document_process_list_new (GListModel *model); +SYSPROF_AVAILABLE_IN_ALL +GListModel *sysprof_document_process_list_get_model (SysprofDocumentProcessList *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_document_process_list_set_model (SysprofDocumentProcessList *self, + GListModel *model); + +G_END_DECLS