X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=include%2Flwt.h;h=085f6dd4031c88f67f9eb0fd8f8d65cb8d86b1bd;hp=789c66704c98f3c6602310d4300c284dd44f5858;hb=HEAD;hpb=4a7804bd08c790fc3c4233312e4b485c3302fe02 diff --git a/include/lwt.h b/include/lwt.h index 789c667..085f6dd 100644 --- a/include/lwt.h +++ b/include/lwt.h @@ -6,7 +6,6 @@ */ #ifndef LWT_H #define LWT_H -#include "tls.h" #ifndef ENABLE_TRACE #define TRACE(...) do { } while (0) @@ -14,25 +13,13 @@ #define TRACE(flag, format, v1, v2) lwt_trace(flag, format, (size_t)(v1), (size_t)(v2)) #endif -#define LWT_BUFFER_SCALE 16 -#define LWT_BUFFER_SIZE (1 << LWT_BUFFER_SCALE) -#define LWT_BUFFER_MASK (LWT_BUFFER_SIZE - 1) - -typedef struct lwt_record { - uint64_t timestamp; - const char *format; - size_t value1; - size_t value2; -} lwt_record_t; - -typedef struct lwt_buffer { - uint32_t head; - lwt_record_t x[0]; -} lwt_buffer_t; - -void lwt_init (void); -void lwt_thread_init (int thread_id); +#ifndef NDEBUG +#define ASSERT(x) do { if (!(x)) { lwt_halt(); assert(!#x); } } while (0) +#else +#define ASSERT(x) do { } while (0) +#endif +// Dump trace records to . The file should be post-processed with "sort" before viewing. void lwt_dump (const char *file_name) __attribute__ ((externally_visible)); // indicates what kind of trace messages should be included in the dump. is a sequence of letters @@ -47,18 +34,15 @@ void lwt_set_trace_level (const char *flags); // the dump. It is only included when its specified category is enabled at a trace level greater than or equal to // the one in . Categories are case sensitive. static inline void lwt_trace (const char *flag, const char *format, size_t value1, size_t value2) { - extern uint64_t flag_mask_; - if (EXPECT_FALSE(flag_mask_ & (1 << (flag[0] - 'A')))) { - LOCALIZE_THREAD_LOCAL(tb_, lwt_buffer_t *); - unsigned int u, l; - __asm__ __volatile__("rdtsc" : "=a" (l), "=d" (u)); - uint64_t timestamp = ((uint64_t)u << 32) | l; + extern char TraceLevel[256]; + if (EXPECT_FALSE(TraceLevel[(unsigned)flag[0]] >= flag[1])) { // embed in so we don't have to make the lwt_record_t any bigger than it already is - format = (const char *)((size_t)format | ((uint64_t)flag[0] << 56) | ((uint64_t)flag[1] << 48)); - lwt_record_t temp = { timestamp, format, value1, value2 }; - if (tb_) { - tb_->x[tb_->head++ & LWT_BUFFER_MASK] = temp; - } + uint64_t f = ((uint64_t)(size_t)format | ((uint64_t)flag[0] << 56) | ((uint64_t)flag[1] << 48)); + extern void lwt_trace_i (uint64_t format, size_t value1, size_t value2); + lwt_trace_i(f, value1, value2); } } + +void lwt_halt (void); + #endif//LWT_H