libsysprof-profile: add RAPL-based SysprofEnergyUsage

This does what we did previously with RAPL via sysprofd, with the new
SysprofInstrument API.
This commit is contained in:
Christian Hergert
2023-06-06 15:56:38 -07:00
parent 6f661c6bfe
commit 0e625cea21
5 changed files with 103 additions and 0 deletions

View File

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

View File

@ -0,0 +1,57 @@
/* sysprof-energy-usage.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-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);
}

View File

@ -0,0 +1,42 @@
/* sysprof-energy-usage.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-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

View File

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

View File

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