libsysprof-analyze: give access to memory maps from process

And add it to test tool to ensure it works.
This commit is contained in:
Christian Hergert
2023-05-11 12:32:32 -07:00
parent 9b5e25037b
commit 5abad47160
3 changed files with 37 additions and 0 deletions

View File

@ -106,6 +106,25 @@ sysprof_document_process_get_command_line (SysprofDocumentProcess *self)
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, proc->cmdline);
}
/**
* sysprof_document_process_list_memory_maps:
* @self: a #SysprofDocumentProcess
*
* Lists the #SysprofDocumentMmap that are associated with the document.
*
* Returns: (transfer full): a #GListModel of #SysprofDocumentMmap
*/
GListModel *
sysprof_document_process_list_memory_maps (SysprofDocumentProcess *self)
{
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_PROCESS (self), NULL);
if (self->process_info == NULL)
return G_LIST_MODEL (g_list_store_new (SYSPROF_TYPE_DOCUMENT_MMAP));
return g_object_ref (G_LIST_MODEL (self->process_info->address_layout));
}
void
_sysprof_document_process_set_info (SysprofDocumentProcess *self,
SysprofProcessInfo *process_info)

View File

@ -20,6 +20,8 @@
#pragma once
#include <gio/gio.h>
#include "sysprof-document-frame.h"
G_BEGIN_DECLS
@ -36,6 +38,8 @@ SYSPROF_AVAILABLE_IN_ALL
GType sysprof_document_process_get_type (void) G_GNUC_CONST;
SYSPROF_AVAILABLE_IN_ALL
const char *sysprof_document_process_get_command_line (SysprofDocumentProcess *self);
SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_process_list_memory_maps (SysprofDocumentProcess *self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentProcess, g_object_unref)

View File

@ -47,10 +47,24 @@ main (int argc,
for (guint i = 0; i < n_items; i++)
{
g_autoptr(SysprofDocumentProcess) process = g_list_model_get_item (processes, i);
g_autoptr(GListModel) memory_maps = sysprof_document_process_list_memory_maps (process);
guint n_maps;
g_print ("%d: %s\n",
sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)),
sysprof_document_process_get_command_line (process));
n_maps = g_list_model_get_n_items (memory_maps);
for (guint j = 0; j < n_maps; j++)
{
g_autoptr(SysprofDocumentMmap) map = g_list_model_get_item (memory_maps, j);
g_print (" [0x%"G_GINT64_MODIFIER"x:0x%"G_GINT64_MODIFIER"x] %s\n",
sysprof_document_mmap_get_start_address (map),
sysprof_document_mmap_get_end_address (map),
sysprof_document_mmap_get_file (map));
}
}
return 0;