1 | /** @file
|
---|
2 | * IPRT - Tracing.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_trace_h
|
---|
27 | #define ___iprt_trace_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 | #include <iprt/stdarg.h>
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_trace RTTrace - Tracing
|
---|
36 | * @ingroup grp_rt
|
---|
37 | *
|
---|
38 | * The tracing facility is somewhat similar to a stripped down logger that
|
---|
39 | * outputs to a circular buffer. Part of the idea here is that it can the
|
---|
40 | * overhead is much smaller and that it can be done without involving any
|
---|
41 | * locking or other thing that could throw off timing.
|
---|
42 | *
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 |
|
---|
47 | #ifdef DOXYGEN_RUNNING
|
---|
48 | # define RTTRACE_DISABLED
|
---|
49 | # define RTTRACE_ENABLED
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | /** @def RTTRACE_DISABLED
|
---|
53 | * Use this compile time define to disable all tracing macros. This trumps
|
---|
54 | * RTTRACE_ENABLED.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /** @def RTTRACE_ENABLED
|
---|
58 | * Use this compile time define to enable tracing when not in debug mode
|
---|
59 | */
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * Determine whether tracing is enabled and forcefully normalize the indicators.
|
---|
63 | */
|
---|
64 | #if (defined(DEBUG) || defined(RTTRACE_ENABLED)) && !defined(RTTRACE_DISABLED)
|
---|
65 | # undef RTTRACE_DISABLED
|
---|
66 | # undef RTTRACE_ENABLED
|
---|
67 | # define RTTRACE_ENABLED
|
---|
68 | #else
|
---|
69 | # undef RTTRACE_DISABLED
|
---|
70 | # undef RTTRACE_ENABLED
|
---|
71 | # define RTTRACE_DISABLED
|
---|
72 | #endif
|
---|
73 |
|
---|
74 |
|
---|
75 | /** @name RTTRACEBUF_FLAGS_XXX - RTTraceBufCarve and RTTraceBufCreate flags.
|
---|
76 | * @{ */
|
---|
77 | /** Free the memory block on release using RTMemFree(). */
|
---|
78 | #define RTTRACEBUF_FLAGS_FREE_ME RT_BIT_32(0)
|
---|
79 | /** Mask of the valid flags. */
|
---|
80 | #define RTTRACEBUF_FLAGS_MASK UINT32_C(0x00000001)
|
---|
81 | /** @} */
|
---|
82 |
|
---|
83 |
|
---|
84 | RTDECL(int) RTTraceBufCreate(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags);
|
---|
85 | RTDECL(int) RTTraceBufCarve(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags,
|
---|
86 | void *pvBlock, size_t *pcbBlock);
|
---|
87 | RTDECL(uint32_t) RTTraceBufRetain(RTTRACEBUF hTraceBuf);
|
---|
88 | RTDECL(uint32_t) RTTraceBufRelease(RTTRACEBUF hTraceBuf);
|
---|
89 | RTDECL(int) RTTraceBufDumpToLog(RTTRACEBUF hTraceBuf);
|
---|
90 | RTDECL(int) RTTraceBufDumpToAssert(RTTRACEBUF hTraceBuf);
|
---|
91 |
|
---|
92 | RTDECL(int) RTTraceBufAddMsg( RTTRACEBUF hTraceBuf, const char *pszMsg);
|
---|
93 | RTDECL(int) RTTraceBufAddMsgF( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, ...);
|
---|
94 | RTDECL(int) RTTraceBufAddMsgV( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, va_list va);
|
---|
95 | RTDECL(int) RTTraceBufAddMsgEx( RTTRACEBUF hTraceBuf, const char *pszMsg, size_t cbMaxMsg);
|
---|
96 |
|
---|
97 | RTDECL(int) RTTraceBufAddPos( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL);
|
---|
98 | RTDECL(int) RTTraceBufAddPosMsg( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg);
|
---|
99 | RTDECL(int) RTTraceBufAddPosMsgEx( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg, size_t cbMaxMsg);
|
---|
100 | RTDECL(int) RTTraceBufAddPosMsgF( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, ...);
|
---|
101 | RTDECL(int) RTTraceBufAddPosMsgV( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, va_list va);
|
---|
102 |
|
---|
103 |
|
---|
104 | RTDECL(int) RTTraceSetDefaultBuf(RTTRACEBUF hTraceBuf);
|
---|
105 | RTDECL(RTTRACEBUF) RTTraceGetDefaultBuf(void);
|
---|
106 |
|
---|
107 |
|
---|
108 | /** @def RTTRACE_BUF
|
---|
109 | * The trace buffer used by the macros.
|
---|
110 | */
|
---|
111 | #ifndef RTTRACE_BUF
|
---|
112 | # define RTTRACE_BUF NULL
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Record the current source position.
|
---|
117 | */
|
---|
118 | #ifdef RTTRACE_ENABLED
|
---|
119 | # define RTTRACE_POS() do { RTTraceBufAddPos(RTTRACE_BUF, RT_SRC_POS); } while (0)
|
---|
120 | #else
|
---|
121 | # define RTTRACE_POS() do { } while (0)
|
---|
122 | #endif
|
---|
123 |
|
---|
124 |
|
---|
125 | /** @} */
|
---|
126 |
|
---|
127 | RT_C_DECLS_END
|
---|
128 |
|
---|
129 | #endif
|
---|
130 |
|
---|
131 |
|
---|