]> git.ipfire.org Git - thirdparty/git.git/blob - trace2/tr2_tls.h
Merge branch 'jt/clone-server-option'
[thirdparty/git.git] / trace2 / tr2_tls.h
1 #ifndef TR2_TLS_H
2 #define TR2_TLS_H
3
4 #include "strbuf.h"
5
6 /*
7 * Arbitry limit for thread names for column alignment.
8 */
9 #define TR2_MAX_THREAD_NAME (24)
10
11 struct tr2tls_thread_ctx {
12 struct strbuf thread_name;
13 uint64_t *array_us_start;
14 int alloc;
15 int nr_open_regions; /* plays role of "nr" in ALLOC_GROW */
16 int thread_id;
17 };
18
19 /*
20 * Create TLS data for the current thread. This gives us a place to
21 * put per-thread data, such as thread start time, function nesting
22 * and a per-thread label for our messages.
23 *
24 * We assume the first thread is "main". Other threads are given
25 * non-zero thread-ids to help distinguish messages from concurrent
26 * threads.
27 *
28 * Truncate the thread name if necessary to help with column alignment
29 * in printf-style messages.
30 *
31 * In this and all following functions the term "self" refers to the
32 * current thread.
33 */
34 struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);
35
36 /*
37 * Get our TLS data.
38 */
39 struct tr2tls_thread_ctx *tr2tls_get_self(void);
40
41 /*
42 * return true if the current thread is the main thread.
43 */
44 int tr2tls_is_main_thread(void);
45
46 /*
47 * Free our TLS data.
48 */
49 void tr2tls_unset_self(void);
50
51 /*
52 * Begin a new nested region and remember the start time.
53 */
54 void tr2tls_push_self(uint64_t us_now);
55
56 /*
57 * End the innermost nested region.
58 */
59 void tr2tls_pop_self(void);
60
61 /*
62 * Pop any extra (above the first) open regions on the current
63 * thread and discard. During a thread-exit, we should only
64 * have region[0] that was pushed in trace2_thread_start() if
65 * the thread exits normally.
66 */
67 void tr2tls_pop_unwind_self(void);
68
69 /*
70 * Compute the elapsed time since the innermost region in the
71 * current thread started and the given time (usually now).
72 */
73 uint64_t tr2tls_region_elasped_self(uint64_t us);
74
75 /*
76 * Compute the elapsed time since the main thread started
77 * and the given time (usually now). This is assumed to
78 * be the absolute run time of the process.
79 */
80 uint64_t tr2tls_absolute_elapsed(uint64_t us);
81
82 /*
83 * Initialize the tr2 TLS system.
84 */
85 void tr2tls_init(void);
86
87 /*
88 * Free all tr2 TLS resources.
89 */
90 void tr2tls_release(void);
91
92 /*
93 * Protected increment of an integer.
94 */
95 int tr2tls_locked_increment(int *p);
96
97 #endif /* TR2_TLS_H */