2018-05-19 18:35:42 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
*
|
|
|
|
* gdkprofiler.c: A simple profiler
|
|
|
|
*
|
|
|
|
* Copyright © 2018 Matthias Clasen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
#include "gdkprofilerprivate.h"
|
|
|
|
|
2018-05-19 18:35:42 +00:00
|
|
|
#include <sys/types.h>
|
2020-01-29 15:55:44 +00:00
|
|
|
#include <signal.h>
|
2019-05-08 00:55:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2018-05-19 18:35:42 +00:00
|
|
|
#include <unistd.h>
|
2019-05-08 00:55:03 +00:00
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
|
2023-05-09 15:16:31 +00:00
|
|
|
#include "version/gdkversionmacros.h"
|
2018-05-19 18:35:42 +00:00
|
|
|
#include "gdkframeclockprivate.h"
|
|
|
|
|
2024-01-21 18:58:09 +00:00
|
|
|
#define CATEGORY "GTK"
|
2018-05-19 18:35:42 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_profiler_is_running (void)
|
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
|
|
|
return sysprof_collector_is_active ();
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_add_mark) (gint64 begin_time,
|
|
|
|
gint64 duration,
|
|
|
|
const char *name,
|
|
|
|
const char *message)
|
2018-05-19 18:35:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2024-01-21 18:58:09 +00:00
|
|
|
sysprof_collector_mark (begin_time, duration, CATEGORY, name, message);
|
2020-08-19 22:49:34 +00:00
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
void
|
|
|
|
(gdk_profiler_end_mark) (gint64 begin_time,
|
|
|
|
const char *name,
|
|
|
|
const char *message)
|
2020-02-12 10:25:34 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2024-01-21 18:58:09 +00:00
|
|
|
sysprof_collector_mark (begin_time, GDK_PROFILER_CURRENT_TIME - begin_time, CATEGORY, name, message);
|
2020-08-19 22:49:34 +00:00
|
|
|
#endif
|
2020-02-12 10:25:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:56:10 +00:00
|
|
|
void
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_add_markf) (gint64 begin_time,
|
|
|
|
gint64 duration,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *message_format,
|
|
|
|
...)
|
2020-02-12 08:56:10 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2020-02-12 08:56:10 +00:00
|
|
|
va_list args;
|
2020-08-19 22:49:34 +00:00
|
|
|
va_start (args, message_format);
|
2024-01-21 18:58:09 +00:00
|
|
|
sysprof_collector_mark_vprintf (begin_time, duration, CATEGORY, name, message_format, args);
|
2020-02-12 08:56:10 +00:00
|
|
|
va_end (args);
|
2020-08-19 22:49:34 +00:00
|
|
|
#endif /* HAVE_SYSPROF */
|
2020-02-12 10:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_end_markf) (gint64 begin_time,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *message_format,
|
|
|
|
...)
|
2020-02-12 10:25:34 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2020-02-12 10:25:34 +00:00
|
|
|
va_list args;
|
2020-08-19 22:49:34 +00:00
|
|
|
va_start (args, message_format);
|
2024-01-21 18:58:09 +00:00
|
|
|
sysprof_collector_mark_vprintf (begin_time, GDK_PROFILER_CURRENT_TIME - begin_time, CATEGORY, name, message_format, args);
|
2020-02-12 10:25:34 +00:00
|
|
|
va_end (args);
|
2020-08-19 22:49:34 +00:00
|
|
|
#endif /* HAVE_SYSPROF */
|
2020-02-12 10:25:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
guint
|
|
|
|
(gdk_profiler_define_counter) (const char *name,
|
|
|
|
const char *description)
|
2018-05-19 18:35:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2019-05-30 02:02:30 +00:00
|
|
|
SysprofCaptureCounter counter;
|
2018-05-19 18:35:42 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
counter.id = sysprof_collector_request_counters (1);
|
|
|
|
counter.type = SYSPROF_CAPTURE_COUNTER_DOUBLE;
|
|
|
|
counter.value.vdbl = 0.0;
|
2024-01-21 18:58:09 +00:00
|
|
|
g_strlcpy (counter.category, CATEGORY, sizeof counter.category);
|
2018-05-19 18:35:42 +00:00
|
|
|
g_strlcpy (counter.name, name, sizeof counter.name);
|
|
|
|
g_strlcpy (counter.description, description, sizeof counter.name);
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
sysprof_collector_define_counters (&counter, 1);
|
2018-05-19 18:35:42 +00:00
|
|
|
|
|
|
|
return counter.id;
|
2020-08-19 22:49:34 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_define_int_counter) (const char *name,
|
|
|
|
const char *description)
|
2018-05-19 18:35:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
|
|
|
SysprofCaptureCounter counter;
|
2018-05-19 18:35:42 +00:00
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
counter.id = sysprof_collector_request_counters (1);
|
|
|
|
counter.type = SYSPROF_CAPTURE_COUNTER_INT64;
|
|
|
|
counter.value.v64 = 0;
|
2024-01-21 18:58:09 +00:00
|
|
|
g_strlcpy (counter.category, CATEGORY, sizeof counter.category);
|
2020-08-19 22:49:34 +00:00
|
|
|
g_strlcpy (counter.name, name, sizeof counter.name);
|
|
|
|
g_strlcpy (counter.description, description, sizeof counter.name);
|
|
|
|
|
|
|
|
sysprof_collector_define_counters (&counter, 1);
|
|
|
|
|
|
|
|
return counter.id;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_set_counter) (guint id,
|
|
|
|
double val)
|
2018-05-19 18:35:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2019-05-30 02:02:30 +00:00
|
|
|
SysprofCaptureCounterValue value;
|
2018-05-19 18:35:42 +00:00
|
|
|
|
|
|
|
value.vdbl = val;
|
2020-08-19 22:49:34 +00:00
|
|
|
sysprof_collector_set_counters (&id, &value, 1);
|
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-19 22:49:34 +00:00
|
|
|
(gdk_profiler_set_int_counter) (guint id,
|
|
|
|
gint64 val)
|
2018-05-19 18:35:42 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
#ifdef HAVE_SYSPROF
|
2019-05-30 02:02:30 +00:00
|
|
|
SysprofCaptureCounterValue value;
|
2018-05-19 18:35:42 +00:00
|
|
|
|
|
|
|
value.v64 = val;
|
2020-08-19 22:49:34 +00:00
|
|
|
sysprof_collector_set_counters (&id, &value, 1);
|
|
|
|
#endif
|
2018-05-19 18:35:42 +00:00
|
|
|
}
|