libsysprof-analyze: add document type for fork

This commit is contained in:
Christian Hergert
2023-04-28 10:36:17 -07:00
parent 72c0ba731c
commit 6b762ef64a
6 changed files with 178 additions and 14 deletions

View File

@ -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',

View File

@ -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"

View File

@ -0,0 +1,95 @@
/* sysprof-document-fork.c
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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);
}

View File

@ -0,0 +1,41 @@
/* sysprof-document-fork.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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

View File

@ -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);

View File

@ -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");