From 24d0d4af52009cb6b1640e8202783bc7a05617e8 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 27 Apr 2023 17:45:04 -0700 Subject: [PATCH] libsysprof-analyze: add document type for processes Generally this is all the processes at startup, but can also be a process that is executed while the capture is running. Useful to pair with an Exit frame for pid/tid duration. --- src/libsysprof-analyze/meson.build | 2 + src/libsysprof-analyze/sysprof-analyze.h | 1 + .../sysprof-document-frame.c | 3 + .../sysprof-document-process.c | 95 +++++++++++++++++++ .../sysprof-document-process.h | 41 ++++++++ 5 files changed, 142 insertions(+) create mode 100644 src/libsysprof-analyze/sysprof-document-process.c create mode 100644 src/libsysprof-analyze/sysprof-document-process.h diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index 471a9ef3..7e13118d 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -4,6 +4,7 @@ libsysprof_analyze_public_sources = [ 'sysprof-document-log.c', 'sysprof-document-mark.c', 'sysprof-document-mmap.c', + 'sysprof-document-process.c', 'sysprof-document-sample.c', ] @@ -14,6 +15,7 @@ libsysprof_analyze_public_headers = [ 'sysprof-document-log.h', 'sysprof-document-mark.h', 'sysprof-document-mmap.h', + 'sysprof-document-process.h', 'sysprof-document-sample.h', ] diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index 01814bd4..d41763d9 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -30,6 +30,7 @@ G_BEGIN_DECLS # include "sysprof-document-log.h" # include "sysprof-document-mark.h" # include "sysprof-document-mmap.h" +# include "sysprof-document-process.h" # include "sysprof-document-sample.h" #undef SYSPROF_ANALYZE_INSIDE diff --git a/src/libsysprof-analyze/sysprof-document-frame.c b/src/libsysprof-analyze/sysprof-document-frame.c index 0f3fd8e6..daa6605c 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.c +++ b/src/libsysprof-analyze/sysprof-document-frame.c @@ -24,6 +24,7 @@ #include "sysprof-document-log.h" #include "sysprof-document-mark.h" #include "sysprof-document-mmap.h" +#include "sysprof-document-process.h" #include "sysprof-document-sample.h" G_DEFINE_TYPE (SysprofDocumentFrame, sysprof_document_frame, G_TYPE_OBJECT) @@ -133,6 +134,8 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, gtype = SYSPROF_TYPE_DOCUMENT_LOG; else if (frame->type == SYSPROF_CAPTURE_FRAME_MARK) gtype = SYSPROF_TYPE_DOCUMENT_MARK; + else if (frame->type == SYSPROF_CAPTURE_FRAME_PROCESS) + gtype = SYSPROF_TYPE_DOCUMENT_PROCESS; self = g_object_new (gtype, NULL); self->mapped_file = g_mapped_file_ref (mapped_file); diff --git a/src/libsysprof-analyze/sysprof-document-process.c b/src/libsysprof-analyze/sysprof-document-process.c new file mode 100644 index 00000000..d307616b --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-process.c @@ -0,0 +1,95 @@ +/* sysprof-document-process.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-frame-private.h" +#include "sysprof-document-process.h" + +struct _SysprofDocumentProcess +{ + SysprofDocumentFrame parent_instance; +}; + +struct _SysprofDocumentProcessClass +{ + SysprofDocumentFrameClass parent_class; +}; + +enum { + PROP_0, + PROP_COMMAND_LINE, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofDocumentProcess, sysprof_document_process, SYSPROF_TYPE_DOCUMENT_FRAME) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_document_process_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofDocumentProcess *self = SYSPROF_DOCUMENT_PROCESS (object); + + switch (prop_id) + { + case PROP_COMMAND_LINE: + g_value_set_string (value, sysprof_document_process_get_command_line (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_document_process_class_init (SysprofDocumentProcessClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = sysprof_document_process_get_property; + + properties [PROP_COMMAND_LINE] = + g_param_spec_string ("command-line", NULL, NULL, + NULL, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_document_process_init (SysprofDocumentProcess *self) +{ +} + +const char * +sysprof_document_process_get_command_line (SysprofDocumentProcess *self) +{ + const SysprofCaptureProcess *proc; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_PROCESS (self), 0); + + proc = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureProcess); + + return SYSPROF_DOCUMENT_FRAME_CSTRING (self, proc->cmdline); +} diff --git a/src/libsysprof-analyze/sysprof-document-process.h b/src/libsysprof-analyze/sysprof-document-process.h new file mode 100644 index 00000000..c6da18db --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-process.h @@ -0,0 +1,41 @@ +/* sysprof-document-process.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 "sysprof-document-frame.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_DOCUMENT_PROCESS (sysprof_document_process_get_type()) +#define SYSPROF_IS_DOCUMENT_PROCESS(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_PROCESS) +#define SYSPROF_DOCUMENT_PROCESS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_PROCESS, SysprofDocumentProcess) +#define SYSPROF_DOCUMENT_PROCESS_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_PROCESS, SysprofDocumentProcessClass) + +typedef struct _SysprofDocumentProcess SysprofDocumentProcess; +typedef struct _SysprofDocumentProcessClass SysprofDocumentProcessClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_document_process_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +const char *sysprof_document_process_get_command_line (SysprofDocumentProcess *self); + +G_END_DECLS +