mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-profile: add scaffolding for battery charge
This is a SysprofInstrument that will eventually contain the contents of the sysprof-battery-source.c to get battery charge/rate/etc. Note that this is different from energy usage which will come from RAPL.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
libsysprof_profile_public_sources = [
|
||||
'sysprof-battery-charge.c',
|
||||
'sysprof-cpu-usage.c',
|
||||
'sysprof-disk-usage.c',
|
||||
'sysprof-instrument.c',
|
||||
@ -21,6 +22,7 @@ libsysprof_profile_private_sources = [
|
||||
libsysprof_profile_public_headers = [
|
||||
'sysprof-profile.h',
|
||||
|
||||
'sysprof-battery-charge.h',
|
||||
'sysprof-cpu-usage.h',
|
||||
'sysprof-disk-usage.h',
|
||||
'sysprof-instrument.h',
|
||||
|
||||
121
src/libsysprof-profile/sysprof-battery-charge.c
Normal file
121
src/libsysprof-profile/sysprof-battery-charge.c
Normal file
@ -0,0 +1,121 @@
|
||||
/* sysprof-battery-charge.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 <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <glib-unix.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "line-reader-private.h"
|
||||
|
||||
#include "sysprof-battery-charge.h"
|
||||
#include "sysprof-instrument-private.h"
|
||||
#include "sysprof-recording-private.h"
|
||||
|
||||
struct _SysprofBatteryCharge
|
||||
{
|
||||
SysprofInstrument parent_instance;
|
||||
};
|
||||
|
||||
struct _SysprofBatteryChargeClass
|
||||
{
|
||||
SysprofInstrumentClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofBatteryCharge, sysprof_battery_charge, SYSPROF_TYPE_INSTRUMENT)
|
||||
|
||||
typedef struct _Record
|
||||
{
|
||||
SysprofRecording *recording;
|
||||
DexFuture *cancellable;
|
||||
} Record;
|
||||
|
||||
static void
|
||||
record_free (gpointer data)
|
||||
{
|
||||
Record *record = data;
|
||||
|
||||
g_clear_object (&record->recording);
|
||||
dex_clear (&record->cancellable);
|
||||
g_free (record);
|
||||
}
|
||||
|
||||
static DexFuture *
|
||||
sysprof_battery_charge_record_fiber (gpointer user_data)
|
||||
{
|
||||
G_GNUC_UNUSED SysprofCaptureWriter *writer;
|
||||
Record *record = user_data;
|
||||
|
||||
g_assert (record != NULL);
|
||||
g_assert (SYSPROF_IS_RECORDING (record->recording));
|
||||
g_assert (DEX_IS_FUTURE (record->cancellable));
|
||||
|
||||
writer = _sysprof_recording_writer (record->recording);
|
||||
|
||||
return dex_future_new_for_boolean (TRUE);
|
||||
}
|
||||
|
||||
static DexFuture *
|
||||
sysprof_battery_charge_record (SysprofInstrument *instrument,
|
||||
SysprofRecording *recording,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
Record *record;
|
||||
|
||||
g_assert (SYSPROF_IS_BATTERY_CHARGE (instrument));
|
||||
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||
g_assert (G_IS_CANCELLABLE (cancellable));
|
||||
|
||||
record = g_new0 (Record, 1);
|
||||
record->recording = g_object_ref (recording);
|
||||
record->cancellable = dex_cancellable_new_from_cancellable (cancellable);
|
||||
|
||||
return dex_scheduler_spawn (NULL, 0,
|
||||
sysprof_battery_charge_record_fiber,
|
||||
record,
|
||||
record_free);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_battery_charge_class_init (SysprofBatteryChargeClass *klass)
|
||||
{
|
||||
SysprofInstrumentClass *instrument_class = SYSPROF_INSTRUMENT_CLASS (klass);
|
||||
|
||||
instrument_class->record = sysprof_battery_charge_record;
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_battery_charge_init (SysprofBatteryCharge *self)
|
||||
{
|
||||
}
|
||||
|
||||
SysprofInstrument *
|
||||
sysprof_battery_charge_new (void)
|
||||
{
|
||||
return g_object_new (SYSPROF_TYPE_BATTERY_CHARGE, NULL);
|
||||
}
|
||||
42
src/libsysprof-profile/sysprof-battery-charge.h
Normal file
42
src/libsysprof-profile/sysprof-battery-charge.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* sysprof-battery-charge.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_BATTERY_CHARGE (sysprof_battery_charge_get_type())
|
||||
#define SYSPROF_IS_BATTERY_CHARGE(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_BATTERY_CHARGE)
|
||||
#define SYSPROF_BATTERY_CHARGE(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_BATTERY_CHARGE, SysprofBatteryCharge)
|
||||
#define SYSPROF_BATTERY_CHARGE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_BATTERY_CHARGE, SysprofBatteryChargeClass)
|
||||
|
||||
typedef struct _SysprofBatteryCharge SysprofBatteryCharge;
|
||||
typedef struct _SysprofBatteryChargeClass SysprofBatteryChargeClass;
|
||||
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GType sysprof_battery_charge_get_type (void) G_GNUC_CONST;
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
SysprofInstrument *sysprof_battery_charge_new (void);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofBatteryCharge, g_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
@ -25,6 +25,7 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SYSPROF_PROFILE_INSIDE
|
||||
# include "sysprof-battery-charge.h"
|
||||
# include "sysprof-cpu-usage.h"
|
||||
# include "sysprof-disk-usage.h"
|
||||
# include "sysprof-instrument.h"
|
||||
|
||||
@ -116,6 +116,7 @@ main (int argc,
|
||||
|
||||
profiler = sysprof_profiler_new ();
|
||||
|
||||
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_memory_usage_new ());
|
||||
|
||||
Reference in New Issue
Block a user