VirtualBox

source: vbox/trunk/include/iprt/trace.h@ 93483

Last change on this file since 93483 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/** @file
2 * IPRT - Tracing.
3 */
4
5/*
6 * Copyright (C) 2011-2022 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_INCLUDED_trace_h
27#define IPRT_INCLUDED_trace_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33#include <iprt/types.h>
34#include <iprt/stdarg.h>
35
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_rt_trace RTTrace - Tracing
39 * @ingroup grp_rt
40 *
41 * The tracing facility is somewhat similar to a stripped down logger that
42 * outputs to a circular buffer. Part of the idea here is that it can the
43 * overhead is much smaller and that it can be done without involving any
44 * locking or other thing that could throw off timing.
45 *
46 * @{
47 */
48
49
50#ifdef DOXYGEN_RUNNING
51# define RTTRACE_DISABLED
52# define RTTRACE_ENABLED
53#endif
54
55/** @def RTTRACE_DISABLED
56 * Use this compile time define to disable all tracing macros. This trumps
57 * RTTRACE_ENABLED.
58 */
59
60/** @def RTTRACE_ENABLED
61 * Use this compile time define to enable tracing when not in debug mode
62 */
63
64/*
65 * Determine whether tracing is enabled and forcefully normalize the indicators.
66 */
67#if (defined(DEBUG) || defined(RTTRACE_ENABLED)) && !defined(RTTRACE_DISABLED)
68# undef RTTRACE_DISABLED
69# undef RTTRACE_ENABLED
70# define RTTRACE_ENABLED
71#else
72# undef RTTRACE_DISABLED
73# undef RTTRACE_ENABLED
74# define RTTRACE_DISABLED
75#endif
76
77
78/** @name RTTRACEBUF_FLAGS_XXX - RTTraceBufCarve and RTTraceBufCreate flags.
79 * @{ */
80/** Free the memory block on release using RTMemFree(). */
81#define RTTRACEBUF_FLAGS_FREE_ME RT_BIT_32(0)
82/** Whether the trace buffer is disabled or enabled. */
83#define RTTRACEBUF_FLAGS_DISABLED RT_BIT_32(RTTRACEBUF_FLAGS_DISABLED_BIT)
84/** The bit number corresponding to the RTTRACEBUF_FLAGS_DISABLED mask. */
85#define RTTRACEBUF_FLAGS_DISABLED_BIT 1
86/** Mask of the valid flags. */
87#define RTTRACEBUF_FLAGS_MASK UINT32_C(0x00000003)
88/** @} */
89
90
91RTDECL(int) RTTraceBufCreate(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags);
92RTDECL(int) RTTraceBufCarve(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags,
93 void *pvBlock, size_t *pcbBlock);
94RTDECL(uint32_t) RTTraceBufRetain(RTTRACEBUF hTraceBuf);
95RTDECL(uint32_t) RTTraceBufRelease(RTTRACEBUF hTraceBuf);
96RTDECL(int) RTTraceBufDumpToLog(RTTRACEBUF hTraceBuf);
97RTDECL(int) RTTraceBufDumpToAssert(RTTRACEBUF hTraceBuf);
98
99/**
100 * Trace buffer callback for processing one entry.
101 *
102 * Used by RTTraceBufEnumEntries.
103 *
104 * @returns IPRT status code. Any status code but VINF_SUCCESS will abort the
105 * enumeration and be returned by RTTraceBufEnumEntries.
106 * @param hTraceBuf The trace buffer handle.
107 * @param iEntry The entry number.
108 * @param NanoTS The timestamp of the entry.
109 * @param idCpu The ID of the CPU which added the entry.
110 * @param pszMsg The message text.
111 * @param pvUser The user argument.
112 */
113typedef DECLCALLBACKTYPE(int, FNRTTRACEBUFCALLBACK,(RTTRACEBUF hTraceBuf, uint32_t iEntry, uint64_t NanoTS,
114 RTCPUID idCpu, const char *pszMsg, void *pvUser));
115/** Pointer to trace buffer enumeration callback function. */
116typedef FNRTTRACEBUFCALLBACK *PFNRTTRACEBUFCALLBACK;
117
118/**
119 * Enumerates the used trace buffer entries, calling @a pfnCallback for each.
120 *
121 * @returns IPRT status code. Should the callback (@a pfnCallback) return
122 * anything other than VINF_SUCCESS, then the enumeration will be
123 * aborted and the status code will be returned by this function.
124 * @retval VINF_SUCCESS
125 * @retval VERR_INVALID_HANDLE
126 * @retval VERR_INVALID_PARAMETER
127 * @retval VERR_INVALID_POINTER
128 *
129 * @param hTraceBuf The trace buffer handle. Special handles are
130 * accepted.
131 * @param pfnCallback The callback to call for each entry.
132 * @param pvUser The user argument for the callback.
133 */
134RTDECL(int) RTTraceBufEnumEntries(RTTRACEBUF hTraceBuf, PFNRTTRACEBUFCALLBACK pfnCallback, void *pvUser);
135
136/**
137 * Gets the entry size used by the specified trace buffer.
138 *
139 * @returns The size on success, 0 if the handle is invalid.
140 *
141 * @param hTraceBuf The trace buffer handle. Special handles are
142 * accepted.
143 */
144RTDECL(uint32_t) RTTraceBufGetEntrySize(RTTRACEBUF hTraceBuf);
145
146/**
147 * Gets the number of entries in the specified trace buffer.
148 *
149 * @returns The entry count on success, 0 if the handle is invalid.
150 *
151 * @param hTraceBuf The trace buffer handle. Special handles are
152 * accepted.
153 */
154RTDECL(uint32_t) RTTraceBufGetEntryCount(RTTRACEBUF hTraceBuf);
155
156
157/**
158 * Disables tracing.
159 *
160 * @returns @c true if tracing was enabled prior to this call, @c false if
161 * disabled already.
162 *
163 * @param hTraceBuf The trace buffer handle. Special handles are
164 * accepted.
165 */
166RTDECL(bool) RTTraceBufDisable(RTTRACEBUF hTraceBuf);
167
168/**
169 * Enables tracing.
170 *
171 * @returns @c true if tracing was enabled prior to this call, @c false if
172 * disabled already.
173 *
174 * @param hTraceBuf The trace buffer handle. Special handles are
175 * accepted.
176 */
177RTDECL(bool) RTTraceBufEnable(RTTRACEBUF hTraceBuf);
178
179
180RTDECL(int) RTTraceBufAddMsg( RTTRACEBUF hTraceBuf, const char *pszMsg);
181RTDECL(int) RTTraceBufAddMsgF( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, ...) RT_IPRT_FORMAT_ATTR(2, 3);
182RTDECL(int) RTTraceBufAddMsgV( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
183RTDECL(int) RTTraceBufAddMsgEx( RTTRACEBUF hTraceBuf, const char *pszMsg, size_t cbMaxMsg);
184
185RTDECL(int) RTTraceBufAddPos( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL);
186RTDECL(int) RTTraceBufAddPosMsg( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg);
187RTDECL(int) RTTraceBufAddPosMsgEx( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg, size_t cbMaxMsg);
188RTDECL(int) RTTraceBufAddPosMsgF( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, ...) RT_IPRT_FORMAT_ATTR(5, 6);
189RTDECL(int) RTTraceBufAddPosMsgV( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
190
191
192RTDECL(int) RTTraceSetDefaultBuf(RTTRACEBUF hTraceBuf);
193RTDECL(RTTRACEBUF) RTTraceGetDefaultBuf(void);
194
195
196/** @def RTTRACE_BUF
197 * The trace buffer used by the macros.
198 */
199#ifndef RTTRACE_BUF
200# define RTTRACE_BUF NULL
201#endif
202
203/**
204 * Record the current source position.
205 */
206#ifdef RTTRACE_ENABLED
207# define RTTRACE_POS() do { RTTraceBufAddPos(RTTRACE_BUF, RT_SRC_POS); } while (0)
208#else
209# define RTTRACE_POS() do { } while (0)
210#endif
211
212
213/** @} */
214
215RT_C_DECLS_END
216
217#endif /* !IPRT_INCLUDED_trace_h */
218
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette