trace.h revision 5c47137ffdbcb823e83b3cfc93bf8ccd3318bec3
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - Tracing.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2011 Oracle Corporation
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @defgroup grp_rt_trace RTTrace - Tracing
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @ingroup grp_rt
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The tracing facility is somewhat similar to a stripped down logger that
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * outputs to a circular buffer. Part of the idea here is that it can the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * overhead is much smaller and that it can be done without involving any
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * locking or other thing that could throw off timing.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @def RTTRACE_DISABLED
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Use this compile time define to disable all tracing macros. This trumps
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * RTTRACE_ENABLED.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @def RTTRACE_ENABLED
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Use this compile time define to enable tracing when not in debug mode
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Determine whether tracing is enabled and forcefully normalize the indicators.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#if (defined(DEBUG) || defined(RTTRACE_ENABLED)) && !defined(RTTRACE_DISABLED)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @name RTTRACEBUF_FLAGS_XXX - RTTraceBufCarve and RTTraceBufCreate flags.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Free the memory block on release using RTMemFree(). */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Whether the trace buffer is disabled or enabled. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#define RTTRACEBUF_FLAGS_DISABLED RT_BIT_32(RTTRACEBUF_FLAGS_DISABLED_BIT)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** The bit number corresponding to the RTTRACEBUF_FLAGS_DISABLED mask. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Mask of the valid flags. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufCreate(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufCarve(PRTTRACEBUF hTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTTraceBufRetain(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTTraceBufRelease(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufDumpToLog(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufDumpToAssert(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Trace buffer callback for processing one entry.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Used by RTTraceBufEnumEntries.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns IPRT status code. Any status code but VINF_SUCCESS will abort the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * enumeration and be returned by RTTraceBufEnumEntries.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param iEntry The entry number.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param NanoTS The timestamp of the entry.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param idCpu The ID of the CPU which added the entry.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pszMsg The message text.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pvUser The user argument.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef DECLCALLBACK(int) FNRTTRACEBUFCALLBACK(RTTRACEBUF hTraceBuf, uint32_t iEntry, uint64_t NanoTS,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to trace buffer enumeration callback function. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef FNRTTRACEBUFCALLBACK *PFNRTTRACEBUFCALLBACK;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Enumerates the used trace buffer entries, calling @a pfnCallback for each.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns IPRT status code. Should the callback (@a pfnCallback) return
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * anything other than VINF_SUCCESS, then the enumeration will be
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * aborted and the status code will be returned by this function.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @retval VINF_SUCCESS
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @retval VERR_INVALID_HANDLE
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @retval VERR_INVALID_PARAMETER
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @retval VERR_INVALID_POINTER
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle. Special handles are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * accepted.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pfnCallback The callback to call for each entry.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pvUser The user argument for the callback.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufEnumEntries(RTTRACEBUF hTraceBuf, PFNRTTRACEBUFCALLBACK pfnCallback, void *pvUser);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Gets the entry size used by the specified trace buffer.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns The size on success, 0 if the handle is invalid.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle. Special handles are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * accepted.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTTraceBufGetEntrySize(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Gets the number of entries in the specified trace buffer.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns The entry count on success, 0 if the handle is invalid.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle. Special handles are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * accepted.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(uint32_t) RTTraceBufGetEntryCount(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Disables tracing.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns @c true if tracing was enabled prior to this call, @c false if
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * disabled already.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle. Special handles are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * accepted.
e5996b7752d36e94746f991da154f641056528d8vboxsyncRTDECL(bool) RTTraceBufDisable(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Enables tracing.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns @c true if tracing was enabled prior to this call, @c false if
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * disabled already.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param hTraceBuf The trace buffer handle. Special handles are
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * accepted.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(bool) RTTraceBufEnable(RTTRACEBUF hTraceBuf);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufAddMsg( RTTRACEBUF hTraceBuf, const char *pszMsg);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufAddMsgF( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, ...);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufAddMsgV( RTTRACEBUF hTraceBuf, const char *pszMsgFmt, va_list va);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTTraceBufAddMsgEx( RTTRACEBUF hTraceBuf, const char *pszMsg, size_t cbMaxMsg);
RTDECL(int) RTTraceBufAddPosMsgEx( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg, size_t cbMaxMsg);
RTDECL(int) RTTraceBufAddPosMsgF( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, ...);
RTDECL(int) RTTraceBufAddPosMsgV( RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, va_list va);
#ifndef RTTRACE_BUF
#ifdef RTTRACE_ENABLED
# define RTTRACE_POS() do { } while (0)