diff --git a/src/libsysprof-profile/meson.build b/src/libsysprof-profile/meson.build index 56893e7b..7277ab98 100644 --- a/src/libsysprof-profile/meson.build +++ b/src/libsysprof-profile/meson.build @@ -2,6 +2,7 @@ libsysprof_profile_public_sources = [ 'sysprof-battery-charge.c', 'sysprof-cpu-usage.c', 'sysprof-disk-usage.c', + 'sysprof-energy-usage.c', 'sysprof-instrument.c', 'sysprof-memory-usage.c', 'sysprof-network-usage.c', @@ -26,6 +27,7 @@ libsysprof_profile_public_headers = [ 'sysprof-battery-charge.h', 'sysprof-cpu-usage.h', 'sysprof-disk-usage.h', + 'sysprof-energy-usage.h', 'sysprof-instrument.h', 'sysprof-memory-usage.h', 'sysprof-network-usage.h', diff --git a/src/libsysprof-profile/sysprof-energy-usage.c b/src/libsysprof-profile/sysprof-energy-usage.c new file mode 100644 index 00000000..6c4db985 --- /dev/null +++ b/src/libsysprof-profile/sysprof-energy-usage.c @@ -0,0 +1,57 @@ +/* sysprof-energy-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-proxied-instrument-private.h" +#include "sysprof-energy-usage.h" + +struct _SysprofEnergyUsage +{ + SysprofProxiedInstrument parent_instance; +}; + +struct _SysprofEnergyUsageClass +{ + SysprofProxiedInstrumentClass parent_class; +}; + +G_DEFINE_FINAL_TYPE (SysprofEnergyUsage, sysprof_energy_usage, SYSPROF_TYPE_PROXIED_INSTRUMENT) + +static void +sysprof_energy_usage_class_init (SysprofEnergyUsageClass *klass) +{ +} + +static void +sysprof_energy_usage_init (SysprofEnergyUsage *self) +{ + SYSPROF_PROXIED_INSTRUMENT (self)->call_stop_first = TRUE; +} + +SysprofInstrument * +sysprof_energy_usage_new (void) +{ + return g_object_new (SYSPROF_TYPE_ENERGY_USAGE, + "bus-type", G_BUS_TYPE_SYSTEM, + "bus-name", "org.gnome.Sysprof3", + "object-path", "/org/gnome/Sysprof3/RAPL", + NULL); +} diff --git a/src/libsysprof-profile/sysprof-energy-usage.h b/src/libsysprof-profile/sysprof-energy-usage.h new file mode 100644 index 00000000..211a2dfd --- /dev/null +++ b/src/libsysprof-profile/sysprof-energy-usage.h @@ -0,0 +1,42 @@ +/* sysprof-energy-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_ENERGY_USAGE (sysprof_energy_usage_get_type()) +#define SYSPROF_IS_ENERGY_USAGE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_ENERGY_USAGE) +#define SYSPROF_ENERGY_USAGE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_ENERGY_USAGE, SysprofEnergyUsage) +#define SYSPROF_ENERGY_USAGE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_ENERGY_USAGE, SysprofEnergyUsageClass) + +typedef struct _SysprofEnergyUsage SysprofEnergyUsage; +typedef struct _SysprofEnergyUsageClass SysprofEnergyUsageClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_energy_usage_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +SysprofInstrument *sysprof_energy_usage_new (void); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofEnergyUsage, g_object_unref) + +G_END_DECLS diff --git a/src/libsysprof-profile/sysprof-profile.h b/src/libsysprof-profile/sysprof-profile.h index 1c3b9a05..067af039 100644 --- a/src/libsysprof-profile/sysprof-profile.h +++ b/src/libsysprof-profile/sysprof-profile.h @@ -28,6 +28,7 @@ G_BEGIN_DECLS # include "sysprof-battery-charge.h" # include "sysprof-cpu-usage.h" # include "sysprof-disk-usage.h" +# include "sysprof-energy-usage.h" # include "sysprof-instrument.h" # include "sysprof-memory-usage.h" # include "sysprof-network-usage.h" diff --git a/src/libsysprof-profile/tests/test-profiler.c b/src/libsysprof-profile/tests/test-profiler.c index 365a09d4..1dbc9d8c 100644 --- a/src/libsysprof-profile/tests/test-profiler.c +++ b/src/libsysprof-profile/tests/test-profiler.c @@ -119,6 +119,7 @@ main (int argc, sysprof_profiler_add_instrument (profiler, sysprof_battery_charge_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_energy_usage_new ()); sysprof_profiler_add_instrument (profiler, sysprof_memory_usage_new ()); sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ()); sysprof_profiler_add_instrument (profiler, sysprof_sampler_new ());