From f3ea9b2401acef94929c67192081cd7540429f53 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 13 Feb 2019 15:47:38 -0800 Subject: [PATCH] profiler: handle stop during startup more gracefully --- lib/profiler/sp-local-profiler.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/profiler/sp-local-profiler.c b/lib/profiler/sp-local-profiler.c index 3c3fc506..fda366a4 100644 --- a/lib/profiler/sp-local-profiler.c +++ b/lib/profiler/sp-local-profiler.c @@ -74,6 +74,13 @@ typedef struct * feature of per-process vs whole-system. */ guint whole_system : 1; + + /* + * If we got a stop request after calling start() but before we have had + * a chance to settle, then we need to stop immediately after starting. + * We do this to avoid a more complex state machine (for now). + */ + guint stop_after_starting : 1; } SpLocalProfilerPrivate; static void profiler_iface_init (SpProfilerInterface *iface); @@ -191,7 +198,13 @@ sp_local_profiler_stop (SpProfiler *profiler) g_return_if_fail (SP_IS_LOCAL_PROFILER (self)); - if (priv->is_stopping || (!priv->is_starting && !priv->is_running)) + if (priv->is_starting) + { + priv->stop_after_starting = TRUE; + return; + } + + if (priv->is_stopping || !priv->is_running) return; priv->is_stopping = TRUE; @@ -444,7 +457,7 @@ sp_local_profiler_finish_startup (SpLocalProfiler *self) * * If we detect this, we stop immediately. */ - if (priv->finished_or_failed->len == priv->sources->len) + if (priv->finished_or_failed->len == priv->sources->len || priv->stop_after_starting) sp_local_profiler_stop (SP_PROFILER (self)); }