7 * Arbitry limit for thread names for column alignment.
9 #define TR2_MAX_THREAD_NAME (24)
11 struct tr2tls_thread_ctx {
12 struct strbuf thread_name;
13 uint64_t *array_us_start;
15 int nr_open_regions; /* plays role of "nr" in ALLOC_GROW */
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
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
34 struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name);
39 struct tr2tls_thread_ctx *tr2tls_get_self(void);
42 * return true if the current thread is the main thread.
44 int tr2tls_is_main_thread(void);
49 void tr2tls_unset_self(void);
52 * Begin a new nested region and remember the start time.
54 void tr2tls_push_self(uint64_t us_now);
57 * End the innermost nested region.
59 void tr2tls_pop_self(void);
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.
67 void tr2tls_pop_unwind_self(void);
70 * Compute the elapsed time since the innermost region in the
71 * current thread started and the given time (usually now).
73 uint64_t tr2tls_region_elasped_self(uint64_t us);
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.
80 uint64_t tr2tls_absolute_elapsed(uint64_t us);
83 * Initialize the tr2 TLS system.
85 void tr2tls_init(void);
88 * Free all tr2 TLS resources.
90 void tr2tls_release(void);
93 * Protected increment of an integer.
95 int tr2tls_locked_increment(int *p);
97 #endif /* TR2_TLS_H */