Debian Codegraph @

src/dex-profiler.h

raw symbols SCIP
1 /* dex-profiler.h
2 *
3 * Copyright 2022 Christian Hergert <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: LGPL-2.1-or-later
19 */
20
21 #pragma once
22
23 #include <glib.h>
24
25 #ifndef PACKAGE_VERSION
26 # error "config.h was not included before dex-profiler.h."
27 #endif
28
29 #ifdef HAVE_SYSPROF
30 # include <sysprof-capture.h>
31 #endif
32
33 G_BEGIN_DECLS
34
35 #ifdef HAVE_SYSPROF
36 # define DEX_PROFILER_ENABLED 1
37 # define DEX_PROFILER_CURRENT_TIME SYSPROF_CAPTURE_CURRENT_TIME
38 # define DEX_PROFILER_ACTIVE (sysprof_collector_is_active())
39 # define DEX_PROFILER_BEGIN_MARK \
40 G_STMT_START { \
41 gint64 __begin_time = SYSPROF_CAPTURE_CURRENT_TIME;
42 # define DEX_PROFILER_END_MARK(name, message) \
43 G_STMT_START { \
44 gint64 __duration = SYSPROF_CAPTURE_CURRENT_TIME - __begin_time; \
45 sysprof_collector_mark (__begin_time, __duration, "libdex", name, message); \
46 } G_STMT_END; \
47 } G_STMT_END
48 # define DEX_PROFILER_MARK(duration, name, message) \
49 G_STMT_START { \
50 sysprof_collector_mark (SYSPROF_CAPTURE_CURRENT_TIME - (duration), \
51 (duration), "libdex", name, message); \
52 } G_STMT_END
53 # define DEX_PROFILER_MARK_AT_TIME(begin_time, duration, name, message) \
54 G_STMT_START { \
55 sysprof_collector_mark ((begin_time), (duration), "libdex", name, message); \
56 } G_STMT_END
57 # define DEX_PROFILER_LOG(format, ...) \
58 G_STMT_START { \
59 if (DEX_PROFILER_ACTIVE) \
60 sysprof_collector_log_printf(G_LOG_LEVEL_DEBUG, G_LOG_DOMAIN, format, __VA_ARGS__); \
61 } G_STMT_END
62 #else
63 # undef DEX_PROFILER_ENABLED
64 # define DEX_PROFILER_ACTIVE (0)
65 # define DEX_PROFILER_CURRENT_TIME 0
66 # define DEX_PROFILER_MARK(duration, name, message) \
67 G_STMT_START { } G_STMT_END
68 # define DEX_PROFILER_MARK_AT_TIME(begin_time, duration, name, message) \
69 G_STMT_START { } G_STMT_END
70 # define DEX_PROFILER_BEGIN_MARK G_STMT_START {
71 # define DEX_PROFILER_END_MARK(name, message) (void)0; } G_STMT_END
72 # define DEX_PROFILER_LOG(format, ...) G_STMT_START { } G_STMT_END
73 #endif
74
75 G_END_DECLS