From 728a9ce86a23f938872a96bf2fbee30513df2f77 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 2 Jun 2023 13:38:03 -0700 Subject: [PATCH] libsysprof-profiler: add scaffolding for disk usage This still needs porting from libsysprof, but this gets the scaffolding in place to bring over those counters. --- src/libsysprof-profile/meson.build | 4 +- src/libsysprof-profile/sysprof-disk-usage.c | 67 ++++++++++++++++++++ src/libsysprof-profile/sysprof-disk-usage.h | 42 ++++++++++++ src/libsysprof-profile/sysprof-profile.h | 1 + src/libsysprof-profile/tests/test-profiler.c | 1 + 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/libsysprof-profile/sysprof-disk-usage.c create mode 100644 src/libsysprof-profile/sysprof-disk-usage.h diff --git a/src/libsysprof-profile/meson.build b/src/libsysprof-profile/meson.build index 957a3509..2d3b3b6f 100644 --- a/src/libsysprof-profile/meson.build +++ b/src/libsysprof-profile/meson.build @@ -1,5 +1,6 @@ libsysprof_profile_public_sources = [ 'sysprof-cpu-usage.c', + 'sysprof-disk-usage.c', 'sysprof-instrument.c', 'sysprof-network-usage.c', 'sysprof-profiler.c', @@ -17,8 +18,9 @@ libsysprof_profile_private_sources = [ libsysprof_profile_public_headers = [ 'sysprof-profile.h', - 'sysprof-instrument.h', 'sysprof-cpu-usage.h', + 'sysprof-disk-usage.h', + 'sysprof-instrument.h', 'sysprof-network-usage.h', 'sysprof-profiler.h', 'sysprof-recording.h', diff --git a/src/libsysprof-profile/sysprof-disk-usage.c b/src/libsysprof-profile/sysprof-disk-usage.c new file mode 100644 index 00000000..689c27a8 --- /dev/null +++ b/src/libsysprof-profile/sysprof-disk-usage.c @@ -0,0 +1,67 @@ +/* sysprof-disk-usage.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-disk-usage.h" +#include "sysprof-instrument-private.h" + +struct _SysprofDiskUsage +{ + SysprofInstrument parent_instance; +}; + +struct _SysprofDiskUsageClass +{ + SysprofInstrumentClass parent_class; +}; + +G_DEFINE_FINAL_TYPE (SysprofDiskUsage, sysprof_disk_usage, SYSPROF_TYPE_INSTRUMENT) + +static DexFuture * +sysprof_disk_usage_record (SysprofInstrument *instrument, + SysprofRecording *recording, + GCancellable *cancellable) +{ + g_assert (SYSPROF_IS_INSTRUMENT (instrument)); + g_assert (SYSPROF_IS_RECORDING (recording)); + g_assert (G_IS_CANCELLABLE (cancellable)); + + return dex_future_new_for_boolean (TRUE); +} + +static void +sysprof_disk_usage_class_init (SysprofDiskUsageClass *klass) +{ + SysprofInstrumentClass *instrument_class = SYSPROF_INSTRUMENT_CLASS (klass); + + instrument_class->record = sysprof_disk_usage_record; +} + +static void +sysprof_disk_usage_init (SysprofDiskUsage *self) +{ +} + +SysprofInstrument * +sysprof_disk_usage_new (void) +{ + return g_object_new (SYSPROF_TYPE_DISK_USAGE, NULL); +} diff --git a/src/libsysprof-profile/sysprof-disk-usage.h b/src/libsysprof-profile/sysprof-disk-usage.h new file mode 100644 index 00000000..af6192e9 --- /dev/null +++ b/src/libsysprof-profile/sysprof-disk-usage.h @@ -0,0 +1,42 @@ +/* sysprof-disk-usage.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.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_DISK_USAGE (sysprof_disk_usage_get_type()) +#define SYSPROF_IS_DISK_USAGE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DISK_USAGE) +#define SYSPROF_DISK_USAGE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DISK_USAGE, SysprofDiskUsage) +#define SYSPROF_DISK_USAGE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DISK_USAGE, SysprofDiskUsageClass) + +typedef struct _SysprofDiskUsage SysprofDiskUsage; +typedef struct _SysprofDiskUsageClass SysprofDiskUsageClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_disk_usage_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +SysprofInstrument *sysprof_disk_usage_new (void); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDiskUsage, g_object_unref) + +G_END_DECLS diff --git a/src/libsysprof-profile/sysprof-profile.h b/src/libsysprof-profile/sysprof-profile.h index 74f6e8ea..e8aace6d 100644 --- a/src/libsysprof-profile/sysprof-profile.h +++ b/src/libsysprof-profile/sysprof-profile.h @@ -26,6 +26,7 @@ G_BEGIN_DECLS #define SYSPROF_PROFILE_INSIDE # include "sysprof-cpu-usage.h" +# include "sysprof-disk-usage.h" # include "sysprof-instrument.h" # include "sysprof-network-usage.h" # include "sysprof-profiler.h" diff --git a/src/libsysprof-profile/tests/test-profiler.c b/src/libsysprof-profile/tests/test-profiler.c index 8e7780a8..5c3aa800 100644 --- a/src/libsysprof-profile/tests/test-profiler.c +++ b/src/libsysprof-profile/tests/test-profiler.c @@ -114,6 +114,7 @@ main (int argc, profiler = sysprof_profiler_new (); sysprof_profiler_add_instrument (profiler, sysprof_cpu_usage_new ()); + sysprof_profiler_add_instrument (profiler, sysprof_disk_usage_new ()); sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ()); sysprof_profiler_record_async (profiler, writer, NULL, record_cb, NULL);