2018-05-15 11:31:29 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COGL_TRACE_H
|
|
|
|
#define COGL_TRACE_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2020-02-17 12:32:35 -05:00
|
|
|
#include "cogl/cogl-defines.h"
|
|
|
|
#include "cogl/cogl-macros.h"
|
2018-05-15 11:31:29 -04:00
|
|
|
|
2020-02-17 12:32:35 -05:00
|
|
|
#ifdef COGL_HAS_TRACING
|
|
|
|
|
|
|
|
typedef struct _CoglTraceContext CoglTraceContext;
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
typedef struct _CoglTraceHead
|
|
|
|
{
|
2020-02-17 12:32:35 -05:00
|
|
|
uint64_t begin_time;
|
2018-05-15 11:31:29 -04:00
|
|
|
const char *name;
|
|
|
|
} CoglTraceHead;
|
|
|
|
|
2019-11-21 06:15:22 -05:00
|
|
|
COGL_EXPORT
|
|
|
|
GPrivate cogl_trace_thread_data;
|
|
|
|
COGL_EXPORT
|
|
|
|
CoglTraceContext *cogl_trace_context;
|
|
|
|
COGL_EXPORT
|
|
|
|
GMutex cogl_trace_mutex;
|
|
|
|
|
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_enabled_on_thread_with_fd (GMainContext *main_context,
|
|
|
|
const char *group,
|
|
|
|
int fd);
|
|
|
|
|
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
|
|
|
|
const char *group,
|
|
|
|
const char *filename);
|
|
|
|
|
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_disabled_on_thread (GMainContext *main_context);
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
cogl_trace_begin (CoglTraceHead *head,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
head->begin_time = g_get_monotonic_time () * 1000;
|
|
|
|
head->name = name;
|
|
|
|
}
|
|
|
|
|
2019-11-21 06:15:22 -05:00
|
|
|
COGL_EXPORT void
|
2020-02-17 12:32:35 -05:00
|
|
|
cogl_trace_end (CoglTraceHead *head);
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
cogl_auto_trace_end_helper (CoglTraceHead **head)
|
|
|
|
{
|
|
|
|
if (*head)
|
|
|
|
cogl_trace_end (*head);
|
|
|
|
}
|
|
|
|
|
2019-04-12 16:19:31 -04:00
|
|
|
#define COGL_TRACE_BEGIN(Name, description) \
|
2018-05-15 11:31:29 -04:00
|
|
|
CoglTraceHead CoglTrace##Name = { 0 }; \
|
|
|
|
if (g_private_get (&cogl_trace_thread_data)) \
|
2019-04-12 16:19:31 -04:00
|
|
|
cogl_trace_begin (&CoglTrace##Name, description); \
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
#define COGL_TRACE_END(Name)\
|
|
|
|
if (g_private_get (&cogl_trace_thread_data)) \
|
|
|
|
cogl_trace_end (&CoglTrace##Name);
|
|
|
|
|
2019-04-12 16:19:31 -04:00
|
|
|
#define COGL_TRACE_BEGIN_SCOPED(Name, description) \
|
2018-05-15 11:31:29 -04:00
|
|
|
CoglTraceHead CoglTrace##Name = { 0 }; \
|
|
|
|
__attribute__((cleanup (cogl_auto_trace_end_helper))) \
|
|
|
|
CoglTraceHead *ScopedCoglTrace##Name = NULL; \
|
|
|
|
if (g_private_get (&cogl_trace_thread_data)) \
|
|
|
|
{ \
|
2019-04-12 16:19:31 -04:00
|
|
|
cogl_trace_begin (&CoglTrace##Name, description); \
|
2018-05-15 11:31:29 -04:00
|
|
|
ScopedCoglTrace##Name = &CoglTrace##Name; \
|
|
|
|
}
|
|
|
|
|
2020-02-17 12:32:35 -05:00
|
|
|
#else /* COGL_HAS_TRACING */
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-04-12 16:19:31 -04:00
|
|
|
#define COGL_TRACE_BEGIN(Name, description) (void) 0
|
2018-05-15 11:31:29 -04:00
|
|
|
#define COGL_TRACE_END(Name) (void) 0
|
2019-04-12 16:19:31 -04:00
|
|
|
#define COGL_TRACE_BEGIN_SCOPED(Name, description) (void) 0
|
2018-05-15 11:31:29 -04:00
|
|
|
|
2019-11-21 06:15:22 -05:00
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_enabled_on_thread_with_fd (void *data,
|
|
|
|
const char *group,
|
|
|
|
int fd);
|
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_enabled_on_thread (void *data,
|
|
|
|
const char *group,
|
|
|
|
const char *filename);
|
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_set_tracing_disabled_on_thread (void *data);
|
2018-05-15 11:31:29 -04:00
|
|
|
|
2020-02-17 12:32:35 -05:00
|
|
|
#endif /* COGL_HAS_TRACING */
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
#endif /* COGL_TRACE_H */
|