From 11aa39f151e9bc6b640b728673b340491786f13f Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 26 May 2023 12:18:59 -0700 Subject: [PATCH] libsysprof-profile: add scaffolding for controlfd source This is internal to the profile and will always be active when running subprocesses with Sysprof. --- src/libsysprof-profile/meson.build | 1 + .../sysprof-controlfd-instrument-private.h | 33 +++++++++++ .../sysprof-controlfd-instrument.c | 57 +++++++++++++++++++ src/libsysprof-profile/sysprof-profiler.c | 3 + 4 files changed, 94 insertions(+) create mode 100644 src/libsysprof-profile/sysprof-controlfd-instrument-private.h create mode 100644 src/libsysprof-profile/sysprof-controlfd-instrument.c diff --git a/src/libsysprof-profile/meson.build b/src/libsysprof-profile/meson.build index 5ce52170..d1fcc752 100644 --- a/src/libsysprof-profile/meson.build +++ b/src/libsysprof-profile/meson.build @@ -5,6 +5,7 @@ libsysprof_profile_public_sources = [ ] libsysprof_profile_private_sources = [ + 'sysprof-controlfd-instrument.c', ] libsysprof_profile_public_headers = [ diff --git a/src/libsysprof-profile/sysprof-controlfd-instrument-private.h b/src/libsysprof-profile/sysprof-controlfd-instrument-private.h new file mode 100644 index 00000000..23352b3c --- /dev/null +++ b/src/libsysprof-profile/sysprof-controlfd-instrument-private.h @@ -0,0 +1,33 @@ +/* sysprof-controlfd-instrument-private.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-instrument-private.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_CONTROLFD_INSTRUMENT (sysprof_controlfd_instrument_get_type()) + +G_DECLARE_FINAL_TYPE (SysprofControlfdInstrument, sysprof_controlfd_instrument, SYSPROF, CONTROLFD_INSTRUMENT, SysprofInstrument) + +SysprofInstrument *_sysprof_controlfd_instrument_new (void); + +G_END_DECLS diff --git a/src/libsysprof-profile/sysprof-controlfd-instrument.c b/src/libsysprof-profile/sysprof-controlfd-instrument.c new file mode 100644 index 00000000..e83f79b5 --- /dev/null +++ b/src/libsysprof-profile/sysprof-controlfd-instrument.c @@ -0,0 +1,57 @@ +/* sysprof-controlfd-instrument.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-controlfd-instrument-private.h" + +struct _SysprofControlfdInstrument +{ + SysprofInstrument parent_instance; +}; + +G_DEFINE_FINAL_TYPE (SysprofControlfdInstrument, sysprof_controlfd_instrument, SYSPROF_TYPE_INSTRUMENT) + +static void +sysprof_controlfd_instrument_finalize (GObject *object) +{ + SysprofControlfdInstrument *self = (SysprofControlfdInstrument *)object; + + G_OBJECT_CLASS (sysprof_controlfd_instrument_parent_class)->finalize (object); +} + +static void +sysprof_controlfd_instrument_class_init (SysprofControlfdInstrumentClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = sysprof_controlfd_instrument_finalize; +} + +static void +sysprof_controlfd_instrument_init (SysprofControlfdInstrument *self) +{ +} + +SysprofInstrument * +_sysprof_controlfd_instrument_new (void) +{ + return g_object_new (SYSPROF_TYPE_CONTROLFD_INSTRUMENT, NULL); +} diff --git a/src/libsysprof-profile/sysprof-profiler.c b/src/libsysprof-profile/sysprof-profiler.c index a0639f41..6f12a118 100644 --- a/src/libsysprof-profile/sysprof-profiler.c +++ b/src/libsysprof-profile/sysprof-profiler.c @@ -20,6 +20,7 @@ #include "config.h" +#include "sysprof-controlfd-instrument-private.h" #include "sysprof-profiler.h" #include "sysprof-recording-private.h" @@ -82,6 +83,8 @@ static void sysprof_profiler_init (SysprofProfiler *self) { self->instruments = g_ptr_array_new_with_free_func (g_object_unref); + + sysprof_profiler_add_instrument (self, _sysprof_controlfd_instrument_new ()); } SysprofProfiler *