PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms


C Header | 48 lines | 24 code | 7 blank | 17 comment | 5 complexity | 3a4fdfceabeb626486edba8214c9a335 MD5 | raw file
Possible License(s): BSD-3-Clause
 2 * Written by Josh Dybnis and released to the public domain, as explained at
 3 *
 4 *
 5 * lightweight tracing
 6 */ 
 7#ifndef LWT_H
 8#define LWT_H
10#ifndef ENABLE_TRACE
11#define TRACE(...) do { } while (0)
13#define TRACE(flag, format, v1, v2) lwt_trace(flag, format, (size_t)(v1), (size_t)(v2))
16#ifndef NDEBUG
17#define ASSERT(x) do { if (!(x)) { lwt_halt(); assert(!#x); } } while (0)
19#define ASSERT(x) do { } while (0)
22// Dump trace records to <file_name>. The file should be post-processed with "sort" before viewing.
23void lwt_dump (const char *file_name) __attribute__ ((externally_visible));
25// <flags> indicates what kind of trace messages should be included in the dump. <flags> is a sequence of letters
26// followed by numbers (e.g. "x1c9n2g3"). The letters indicate trace categories and the numbers are trace levels 
27// for each category. If a category appears in <flags>, then messages from that category will be included in the
28// dump if they have a trace level less than or equal to the one specified in <flags>. Categories are case
29// sensitive.
30void lwt_set_trace_level (const char *flags);
32// <flag> is a two character string containing a letter followed by a number (e.g. "f3"). The letter indicates a
33// trace category, and the number a trace level. <flag> controls whether or not the trace message gets included in
34// the dump. It is only included when its specified category is enabled at a trace level greater than or equal to
35// the one in <flag>. Categories are case sensitive. 
36static inline void lwt_trace (const char *flag, const char *format, size_t value1, size_t value2) {
37    extern char flag_state_[256];
38    if (EXPECT_FALSE(flag_state_[(unsigned)flag[0]] >= flag[1])) {
39        // embed <flags> in <format> so we don't have to make the lwt_record_t any bigger than it already is
40        uint64_t f = ((uint64_t)(size_t)format | ((uint64_t)flag[0] << 56) | ((uint64_t)flag[1] << 48));
41        extern void lwt_trace_i (uint64_t format, size_t value1, size_t value2);
42        lwt_trace_i(f, value1, value2);
43    }
46void lwt_halt (void);