GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 11 / 0 / 11
Functions: 100.0% 1 / 0 / 1
Branches: 83.3% 5 / 0 / 6

shumate/shumate-profiling-private.h
Line Branch Exec Source
1 /*
2 * Copyright (C) 2023 James Westman <james@jwestman.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
16 */
17
18
19 #pragma once
20
21
22 #if SHUMATE_HAS_SYSPROF
23
24 #include <sysprof-capture.h>
25
26 #define SHUMATE_PROFILE_CURRENT_TIME SYSPROF_CAPTURE_CURRENT_TIME
27
28 typedef struct {
29 gint64 begin;
30 char *name;
31 gboolean exited : 1;
32 gboolean free_name : 1;
33 } ShumateProfileScope;
34
35 static inline void
36 26 shumate_profile_scope_end_with_desc (ShumateProfileScope *self,
37 const char *desc)
38 {
39
2/2
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 9 taken 10 times.
26 if (self->exited)
40 return;
41
42 16 self->exited = TRUE;
43
44 32 sysprof_collector_mark (self->begin,
45 16 SYSPROF_CAPTURE_CURRENT_TIME - self->begin,
46 "shumate",
47 16 self->name,
48 desc);
49
50
2/2
✓ Branch 5 → 6 taken 8 times.
✓ Branch 5 → 9 taken 8 times.
16 if (self->free_name)
51
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 8 times.
8 g_free (self->name);
52 }
53
54 static inline void
55 16 shumate_profile_scope_end (ShumateProfileScope *self)
56 {
57 16 shumate_profile_scope_end_with_desc (self, NULL);
58 }
59
60 16 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ShumateProfileScope, shumate_profile_scope_end)
61
62 #define SHUMATE_PROFILE_COLLECT(begin, name, desc) \
63 sysprof_collector_mark (begin, \
64 SYSPROF_CAPTURE_CURRENT_TIME - begin, \
65 "shumate", \
66 name, \
67 desc);
68
69 #define SHUMATE_PROFILE_START() \
70 G_GNUC_UNUSED g_auto(ShumateProfileScope) __profile_scope = { \
71 .begin = SYSPROF_CAPTURE_CURRENT_TIME, \
72 .name = ((char *)__PRETTY_FUNCTION__), \
73 .free_name = FALSE, \
74 .exited = FALSE, \
75 }
76
77 #define SHUMATE_PROFILE_START_NAMED(var_name) \
78 G_GNUC_UNUSED g_auto(ShumateProfileScope) __profile_scope_##var_name = { \
79 .begin = SYSPROF_CAPTURE_CURRENT_TIME, \
80 .name = g_strdup_printf ("%s -- %s", __FUNCTION__, G_STRINGIFY (var_name)), \
81 .free_name = TRUE, \
82 .exited = FALSE, \
83 }
84
85 #define SHUMATE_PROFILE_END(desc) \
86 shumate_profile_scope_end_with_desc (&__profile_scope, desc)
87
88 #define SHUMATE_PROFILE_END_NAMED(var_name, desc) \
89 shumate_profile_scope_end_with_desc (&__profile_scope_##var_name, desc)
90
91 #else
92
93 #define SHUMATE_PROFILE_CURRENT_TIME ((gint64) -1)
94
95 #define SHUMATE_PROFILE_COLLECT(begin, name, desc)
96 #define SHUMATE_PROFILE_START()
97 #define SHUMATE_PROFILE_START_NAMED(var_name)
98 #define SHUMATE_PROFILE_END(desc)
99 #define SHUMATE_PROFILE_END_NAMED(var_name, desc)
100
101 #endif
102
103