mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-analyze: add listmodel of processes
This is handy to be able to show a list of processes that were contained within a particular capture file.
This commit is contained in:
@ -43,6 +43,7 @@ struct _SysprofDocument
|
||||
|
||||
GtkBitset *file_chunks;
|
||||
GtkBitset *traceables;
|
||||
GtkBitset *processes;
|
||||
|
||||
GHashTable *files_first_position;
|
||||
|
||||
@ -117,6 +118,7 @@ sysprof_document_finalize (GObject *object)
|
||||
g_clear_pointer (&self->frames, g_array_unref);
|
||||
g_clear_pointer (&self->strings, g_hash_table_unref);
|
||||
g_clear_pointer (&self->traceables, gtk_bitset_unref);
|
||||
g_clear_pointer (&self->processes, gtk_bitset_unref);
|
||||
g_clear_pointer (&self->file_chunks, gtk_bitset_unref);
|
||||
g_clear_pointer (&self->files_first_position, g_hash_table_unref);
|
||||
|
||||
@ -142,6 +144,7 @@ sysprof_document_init (SysprofDocument *self)
|
||||
(GDestroyNotify)g_ref_string_release);
|
||||
self->traceables = gtk_bitset_new_empty ();
|
||||
self->file_chunks = gtk_bitset_new_empty ();
|
||||
self->processes = gtk_bitset_new_empty ();
|
||||
|
||||
self->files_first_position = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
@ -212,15 +215,19 @@ sysprof_document_load (SysprofDocument *self,
|
||||
ptr.length = frame_len;
|
||||
|
||||
tainted = (const SysprofCaptureFrame *)(gpointer)&self->base[pos];
|
||||
|
||||
if (tainted->type == SYSPROF_CAPTURE_FRAME_SAMPLE ||
|
||||
tainted->type == SYSPROF_CAPTURE_FRAME_ALLOCATION)
|
||||
gtk_bitset_add (self->traceables, self->frames->len);
|
||||
else if (tainted->type == SYSPROF_CAPTURE_FRAME_PROCESS)
|
||||
gtk_bitset_add (self->processes, self->frames->len);
|
||||
else if (tainted->type == SYSPROF_CAPTURE_FRAME_FILE_CHUNK)
|
||||
gtk_bitset_add (self->file_chunks, self->frames->len);
|
||||
|
||||
if (tainted->type == SYSPROF_CAPTURE_FRAME_FILE_CHUNK)
|
||||
{
|
||||
const SysprofCaptureFileChunk *file_chunk = (const SysprofCaptureFileChunk *)tainted;
|
||||
|
||||
gtk_bitset_add (self->file_chunks, self->frames->len);
|
||||
|
||||
if (has_null_byte (file_chunk->path, (const char *)file_chunk->data) &&
|
||||
!g_hash_table_contains (self->files_first_position, file_chunk->path))
|
||||
g_hash_table_insert (self->files_first_position,
|
||||
@ -540,3 +547,20 @@ sysprof_document_list_traceables (SysprofDocument *self)
|
||||
|
||||
return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), self->traceables);
|
||||
}
|
||||
|
||||
/**
|
||||
* sysprof_document_list_processes:
|
||||
* @self: a #SysprofDocument
|
||||
*
|
||||
* Gets a #GListModel containing #SysprofDocumentProcess found within
|
||||
* the #SysprofDocument.
|
||||
*
|
||||
* Returns: (transfer full): a #GListModel
|
||||
*/
|
||||
GListModel *
|
||||
sysprof_document_list_processes (SysprofDocument *self)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
|
||||
|
||||
return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), self->processes);
|
||||
}
|
||||
|
||||
@ -58,5 +58,7 @@ SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_files (SysprofDocument *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_traceables (SysprofDocument *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_processes (SysprofDocument *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@ -12,10 +12,11 @@ libsysprof_analyze_testsuite_c_args = [
|
||||
]
|
||||
|
||||
libsysprof_analyze_testsuite = {
|
||||
'test-capture-model' : {'skip': true},
|
||||
'test-list-files' : {'skip': true},
|
||||
'test-print-file' : {'skip': true},
|
||||
'test-symbolize' : {'skip': true},
|
||||
'test-capture-model' : {'skip': true},
|
||||
'test-list-files' : {'skip': true},
|
||||
'test-print-file' : {'skip': true},
|
||||
'test-list-processes' : {'skip': true},
|
||||
'test-symbolize' : {'skip': true},
|
||||
}
|
||||
|
||||
libsysprof_analyze_testsuite_deps = [
|
||||
|
||||
57
src/libsysprof-analyze/tests/test-list-processes.c
Normal file
57
src/libsysprof-analyze/tests/test-list-processes.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* test-list-processes.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 <sysprof-analyze.h>
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
g_autoptr(SysprofDocument) document = NULL;
|
||||
g_autoptr(GListModel) processes = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
guint n_items;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(document = sysprof_document_new (argv[1], &error)))
|
||||
{
|
||||
g_printerr ("Failed to open capture: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
processes = sysprof_document_list_processes (document);
|
||||
n_items = g_list_model_get_n_items (processes);
|
||||
|
||||
for (guint i = 0; i < n_items; i++)
|
||||
{
|
||||
g_autoptr(SysprofDocumentProcess) process = g_list_model_get_item (processes, i);
|
||||
|
||||
g_print ("%d: %s\n",
|
||||
sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)),
|
||||
sysprof_document_process_get_command_line (process));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user