mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-capture: add helper to list files in capture
This commit is contained in:
@ -1173,3 +1173,39 @@ sysprof_capture_reader_read_file (SysprofCaptureReader *self)
|
|||||||
|
|
||||||
return file_chunk;
|
return file_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar **
|
||||||
|
sysprof_capture_reader_list_files (SysprofCaptureReader *self)
|
||||||
|
{
|
||||||
|
g_autoptr(GHashTable) files = NULL;
|
||||||
|
g_autoptr(GPtrArray) ar = NULL;
|
||||||
|
SysprofCaptureFrameType type;
|
||||||
|
GHashTableIter iter;
|
||||||
|
const gchar *key;
|
||||||
|
|
||||||
|
g_assert (self != NULL);
|
||||||
|
|
||||||
|
ar = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||||
|
|
||||||
|
while (sysprof_capture_reader_peek_type (self, &type))
|
||||||
|
{
|
||||||
|
const SysprofCaptureFileChunk *file;
|
||||||
|
|
||||||
|
if (type != SYSPROF_CAPTURE_FRAME_FILE_CHUNK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(file = sysprof_capture_reader_read_file (self)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!g_hash_table_contains (files, file->path))
|
||||||
|
g_hash_table_insert (files, g_strdup (file->path), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_iter_init (&iter, files);
|
||||||
|
while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
|
||||||
|
g_ptr_array_add (ar, g_strdup (key));
|
||||||
|
g_ptr_array_add (ar, NULL);
|
||||||
|
|
||||||
|
return (gchar **)g_ptr_array_free (g_steal_pointer (&ar), FALSE);
|
||||||
|
}
|
||||||
|
|||||||
@ -97,6 +97,8 @@ gboolean sysprof_capture_reader_get_stat
|
|||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_capture_reader_set_stat (SysprofCaptureReader *self,
|
void sysprof_capture_reader_set_stat (SysprofCaptureReader *self,
|
||||||
const SysprofCaptureStat *st_buf);
|
const SysprofCaptureStat *st_buf);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
gchar **sysprof_capture_reader_list_files (SysprofCaptureReader *self);
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unref)
|
||||||
|
|
||||||
|
|||||||
@ -716,6 +716,7 @@ test_reader_writer_file (void)
|
|||||||
{
|
{
|
||||||
g_autofree gchar *data = NULL;
|
g_autofree gchar *data = NULL;
|
||||||
GByteArray *buf = g_byte_array_new ();
|
GByteArray *buf = g_byte_array_new ();
|
||||||
|
g_auto(GStrv) files = NULL;
|
||||||
SysprofCaptureWriter *writer;
|
SysprofCaptureWriter *writer;
|
||||||
SysprofCaptureReader *reader;
|
SysprofCaptureReader *reader;
|
||||||
SysprofCaptureFrameType type;
|
SysprofCaptureFrameType type;
|
||||||
@ -772,6 +773,12 @@ test_reader_writer_file (void)
|
|||||||
r = sysprof_capture_reader_peek_type (reader, &type);
|
r = sysprof_capture_reader_peek_type (reader, &type);
|
||||||
g_assert_cmpint (r, ==, FALSE);
|
g_assert_cmpint (r, ==, FALSE);
|
||||||
|
|
||||||
|
sysprof_capture_reader_reset (reader);
|
||||||
|
files = sysprof_capture_reader_list_files (reader);
|
||||||
|
g_assert_nonnull (files);
|
||||||
|
g_assert_cmpstr (files[0], ==, "/proc/kallsyms");
|
||||||
|
g_assert_null (files[1]);
|
||||||
|
|
||||||
g_clear_pointer (&reader, sysprof_capture_reader_unref);
|
g_clear_pointer (&reader, sysprof_capture_reader_unref);
|
||||||
g_clear_pointer (&buf, g_byte_array_unref);
|
g_clear_pointer (&buf, g_byte_array_unref);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user