revision: use generation for A..B --topo-order queries
[git.git] / trace2 / tr2_tls.h
blobb1e327a928e2ba084714770c85c15a219dab35f3
1 #ifndef TR2_TLS_H
2 #define TR2_TLS_H
4 #include "strbuf.h"
6 /*
7 * Arbitry limit for thread names for column alignment.
8 */
9 #define TR2_MAX_THREAD_NAME (24)
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;
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.
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.
28 * Truncate the thread name if necessary to help with column alignment
29 * in printf-style messages.
31 * In this and all following functions the term "self" refers to the
32 * current thread.
34 struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,
35 uint64_t us_thread_start);
38 * Get our TLS data.
40 struct tr2tls_thread_ctx *tr2tls_get_self(void);
43 * return true if the current thread is the main thread.
45 int tr2tls_is_main_thread(void);
48 * Free our TLS data.
50 void tr2tls_unset_self(void);
53 * Begin a new nested region and remember the start time.
55 void tr2tls_push_self(uint64_t us_now);
58 * End the innermost nested region.
60 void tr2tls_pop_self(void);
63 * Pop any extra (above the first) open regions on the current
64 * thread and discard. During a thread-exit, we should only
65 * have region[0] that was pushed in trace2_thread_start() if
66 * the thread exits normally.
68 void tr2tls_pop_unwind_self(void);
71 * Compute the elapsed time since the innermost region in the
72 * current thread started and the given time (usually now).
74 uint64_t tr2tls_region_elasped_self(uint64_t us);
77 * Compute the elapsed time since the main thread started
78 * and the given time (usually now). This is assumed to
79 * be the absolute run time of the process.
81 uint64_t tr2tls_absolute_elapsed(uint64_t us);
84 * Initialize the tr2 TLS system.
86 void tr2tls_init(void);
89 * Free all tr2 TLS resources.
91 void tr2tls_release(void);
94 * Protected increment of an integer.
96 int tr2tls_locked_increment(int *p);
99 * Capture the process start time and do nothing else.
101 void tr2tls_start_process_clock(void);
103 #endif /* TR2_TLS_H */