1/* GDK - The GIMP Drawing Kit
2 *
3 * gdkprofiler.c: A simple profiler
4 *
5 * Copyright © 2018 Matthias Clasen
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "config.h"
22
23#include "gdkprofilerprivate.h"
24
25#include <sys/types.h>
26#include <signal.h>
27
28#ifdef HAVE_UNISTD_H
29#include <unistd.h>
30#endif
31
32#include "gdkversionmacros.h"
33#include "gdkframeclockprivate.h"
34
35
36gboolean
37gdk_profiler_is_running (void)
38{
39#ifdef HAVE_SYSPROF
40 return sysprof_collector_is_active ();
41#else
42 return FALSE;
43#endif
44}
45
46void
47(gdk_profiler_add_mark) (gint64 begin_time,
48 gint64 duration,
49 const char *name,
50 const char *message)
51{
52#ifdef HAVE_SYSPROF
53 sysprof_collector_mark (begin_time, duration, "gtk", name, message);
54#endif
55}
56
57void
58(gdk_profiler_end_mark) (gint64 begin_time,
59 const char *name,
60 const char *message)
61{
62#ifdef HAVE_SYSPROF
63 sysprof_collector_mark (begin_time, GDK_PROFILER_CURRENT_TIME - begin_time, "gtk", name, message);
64#endif
65}
66
67void
68(gdk_profiler_add_markf) (gint64 begin_time,
69 gint64 duration,
70 const gchar *name,
71 const gchar *message_format,
72 ...)
73{
74#ifdef HAVE_SYSPROF
75 va_list args;
76 va_start (args, message_format);
77 sysprof_collector_mark_vprintf (begin_time, duration, "gtk", name, message_format, args);
78 va_end (args);
79#endif /* HAVE_SYSPROF */
80}
81
82void
83(gdk_profiler_end_markf) (gint64 begin_time,
84 const gchar *name,
85 const gchar *message_format,
86 ...)
87{
88#ifdef HAVE_SYSPROF
89 va_list args;
90 va_start (args, message_format);
91 sysprof_collector_mark_vprintf (begin_time, GDK_PROFILER_CURRENT_TIME - begin_time, "gtk", name, message_format, args);
92 va_end (args);
93#endif /* HAVE_SYSPROF */
94}
95
96guint
97(gdk_profiler_define_counter) (const char *name,
98 const char *description)
99{
100#ifdef HAVE_SYSPROF
101 SysprofCaptureCounter counter;
102
103 counter.id = sysprof_collector_request_counters (1);
104 counter.type = SYSPROF_CAPTURE_COUNTER_DOUBLE;
105 counter.value.vdbl = 0.0;
106 g_strlcpy (counter.category, "gtk", sizeof counter.category);
107 g_strlcpy (counter.name, name, sizeof counter.name);
108 g_strlcpy (counter.description, description, sizeof counter.name);
109
110 sysprof_collector_define_counters (&counter, 1);
111
112 return counter.id;
113#else
114 return 0;
115#endif
116}
117
118guint
119(gdk_profiler_define_int_counter) (const char *name,
120 const char *description)
121{
122#ifdef HAVE_SYSPROF
123 SysprofCaptureCounter counter;
124
125 counter.id = sysprof_collector_request_counters (1);
126 counter.type = SYSPROF_CAPTURE_COUNTER_INT64;
127 counter.value.v64 = 0;
128 g_strlcpy (counter.category, "gtk", sizeof counter.category);
129 g_strlcpy (counter.name, name, sizeof counter.name);
130 g_strlcpy (counter.description, description, sizeof counter.name);
131
132 sysprof_collector_define_counters (&counter, 1);
133
134 return counter.id;
135#else
136 return 0;
137#endif
138}
139
140void
141(gdk_profiler_set_counter) (guint id,
142 double val)
143{
144#ifdef HAVE_SYSPROF
145 SysprofCaptureCounterValue value;
146
147 value.vdbl = val;
148 sysprof_collector_set_counters (&id, &value, 1);
149#endif
150}
151
152void
153(gdk_profiler_set_int_counter) (guint id,
154 gint64 val)
155{
156#ifdef HAVE_SYSPROF
157 SysprofCaptureCounterValue value;
158
159 value.v64 = val;
160 sysprof_collector_set_counters (&id, &value, 1);
161#endif
162}
163

source code of gtk/gdk/gdkprofiler.c