diff --git a/src/libsysprof-analyze/meson.build b/src/libsysprof-analyze/meson.build index e3c2f237..1c0f0eb2 100644 --- a/src/libsysprof-analyze/meson.build +++ b/src/libsysprof-analyze/meson.build @@ -1,6 +1,7 @@ libsysprof_analyze_public_sources = [ 'sysprof-document.c', 'sysprof-document-exit.c', + 'sysprof-document-fork.c', 'sysprof-document-frame.c', 'sysprof-document-log.c', 'sysprof-document-mark.c', @@ -14,6 +15,7 @@ libsysprof_analyze_public_headers = [ 'sysprof-analyze.h', 'sysprof-document.h', 'sysprof-document-exit.h', + 'sysprof-document-fork.h', 'sysprof-document-frame.h', 'sysprof-document-log.h', 'sysprof-document-mark.h', diff --git a/src/libsysprof-analyze/sysprof-analyze.h b/src/libsysprof-analyze/sysprof-analyze.h index e5b84129..c4d6df45 100644 --- a/src/libsysprof-analyze/sysprof-analyze.h +++ b/src/libsysprof-analyze/sysprof-analyze.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS #define SYSPROF_ANALYZE_INSIDE # include "sysprof-document.h" # include "sysprof-document-exit.h" +# include "sysprof-document-fork.h" # include "sysprof-document-frame.h" # include "sysprof-document-log.h" # include "sysprof-document-mark.h" diff --git a/src/libsysprof-analyze/sysprof-document-fork.c b/src/libsysprof-analyze/sysprof-document-fork.c new file mode 100644 index 00000000..fd4c44bf --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-fork.c @@ -0,0 +1,95 @@ +/* sysprof-document-fork.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-fork.h" + +struct _SysprofDocumentFork +{ + SysprofDocumentFrame parent_instance; +}; + +struct _SysprofDocumentForkClass +{ + SysprofDocumentFrameClass parent_class; +}; + +enum { + PROP_0, + PROP_CHILD_PID, + N_PROPS +}; + +G_DEFINE_FINAL_TYPE (SysprofDocumentFork, sysprof_document_fork, SYSPROF_TYPE_DOCUMENT_FRAME) + +static GParamSpec *properties [N_PROPS]; + +static void +sysprof_document_fork_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SysprofDocumentFork *self = SYSPROF_DOCUMENT_FORK (object); + + switch (prop_id) + { + case PROP_CHILD_PID: + g_value_set_int (value, sysprof_document_fork_get_child_pid (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +sysprof_document_fork_class_init (SysprofDocumentForkClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->get_property = sysprof_document_fork_get_property; + + properties [PROP_CHILD_PID] = + g_param_spec_int ("child-pid", NULL, NULL, + G_MININT, G_MAXINT, 0, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); +} + +static void +sysprof_document_fork_init (SysprofDocumentFork *self) +{ +} + +int +sysprof_document_fork_get_child_pid (SysprofDocumentFork *self) +{ + const SysprofCaptureFork *fork; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FORK (self), 0); + + fork = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureFork); + + return SYSPROF_DOCUMENT_FRAME_INT32 (self, fork->child_pid); +} diff --git a/src/libsysprof-analyze/sysprof-document-fork.h b/src/libsysprof-analyze/sysprof-document-fork.h new file mode 100644 index 00000000..021a157e --- /dev/null +++ b/src/libsysprof-analyze/sysprof-document-fork.h @@ -0,0 +1,41 @@ +/* sysprof-document-fork.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_FORK (sysprof_document_fork_get_type()) +#define SYSPROF_IS_DOCUMENT_FORK(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_FORK) +#define SYSPROF_DOCUMENT_FORK(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_FORK, SysprofDocumentFork) +#define SYSPROF_DOCUMENT_FORK_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_FORK, SysprofDocumentForkClass) + +typedef struct _SysprofDocumentFork SysprofDocumentFork; +typedef struct _SysprofDocumentForkClass SysprofDocumentForkClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_document_fork_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +int sysprof_document_fork_get_child_pid (SysprofDocumentFork *self); + +G_END_DECLS + diff --git a/src/libsysprof-analyze/sysprof-document-frame.c b/src/libsysprof-analyze/sysprof-document-frame.c index 0b13a3dd..e96ead77 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.c +++ b/src/libsysprof-analyze/sysprof-document-frame.c @@ -23,6 +23,7 @@ #include "sysprof-document-frame-private.h" #include "sysprof-document-exit.h" +#include "sysprof-document-fork.h" #include "sysprof-document-log.h" #include "sysprof-document-mark.h" #include "sysprof-document-mmap.h" @@ -124,22 +125,43 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, guint16 frame_len, gboolean needs_swap) { - GType gtype = SYSPROF_TYPE_DOCUMENT_FRAME; SysprofDocumentFrame *self; + GType gtype; - if (0) {} - else if (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE) - gtype = SYSPROF_TYPE_DOCUMENT_SAMPLE; - else if (frame->type == SYSPROF_CAPTURE_FRAME_MAP) - gtype = SYSPROF_TYPE_DOCUMENT_MMAP; - else if (frame->type == SYSPROF_CAPTURE_FRAME_LOG) - 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; - else if (frame->type == SYSPROF_CAPTURE_FRAME_EXIT) - gtype = SYSPROF_TYPE_DOCUMENT_EXIT; + switch (frame->type) + { + case SYSPROF_CAPTURE_FRAME_SAMPLE: + gtype = SYSPROF_TYPE_DOCUMENT_SAMPLE; + break; + + case SYSPROF_CAPTURE_FRAME_MAP: + gtype = SYSPROF_TYPE_DOCUMENT_MMAP; + break; + + case SYSPROF_CAPTURE_FRAME_LOG: + gtype = SYSPROF_TYPE_DOCUMENT_LOG; + break; + + case SYSPROF_CAPTURE_FRAME_MARK: + gtype = SYSPROF_TYPE_DOCUMENT_MARK; + break; + + case SYSPROF_CAPTURE_FRAME_PROCESS: + gtype = SYSPROF_TYPE_DOCUMENT_PROCESS; + break; + + case SYSPROF_CAPTURE_FRAME_EXIT: + gtype = SYSPROF_TYPE_DOCUMENT_EXIT; + break; + + case SYSPROF_CAPTURE_FRAME_FORK: + gtype = SYSPROF_TYPE_DOCUMENT_FORK; + break; + + default: + gtype = SYSPROF_TYPE_DOCUMENT_FRAME; + break; + } self = g_object_new (gtype, NULL); self->mapped_file = g_mapped_file_ref (mapped_file); diff --git a/src/libsysprof-analyze/tests/test-capture-model.c b/src/libsysprof-analyze/tests/test-capture-model.c index 35485924..6044a49c 100644 --- a/src/libsysprof-analyze/tests/test-capture-model.c +++ b/src/libsysprof-analyze/tests/test-capture-model.c @@ -58,6 +58,9 @@ main (int argc, g_print (" id=%s value=%s", sysprof_document_metadata_get_id (SYSPROF_DOCUMENT_METADATA (frame)), sysprof_document_metadata_get_value (SYSPROF_DOCUMENT_METADATA (frame))); + else if (SYSPROF_IS_DOCUMENT_FORK (frame)) + g_print (" child-pid=%d", + sysprof_document_fork_get_child_pid (SYSPROF_DOCUMENT_FORK (frame))); g_print ("\n");