mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Merge branch 'task-trace' into 'master'
Add some tracing to GTask See merge request GNOME/glib!1629
This commit is contained in:
commit
6e9ed964c3
25
gio/gtask.c
25
gio/gtask.c
@ -24,6 +24,7 @@
|
|||||||
#include "gasyncresult.h"
|
#include "gasyncresult.h"
|
||||||
#include "gcancellable.h"
|
#include "gcancellable.h"
|
||||||
#include "glib-private.h"
|
#include "glib-private.h"
|
||||||
|
#include "gtrace-private.h"
|
||||||
|
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
|
|
||||||
@ -618,6 +619,9 @@ static GSource *task_pool_manager;
|
|||||||
static guint64 task_wait_time;
|
static guint64 task_wait_time;
|
||||||
static gint tasks_running;
|
static gint tasks_running;
|
||||||
|
|
||||||
|
static guint task_pool_max_counter;
|
||||||
|
static guint tasks_running_counter;
|
||||||
|
|
||||||
/* When the task pool fills up and blocks, and the program keeps
|
/* When the task pool fills up and blocks, and the program keeps
|
||||||
* queueing more tasks, we will slowly add more threads to the pool
|
* queueing more tasks, we will slowly add more threads to the pool
|
||||||
* (in case the existing tasks are trying to queue subtasks of their
|
* (in case the existing tasks are trying to queue subtasks of their
|
||||||
@ -1361,6 +1365,7 @@ task_pool_manager_timeout (gpointer user_data)
|
|||||||
{
|
{
|
||||||
g_mutex_lock (&task_pool_mutex);
|
g_mutex_lock (&task_pool_mutex);
|
||||||
g_thread_pool_set_max_threads (task_pool, tasks_running + 1, NULL);
|
g_thread_pool_set_max_threads (task_pool, tasks_running + 1, NULL);
|
||||||
|
g_trace_set_int64_counter (task_pool_max_counter, tasks_running + 1);
|
||||||
g_source_set_ready_time (task_pool_manager, -1);
|
g_source_set_ready_time (task_pool_manager, -1);
|
||||||
g_mutex_unlock (&task_pool_mutex);
|
g_mutex_unlock (&task_pool_mutex);
|
||||||
|
|
||||||
@ -1374,6 +1379,8 @@ g_task_thread_setup (void)
|
|||||||
g_mutex_lock (&task_pool_mutex);
|
g_mutex_lock (&task_pool_mutex);
|
||||||
tasks_running++;
|
tasks_running++;
|
||||||
|
|
||||||
|
g_trace_set_int64_counter (tasks_running_counter, tasks_running);
|
||||||
|
|
||||||
if (tasks_running == G_TASK_POOL_SIZE)
|
if (tasks_running == G_TASK_POOL_SIZE)
|
||||||
task_wait_time = G_TASK_WAIT_TIME_BASE;
|
task_wait_time = G_TASK_WAIT_TIME_BASE;
|
||||||
else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
|
else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
|
||||||
@ -1394,7 +1401,10 @@ g_task_thread_cleanup (void)
|
|||||||
tasks_pending = g_thread_pool_unprocessed (task_pool);
|
tasks_pending = g_thread_pool_unprocessed (task_pool);
|
||||||
|
|
||||||
if (tasks_running > G_TASK_POOL_SIZE)
|
if (tasks_running > G_TASK_POOL_SIZE)
|
||||||
g_thread_pool_set_max_threads (task_pool, tasks_running - 1, NULL);
|
{
|
||||||
|
g_thread_pool_set_max_threads (task_pool, tasks_running - 1, NULL);
|
||||||
|
g_trace_set_int64_counter (task_pool_max_counter, tasks_running - 1);
|
||||||
|
}
|
||||||
else if (tasks_running + tasks_pending < G_TASK_POOL_SIZE)
|
else if (tasks_running + tasks_pending < G_TASK_POOL_SIZE)
|
||||||
g_source_set_ready_time (task_pool_manager, -1);
|
g_source_set_ready_time (task_pool_manager, -1);
|
||||||
|
|
||||||
@ -1402,6 +1412,9 @@ g_task_thread_cleanup (void)
|
|||||||
task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER;
|
task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER;
|
||||||
|
|
||||||
tasks_running--;
|
tasks_running--;
|
||||||
|
|
||||||
|
g_trace_set_int64_counter (tasks_running_counter, tasks_running);
|
||||||
|
|
||||||
g_mutex_unlock (&task_pool_mutex);
|
g_mutex_unlock (&task_pool_mutex);
|
||||||
g_private_set (&task_private, GUINT_TO_POINTER (FALSE));
|
g_private_set (&task_private, GUINT_TO_POINTER (FALSE));
|
||||||
}
|
}
|
||||||
@ -2214,6 +2227,16 @@ g_task_class_init (GTaskClass *klass)
|
|||||||
P_("Task completed"),
|
P_("Task completed"),
|
||||||
P_("Whether the task has completed yet"),
|
P_("Whether the task has completed yet"),
|
||||||
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
if (G_UNLIKELY (task_pool_max_counter == 0))
|
||||||
|
{
|
||||||
|
/* We use two counters to track characteristics of the GTask thread pool.
|
||||||
|
* task pool max size - the value of g_thread_pool_set_max_threads()
|
||||||
|
* tasks running - the number of running threads
|
||||||
|
*/
|
||||||
|
task_pool_max_counter = g_trace_define_int64_counter ("GIO", "task pool max size", "Maximum number of threads allowed in the GTask thread pool; see g_thread_pool_set_max_threads()");
|
||||||
|
tasks_running_counter = g_trace_define_int64_counter ("GIO", "tasks running", "Number of currently running tasks in the GTask thread pool");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
|
@ -577,6 +577,7 @@ gio_sources = files(
|
|||||||
'gzlibdecompressor.c',
|
'gzlibdecompressor.c',
|
||||||
'glistmodel.c',
|
'glistmodel.c',
|
||||||
'gliststore.c',
|
'gliststore.c',
|
||||||
|
'../glib/gtrace.c',
|
||||||
)
|
)
|
||||||
|
|
||||||
gio_sources += appinfo_sources
|
gio_sources += appinfo_sources
|
||||||
@ -791,7 +792,7 @@ libgio = library('gio-2.0',
|
|||||||
# '$(gio_win32_res_ldflag)',
|
# '$(gio_win32_res_ldflag)',
|
||||||
dependencies : [libz_dep, libdl_dep, libmount_dep, libglib_dep,
|
dependencies : [libz_dep, libdl_dep, libmount_dep, libglib_dep,
|
||||||
libgobject_dep, libgmodule_dep, selinux_dep, xattr_dep,
|
libgobject_dep, libgmodule_dep, selinux_dep, xattr_dep,
|
||||||
platform_deps, network_libs],
|
platform_deps, network_libs, libsysprof_capture_dep],
|
||||||
c_args : gio_c_args,
|
c_args : gio_c_args,
|
||||||
objc_args : gio_c_args,
|
objc_args : gio_c_args,
|
||||||
# intl.lib is not compatible with SAFESEH
|
# intl.lib is not compatible with SAFESEH
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
#include <sysprof-capture.h>
|
#include <sysprof-capture.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gmem.h"
|
#include "glib.h"
|
||||||
#include "gmacros.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -67,4 +66,15 @@ void (g_trace_mark) (gint64 begin_time_nsec,
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
guint (g_trace_define_int64_counter) (const char *group,
|
||||||
|
const char *name,
|
||||||
|
const char *description);
|
||||||
|
void (g_trace_set_int64_counter) (guint id,
|
||||||
|
gint64 value);
|
||||||
|
|
||||||
|
#ifndef HAVE_SYSPROF
|
||||||
|
#define g_trace_define_int64_counter(g, n, d) ((guint) -1)
|
||||||
|
#define g_trace_set_int64_counter(i,v)
|
||||||
|
#endif
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@ -96,3 +96,82 @@ void
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
#endif /* HAVE_SYSPROF */
|
#endif /* HAVE_SYSPROF */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* g_trace_define_int64_counter:
|
||||||
|
* @group: name of the group for categorising this counter
|
||||||
|
* @name: name of the counter
|
||||||
|
* @description: description for the counter
|
||||||
|
*
|
||||||
|
* Defines a new counter with integer values.
|
||||||
|
*
|
||||||
|
* The name should be unique within all counters defined with
|
||||||
|
* the same @group. The description will be shown in the sysprof UI.
|
||||||
|
*
|
||||||
|
* To add entries for this counter to a trace, use
|
||||||
|
* g_trace_set_int64_counter().
|
||||||
|
*
|
||||||
|
* Returns: ID of the counter, for use with g_trace_set_int64_counter(),
|
||||||
|
* guaranteed to never be zero
|
||||||
|
*
|
||||||
|
* Since: 2.68
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
(g_trace_define_int64_counter) (const char *group,
|
||||||
|
const char *name,
|
||||||
|
const char *description)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYSPROF
|
||||||
|
SysprofCaptureCounter counter;
|
||||||
|
|
||||||
|
counter.id = sysprof_collector_request_counters (1);
|
||||||
|
|
||||||
|
/* sysprof not enabled? */
|
||||||
|
if (counter.id == 0)
|
||||||
|
return (guint) -1;
|
||||||
|
|
||||||
|
counter.type = SYSPROF_CAPTURE_COUNTER_INT64;
|
||||||
|
counter.value.v64 = 0;
|
||||||
|
g_strlcpy (counter.category, group, sizeof counter.category);
|
||||||
|
g_strlcpy (counter.name, name, sizeof counter.name);
|
||||||
|
g_strlcpy (counter.description, description, sizeof counter.description);
|
||||||
|
|
||||||
|
sysprof_collector_define_counters (&counter, 1);
|
||||||
|
|
||||||
|
g_assert (counter.id != 0);
|
||||||
|
|
||||||
|
return counter.id;
|
||||||
|
#else
|
||||||
|
return (guint) -1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* g_trace_set_int64_counter:
|
||||||
|
* @id: ID of the counter
|
||||||
|
* @val: the value to set the counter to
|
||||||
|
*
|
||||||
|
* Adds a counter value to a trace.
|
||||||
|
*
|
||||||
|
* The ID must be obtained via g_trace_define_int64_counter()
|
||||||
|
* before using this function.
|
||||||
|
*
|
||||||
|
* Since: 2.68
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
(g_trace_set_int64_counter) (guint id,
|
||||||
|
gint64 val)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYSPROF
|
||||||
|
SysprofCaptureCounterValue value;
|
||||||
|
|
||||||
|
g_return_if_fail (id != 0);
|
||||||
|
|
||||||
|
/* Ignore setting the counter if we failed to define it in the first place. */
|
||||||
|
if (id == (guint) -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
value.v64 = val;
|
||||||
|
sysprof_collector_set_counters (&id, &value, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ if not use_system_pcre
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# libsysprof-capture support
|
# libsysprof-capture support
|
||||||
libsysprof_capture_dep = dependency('sysprof-capture-4',
|
libsysprof_capture_dep = dependency('sysprof-capture-4', version: '>= 3.38.0',
|
||||||
required: get_option('sysprof'),
|
required: get_option('sysprof'),
|
||||||
default_options: [
|
default_options: [
|
||||||
'enable_examples=false',
|
'enable_examples=false',
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[wrap-git]
|
[wrap-git]
|
||||||
directory=sysprof
|
directory=sysprof
|
||||||
url=https://gitlab.gnome.org/GNOME/sysprof.git
|
url=https://gitlab.gnome.org/GNOME/sysprof.git
|
||||||
revision=6b1cd7a722fcebae1ac392562c47957477ade8bf
|
revision=3.38.0
|
||||||
depth=1
|
depth=1
|
||||||
|
Loading…
Reference in New Issue
Block a user