mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-analyze: improve progress notifications
This commit is contained in:
@ -44,6 +44,7 @@ struct _SysprofDocumentLoader
|
||||
double fraction;
|
||||
int fd;
|
||||
guint notify_source;
|
||||
guint symbolizing : 1;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -85,8 +86,14 @@ set_progress (double fraction,
|
||||
g_assert (SYSPROF_IS_DOCUMENT_LOADER (self));
|
||||
|
||||
g_mutex_lock (&self->mutex);
|
||||
self->fraction = fraction;
|
||||
|
||||
self->fraction = fraction * .5;
|
||||
|
||||
if (self->symbolizing)
|
||||
self->fraction += .5;
|
||||
|
||||
g_set_str (&self->message, message);
|
||||
|
||||
if (!self->notify_source)
|
||||
self->notify_source = g_idle_add_full (G_PRIORITY_LOW,
|
||||
progress_notify_in_idle,
|
||||
@ -421,7 +428,7 @@ sysprof_document_loader_load_symbols_cb (GObject *object,
|
||||
|
||||
self = g_task_get_source_object (task);
|
||||
|
||||
set_progress (1., _("Document loaded"), self);
|
||||
set_progress (0., _("Document loaded"), self);
|
||||
|
||||
if (!_sysprof_document_symbolize_finish (document, result, &error))
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
@ -449,16 +456,24 @@ sysprof_document_loader_load_document_cb (GObject *object,
|
||||
g_assert (symbolizer != NULL);
|
||||
g_assert (SYSPROF_IS_SYMBOLIZER (symbolizer));
|
||||
|
||||
set_progress (.9, _("Symbolizing stack traces"), self);
|
||||
|
||||
if (!(document = _sysprof_document_new_finish (result, &error)))
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
else
|
||||
_sysprof_document_symbolize_async (document,
|
||||
symbolizer,
|
||||
g_task_get_cancellable (task),
|
||||
sysprof_document_loader_load_symbols_cb,
|
||||
g_object_ref (task));
|
||||
{
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
set_progress (1., _("Loading failed"), self);
|
||||
}
|
||||
|
||||
self->symbolizing = TRUE;
|
||||
|
||||
set_progress (.0, _("Symbolizing stack traces"), self);
|
||||
|
||||
_sysprof_document_symbolize_async (document,
|
||||
symbolizer,
|
||||
set_progress,
|
||||
g_object_ref (self),
|
||||
g_object_unref,
|
||||
g_task_get_cancellable (task),
|
||||
sysprof_document_loader_load_symbols_cb,
|
||||
g_object_ref (task));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -53,6 +53,9 @@ SysprofDocument *_sysprof_document_new_finish (GAsyncResult *resul
|
||||
GError **error);
|
||||
void _sysprof_document_symbolize_async (SysprofDocument *self,
|
||||
SysprofSymbolizer *symbolizer,
|
||||
ProgressFunc progress_func,
|
||||
gpointer progress_data,
|
||||
GDestroyNotify progress_data_destroy,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
@ -43,6 +43,9 @@ void _sysprof_document_symbols_new (SysprofDocument
|
||||
SysprofStrings *strings,
|
||||
SysprofSymbolizer *symbolizer,
|
||||
GHashTable *pid_to_process_info,
|
||||
ProgressFunc progress_func,
|
||||
gpointer progress_data,
|
||||
GDestroyNotify progress_data_destroy,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
@ -20,6 +20,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "sysprof-address-layout-private.h"
|
||||
#include "sysprof-document-private.h"
|
||||
#include "sysprof-document-symbols-private.h"
|
||||
@ -65,11 +67,16 @@ typedef struct _Symbolize
|
||||
SysprofDocumentSymbols *symbols;
|
||||
SysprofStrings *strings;
|
||||
GHashTable *pid_to_process_info;
|
||||
ProgressFunc progress_func;
|
||||
gpointer progress_data;
|
||||
GDestroyNotify progress_data_destroy;
|
||||
} Symbolize;
|
||||
|
||||
static void
|
||||
symbolize_free (Symbolize *state)
|
||||
{
|
||||
if (state->progress_data_destroy)
|
||||
state->progress_data_destroy (state->progress_data);
|
||||
g_clear_object (&state->document);
|
||||
g_clear_object (&state->symbolizer);
|
||||
g_clear_object (&state->symbols);
|
||||
@ -155,6 +162,7 @@ sysprof_document_symbols_worker (GTask *task,
|
||||
EggBitsetIter iter;
|
||||
EggBitset *bitset;
|
||||
GListModel *model;
|
||||
guint count = 0;
|
||||
guint i;
|
||||
|
||||
g_assert (source_object == NULL);
|
||||
@ -189,6 +197,8 @@ sysprof_document_symbols_worker (GTask *task,
|
||||
if (!SYSPROF_IS_NO_SYMBOLIZER (state->symbolizer) &&
|
||||
egg_bitset_iter_init_first (&iter, bitset, &i))
|
||||
{
|
||||
guint n_items = egg_bitset_get_size (bitset);
|
||||
|
||||
do
|
||||
{
|
||||
g_autoptr(SysprofDocumentTraceable) traceable = g_list_model_get_item (model, i);
|
||||
@ -200,6 +210,11 @@ sysprof_document_symbols_worker (GTask *task,
|
||||
process_info,
|
||||
traceable,
|
||||
state->symbolizer);
|
||||
|
||||
count++;
|
||||
|
||||
if (state->progress_func != NULL && count % 100 == 0)
|
||||
state->progress_func (count / (double)n_items, _("Symbolizing stack traces"), state->progress_data);
|
||||
}
|
||||
while (egg_bitset_iter_next (&iter, &i));
|
||||
}
|
||||
@ -214,6 +229,9 @@ _sysprof_document_symbols_new (SysprofDocument *document,
|
||||
SysprofStrings *strings,
|
||||
SysprofSymbolizer *symbolizer,
|
||||
GHashTable *pid_to_process_info,
|
||||
ProgressFunc progress_func,
|
||||
gpointer progress_data,
|
||||
GDestroyNotify progress_data_destroy,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
@ -230,6 +248,9 @@ _sysprof_document_symbols_new (SysprofDocument *document,
|
||||
state->symbols = g_object_new (SYSPROF_TYPE_DOCUMENT_SYMBOLS, NULL);
|
||||
state->strings = sysprof_strings_ref (strings);
|
||||
state->pid_to_process_info = g_hash_table_ref (pid_to_process_info);
|
||||
state->progress_func = progress_func;
|
||||
state->progress_data = progress_data;
|
||||
state->progress_data_destroy = progress_data_destroy;
|
||||
|
||||
task = g_task_new (NULL, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, _sysprof_document_symbols_new);
|
||||
|
||||
@ -1003,6 +1003,21 @@ sysprof_document_symbolize_symbols_cb (GObject *object,
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
|
||||
typedef struct _Symbolize
|
||||
{
|
||||
ProgressFunc progress_func;
|
||||
gpointer progress_data;
|
||||
GDestroyNotify progress_data_destroy;
|
||||
} Symbolize;
|
||||
|
||||
static void
|
||||
symbolize_free (Symbolize *state)
|
||||
{
|
||||
if (state->progress_data_destroy)
|
||||
state->progress_data_destroy (state->progress_data);
|
||||
g_free (state);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_document_symbolize_prepare_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
@ -1012,6 +1027,7 @@ sysprof_document_symbolize_prepare_cb (GObject *object,
|
||||
g_autoptr(GTask) task = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
SysprofDocument *self;
|
||||
Symbolize *state;
|
||||
|
||||
g_assert (SYSPROF_IS_SYMBOLIZER (symbolizer));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
@ -1023,6 +1039,8 @@ sysprof_document_symbolize_prepare_cb (GObject *object,
|
||||
g_assert (SYSPROF_IS_DOCUMENT (self));
|
||||
g_assert (self->pid_to_process_info != NULL);
|
||||
|
||||
state = g_task_get_task_data (task);
|
||||
|
||||
if (!_sysprof_symbolizer_prepare_finish (symbolizer, result, &error))
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
else
|
||||
@ -1030,6 +1048,9 @@ sysprof_document_symbolize_prepare_cb (GObject *object,
|
||||
self->strings,
|
||||
symbolizer,
|
||||
self->pid_to_process_info,
|
||||
state->progress_func,
|
||||
state->progress_data,
|
||||
NULL,
|
||||
g_task_get_cancellable (task),
|
||||
sysprof_document_symbolize_symbols_cb,
|
||||
g_object_ref (task));
|
||||
@ -1038,12 +1059,15 @@ sysprof_document_symbolize_prepare_cb (GObject *object,
|
||||
void
|
||||
_sysprof_document_symbolize_async (SysprofDocument *self,
|
||||
SysprofSymbolizer *symbolizer,
|
||||
ProgressFunc progress_func,
|
||||
gpointer progress_data,
|
||||
GDestroyNotify progress_data_destroy,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(SysprofDocumentSymbols) symbols = NULL;
|
||||
g_autoptr(GTask) task = NULL;
|
||||
Symbolize *state;
|
||||
|
||||
g_return_if_fail (SYSPROF_IS_DOCUMENT (self));
|
||||
g_return_if_fail (SYSPROF_IS_SYMBOLIZER (symbolizer));
|
||||
@ -1052,6 +1076,12 @@ _sysprof_document_symbolize_async (SysprofDocument *self,
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, _sysprof_document_symbolize_async);
|
||||
|
||||
state = g_new0 (Symbolize, 1);
|
||||
state->progress_func = progress_func;
|
||||
state->progress_data = progress_data;
|
||||
state->progress_data_destroy = progress_data_destroy;
|
||||
g_task_set_task_data(task, state, (GDestroyNotify)symbolize_free);
|
||||
|
||||
_sysprof_symbolizer_prepare_async (symbolizer,
|
||||
self,
|
||||
cancellable,
|
||||
|
||||
@ -147,7 +147,7 @@ main (int argc,
|
||||
"spacing", 6,
|
||||
NULL);
|
||||
message = g_object_new (GTK_TYPE_LABEL,
|
||||
"xalign", .0f,
|
||||
"xalign", 1.f,
|
||||
"hexpand", TRUE,
|
||||
NULL);
|
||||
progress = g_object_new (GTK_TYPE_PROGRESS_BAR,
|
||||
|
||||
Reference in New Issue
Block a user