mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: break track discover out into seperate module
This stuff can eventually get pretty hairy, so keep it contained and away from the rest of the session so it may stay tidy.
This commit is contained in:
@ -67,6 +67,7 @@ libsysprof_gtk_private_sources = [
|
||||
'sysprof-mark-chart-item.c',
|
||||
'sysprof-mark-chart-row.c',
|
||||
'sysprof-progress-cell.c',
|
||||
'sysprof-session-discover.c',
|
||||
'sysprof-symbol-label.c',
|
||||
'sysprof-time-label.c',
|
||||
]
|
||||
|
||||
48
src/libsysprof-gtk/sysprof-session-discover.c
Normal file
48
src/libsysprof-gtk/sysprof-session-discover.c
Normal file
@ -0,0 +1,48 @@
|
||||
/* sysprof-session-discover.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 <glib/gi18n.h>
|
||||
|
||||
#include "sysprof-session-private.h"
|
||||
#include "sysprof-track.h"
|
||||
|
||||
void
|
||||
_sysprof_session_discover_tracks (SysprofSession *self,
|
||||
SysprofDocument *document,
|
||||
GListStore *tracks)
|
||||
{
|
||||
g_autoptr(SysprofDocumentCounter) cpu = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (self));
|
||||
g_assert (SYSPROF_IS_DOCUMENT (document));
|
||||
g_assert (G_IS_LIST_STORE (tracks));
|
||||
|
||||
if ((cpu = sysprof_document_find_counter (document, "CPU Percent", "Combined")))
|
||||
{
|
||||
g_autoptr(SysprofTrack) cpu_track = NULL;
|
||||
|
||||
cpu_track = g_object_new (SYSPROF_TYPE_TRACK,
|
||||
"title", _("CPU Usage"),
|
||||
NULL);
|
||||
g_list_store_append (tracks, cpu_track);
|
||||
}
|
||||
}
|
||||
31
src/libsysprof-gtk/sysprof-session-private.h
Normal file
31
src/libsysprof-gtk/sysprof-session-private.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* sysprof-session-private.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-session.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void _sysprof_session_discover_tracks (SysprofSession *session,
|
||||
SysprofDocument *document,
|
||||
GListStore *tracks);
|
||||
|
||||
G_END_DECLS
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "sysprof-session.h"
|
||||
#include "sysprof-session-private.h"
|
||||
#include "sysprof-track.h"
|
||||
#include "sysprof-value-axis.h"
|
||||
|
||||
@ -74,54 +74,6 @@ sysprof_session_update_axis (SysprofSession *self)
|
||||
self->selected_time.end_nsec);
|
||||
}
|
||||
|
||||
static SysprofDocumentCounter *
|
||||
sysprof_session_find_counter (SysprofSession *self,
|
||||
const char *category,
|
||||
const char *name)
|
||||
{
|
||||
g_autoptr(GListModel) counters = NULL;
|
||||
guint n_items;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (self));
|
||||
g_assert (category != NULL);
|
||||
g_assert (name != NULL);
|
||||
|
||||
if (self->document == NULL)
|
||||
return NULL;
|
||||
|
||||
counters = sysprof_document_list_counters (self->document);
|
||||
n_items = g_list_model_get_n_items (counters);
|
||||
|
||||
for (guint i = 0; i < n_items; i++)
|
||||
{
|
||||
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (counters, i);
|
||||
|
||||
if (g_strcmp0 (category, sysprof_document_counter_get_category (counter)) == 0 &&
|
||||
g_strcmp0 (name, sysprof_document_counter_get_name (counter)) == 0)
|
||||
return g_steal_pointer (&counter);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_session_discover_tracks (SysprofSession *self)
|
||||
{
|
||||
g_autoptr(SysprofDocumentCounter) cpu = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (self));
|
||||
|
||||
if ((cpu = sysprof_session_find_counter (self, "CPU Percent", "Combined")))
|
||||
{
|
||||
g_autoptr(SysprofTrack) cpu_track = NULL;
|
||||
|
||||
cpu_track = g_object_new (SYSPROF_TYPE_TRACK,
|
||||
"title", _("CPU Usage"),
|
||||
NULL);
|
||||
g_list_store_append (self->tracks, cpu_track);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_session_set_document (SysprofSession *self,
|
||||
SysprofDocument *document)
|
||||
@ -141,7 +93,7 @@ sysprof_session_set_document (SysprofSession *self,
|
||||
sysprof_session_update_axis (self);
|
||||
|
||||
/* Discover tracks to show from the document */
|
||||
sysprof_session_discover_tracks (self);
|
||||
_sysprof_session_discover_tracks (self, self->document, self->tracks);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user