diff --git a/src/libsysprof-gtk/meson.build b/src/libsysprof-gtk/meson.build index c43b3e8c..bb6b2dc3 100644 --- a/src/libsysprof-gtk/meson.build +++ b/src/libsysprof-gtk/meson.build @@ -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', ] diff --git a/src/libsysprof-gtk/sysprof-session-discover.c b/src/libsysprof-gtk/sysprof-session-discover.c new file mode 100644 index 00000000..b4af6be0 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-session-discover.c @@ -0,0 +1,48 @@ +/* sysprof-session-discover.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 + +#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); + } +} diff --git a/src/libsysprof-gtk/sysprof-session-private.h b/src/libsysprof-gtk/sysprof-session-private.h new file mode 100644 index 00000000..8eee33d8 --- /dev/null +++ b/src/libsysprof-gtk/sysprof-session-private.h @@ -0,0 +1,31 @@ +/* sysprof-session-private.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-session.h" + +G_BEGIN_DECLS + +void _sysprof_session_discover_tracks (SysprofSession *session, + SysprofDocument *document, + GListStore *tracks); + +G_END_DECLS diff --git a/src/libsysprof-gtk/sysprof-session.c b/src/libsysprof-gtk/sysprof-session.c index f6577c09..e2062efa 100644 --- a/src/libsysprof-gtk/sysprof-session.c +++ b/src/libsysprof-gtk/sysprof-session.c @@ -22,7 +22,7 @@ #include -#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