diff --git a/src/libsysprof/sysprof-document.c b/src/libsysprof/sysprof-document.c index 7dac5538..b376c34a 100644 --- a/src/libsysprof/sysprof-document.c +++ b/src/libsysprof/sysprof-document.c @@ -2498,3 +2498,40 @@ sysprof_document_serialize_symbols_finish (SysprofDocument *self, return dex_async_result_propagate_pointer (DEX_ASYNC_RESULT (result), error); } + +/** + * sysprof_document_lookup_process: + * @self: a #SysprofDocument + * @pid: the process identifier + * + * Looks up a process by PID. + * + * If multiple copies of the process exist, the result is undefined. + * + * Returns: (transfer full) (nullable): a #SysprofDocumentProcess or %NULL + */ +SysprofDocumentProcess * +sysprof_document_lookup_process (SysprofDocument *self, + int pid) +{ + EggBitsetIter iter; + guint position; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL); + + if (egg_bitset_iter_init_first (&iter, self->processes, &position)) + { + do + { + g_autoptr(SysprofDocumentProcess) process = g_list_model_get_item (G_LIST_MODEL (self), position); + + g_assert (SYSPROF_IS_DOCUMENT_PROCESS (process)); + + if (sysprof_document_frame_get_pid (SYSPROF_DOCUMENT_FRAME (process)) == pid) + return g_steal_pointer (&process); + } + while (egg_bitset_iter_next (&iter, &position)); + } + + return NULL; +} diff --git a/src/libsysprof/sysprof-document.h b/src/libsysprof/sysprof-document.h index 2eb85fa0..fa72d807 100644 --- a/src/libsysprof/sysprof-document.h +++ b/src/libsysprof/sysprof-document.h @@ -27,6 +27,7 @@ #include "sysprof-callgraph.h" #include "sysprof-document-counter.h" #include "sysprof-document-file.h" +#include "sysprof-document-process.h" #include "sysprof-document-traceable.h" #include "sysprof-mark-catalog.h" #include "sysprof-symbol.h" @@ -47,6 +48,9 @@ SYSPROF_AVAILABLE_IN_ALL SysprofDocumentFile *sysprof_document_lookup_file (SysprofDocument *self, const char *path); SYSPROF_AVAILABLE_IN_ALL +SysprofDocumentProcess *sysprof_document_lookup_process (SysprofDocument *self, + int pid); +SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_document_list_cpu_info (SysprofDocument *self); SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_document_list_files (SysprofDocument *self);