mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
perf: delay source start until polkit has authorized
Without this, after logging in you are already multiple seconds into your profiling session recording. Not ideal. So instead, we do the async polkit auth upfront during SpSource::prepare(), and then toggle ready after we have received notification.
This commit is contained in:
@ -55,6 +55,7 @@ struct _SpPerfSource
|
||||
GHashTable *pids;
|
||||
|
||||
guint running : 1;
|
||||
guint is_ready : 1;
|
||||
};
|
||||
|
||||
static void source_iface_init (SpSourceInterface *iface);
|
||||
@ -430,6 +431,49 @@ sp_perf_source_add_pid (SpSource *source,
|
||||
g_hash_table_add (self->pids, GINT_TO_POINTER (pid));
|
||||
}
|
||||
|
||||
static void
|
||||
sp_perf_source_authorize_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(SpPerfSource) self = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
|
||||
if (!sp_perf_counter_authorize_finish (result, &error))
|
||||
{
|
||||
sp_source_emit_failed (SP_SOURCE (self), error);
|
||||
return;
|
||||
}
|
||||
|
||||
self->is_ready = TRUE;
|
||||
|
||||
sp_source_emit_ready (SP_SOURCE (self));
|
||||
}
|
||||
|
||||
static void
|
||||
sp_perf_source_prepare (SpSource *source)
|
||||
{
|
||||
SpPerfSource *self = (SpPerfSource *)source;
|
||||
|
||||
g_assert (SP_IS_PERF_SOURCE (self));
|
||||
|
||||
sp_perf_counter_authorize_async (NULL,
|
||||
sp_perf_source_authorize_cb,
|
||||
g_object_ref (self));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_perf_source_get_is_ready (SpSource *source)
|
||||
{
|
||||
SpPerfSource *self = (SpPerfSource *)source;
|
||||
|
||||
g_assert (SP_IS_PERF_SOURCE (self));
|
||||
|
||||
return self->is_ready;
|
||||
}
|
||||
|
||||
static void
|
||||
source_iface_init (SpSourceInterface *iface)
|
||||
{
|
||||
@ -437,6 +481,8 @@ source_iface_init (SpSourceInterface *iface)
|
||||
iface->stop = sp_perf_source_stop;
|
||||
iface->set_writer = sp_perf_source_set_writer;
|
||||
iface->add_pid = sp_perf_source_add_pid;
|
||||
iface->prepare = sp_perf_source_prepare;
|
||||
iface->get_is_ready = sp_perf_source_get_is_ready;
|
||||
}
|
||||
|
||||
SpSource *
|
||||
|
||||
Reference in New Issue
Block a user