2018-05-15 11:31:29 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Red Hat, Inc.
|
|
|
|
*
|
2021-01-28 12:05:25 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2018-05-15 11:31:29 -04:00
|
|
|
*
|
2021-01-28 12:05:25 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2018-05-15 11:31:29 -04:00
|
|
|
*
|
2021-01-28 12:05:25 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
2018-05-15 11:31:29 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
2021-02-02 17:30:53 -05:00
|
|
|
char *description;
|
2018-05-15 11:31:29 -04:00
|
|
|
} 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
|
|
|
|
2021-02-02 17:30:53 -05:00
|
|
|
COGL_EXPORT void
|
|
|
|
cogl_trace_describe (CoglTraceHead *head,
|
|
|
|
const char *description);
|
|
|
|
|
2018-05-15 11:31:29 -04:00
|
|
|
static inline void
|
|
|
|
cogl_auto_trace_end_helper (CoglTraceHead **head)
|
|
|
|
{
|
|
|
|
if (*head)
|
|
|
|
cogl_trace_end (*head);
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:56:57 -05:00
|
|
|
static inline gboolean
|
|
|
|
cogl_is_tracing_enabled (void)
|
|
|
|
{
|
|
|
|
return !!g_private_get (&cogl_trace_thread_data);
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:28:01 -05:00
|
|
|
#define COGL_TRACE_BEGIN(Name, name) \
|
2018-05-15 11:31:29 -04:00
|
|
|
CoglTraceHead CoglTrace##Name = { 0 }; \
|
2021-02-02 17:56:57 -05:00
|
|
|
if (cogl_is_tracing_enabled ()) \
|
2021-02-02 17:28:01 -05:00
|
|
|
cogl_trace_begin (&CoglTrace##Name, name); \
|
2018-05-15 11:31:29 -04:00
|
|
|
|
|
|
|
#define COGL_TRACE_END(Name)\
|
2021-02-02 17:56:57 -05:00
|
|
|
if (cogl_is_tracing_enabled ()) \
|
2018-05-15 11:31:29 -04:00
|
|
|
cogl_trace_end (&CoglTrace##Name);
|
|
|
|
|
2021-02-02 17:28:01 -05:00
|
|
|
#define COGL_TRACE_BEGIN_SCOPED(Name, name) \
|
2018-05-15 11:31:29 -04:00
|
|
|
CoglTraceHead CoglTrace##Name = { 0 }; \
|
|
|
|
__attribute__((cleanup (cogl_auto_trace_end_helper))) \
|
|
|
|
CoglTraceHead *ScopedCoglTrace##Name = NULL; \
|
2021-02-02 17:56:57 -05:00
|
|
|
if (cogl_is_tracing_enabled ()) \
|
2018-05-15 11:31:29 -04:00
|
|
|
{ \
|
2021-02-02 17:28:01 -05:00
|
|
|
cogl_trace_begin (&CoglTrace##Name, name); \
|
2018-05-15 11:31:29 -04:00
|
|
|
ScopedCoglTrace##Name = &CoglTrace##Name; \
|
|
|
|
}
|
|
|
|
|
2021-02-02 17:30:53 -05:00
|
|
|
#define COGL_TRACE_DESCRIBE(Name, description)\
|
2021-02-02 17:56:57 -05:00
|
|
|
if (cogl_is_tracing_enabled ()) \
|
2021-02-02 17:30:53 -05:00
|
|
|
cogl_trace_describe (&CoglTrace##Name, description);
|
|
|
|
|
2021-02-02 17:32:27 -05:00
|
|
|
#define COGL_TRACE_SCOPED_ANCHOR(Name) \
|
|
|
|
CoglTraceHead G_GNUC_UNUSED CoglTrace##Name = { 0 }; \
|
|
|
|
__attribute__((cleanup (cogl_auto_trace_end_helper))) \
|
|
|
|
CoglTraceHead *ScopedCoglTrace##Name = NULL; \
|
|
|
|
|
|
|
|
#define COGL_TRACE_BEGIN_ANCHORED(Name, name) \
|
2021-02-02 17:56:57 -05:00
|
|
|
if (cogl_is_tracing_enabled ()) \
|
2021-02-02 17:32:27 -05:00
|
|
|
{ \
|
|
|
|
cogl_trace_begin (&CoglTrace##Name, name); \
|
|
|
|
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>
|
|
|
|
|
2021-02-02 17:28:01 -05:00
|
|
|
#define COGL_TRACE_BEGIN(Name, name) (void) 0
|
2018-05-15 11:31:29 -04:00
|
|
|
#define COGL_TRACE_END(Name) (void) 0
|
2021-02-02 17:28:01 -05:00
|
|
|
#define COGL_TRACE_BEGIN_SCOPED(Name, name) (void) 0
|
2021-02-02 17:30:53 -05:00
|
|
|
#define COGL_TRACE_DESCRIBE(Name, description) (void) 0
|
2021-02-02 17:32:27 -05:00
|
|
|
#define COGL_TRACE_ANCHOR(Name) (void) 0
|
|
|
|
#define COGL_TRACE_BEGIN_ANCHORED(Name, name) (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 */
|