1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <stdio.h>
8 
9 // clang-format off
10 
11 // trace routines
12 #define TRACE_ENTRY printf("%s: entry\n", __PRETTY_FUNCTION__)
13 #define TRACE_EXIT printf("%s: exit\n", __PRETTY_FUNCTION__)
14 #define TRACE_ENTRY_OBJ printf("%s: entry obj %p\n", __PRETTY_FUNCTION__, this)
15 #define TRACE_EXIT_OBJ printf("%s: exit obj %p\n", __PRETTY_FUNCTION__, this)
16 #define TRACE printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__)
17 #define TRACEF(str, x...) do { printf("%s:%d: " str, __PRETTY_FUNCTION__, __LINE__, ## x); } while (0)
18 
19 // trace routines that work if LOCAL_TRACE is set
20 #define LTRACE_ENTRY do { if (LOCAL_TRACE) { TRACE_ENTRY; } } while (0)
21 #define LTRACE_EXIT do { if (LOCAL_TRACE) { TRACE_EXIT; } } while (0)
22 #define LTRACE_ENTRY_OBJ do { if (LOCAL_TRACE) { TRACE_ENTRY_OBJ; } } while (0)
23 #define LTRACE_EXIT_OBJ do { if (LOCAL_TRACE) { TRACE_EXIT_OBJ; } } while (0)
24 #define LTRACE do { if (LOCAL_TRACE) { TRACE; } } while (0)
25 #define LTRACE_DO(expr) do { if (LOCAL_TRACE) { expr; } } while (0)
26 #define LTRACEF(x...) do { if (LOCAL_TRACE) { TRACEF(x); } } while (0)
27 #define LTRACEF_LEVEL(level, x...) do { if (LOCAL_TRACE >= (level)) { TRACEF(x); } } while (0)
28 
29 // clang-format on
30