tracebuf.cpp revision d793e85931b7b22b0a443db1510b26c180d44a18
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync* Header Files *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync*******************************************************************************/
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#if defined(IN_RING0) || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync* Structures and Typedefs *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync*******************************************************************************/
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Alignment used to place the trace buffer members, this should be a multiple
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * of the cache line size if possible. (We should dynamically determine it.) */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncAssertCompile(RTTRACEBUF_ALIGNMENT >= sizeof(uint64_t) * 2);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The maximum number of entries. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The minimum number of entries. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The default number of entries. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The maximum entry size. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The minimum entry size. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#define RTTRACEBUF_MIN_ENTRY_SIZE RTTRACEBUF_ALIGNMENT
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** The default entry size. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncAssertCompile(!(RTTRACEBUF_DEF_ENTRY_SIZE & (RTTRACEBUF_DEF_ENTRY_SIZE - 1)));
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * The volatile trace buffer members.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** Reference counter. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The next entry to make use of. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Pointer to the volatile parts of a trace buffer. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Trace buffer entry.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The nano second entry time stamp. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The ID of the CPU the event was recorded. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The message. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync char szMsg[RTTRACEBUF_ALIGNMENT - sizeof(uint64_t) - sizeof(RTCPUID)];
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncAssertCompile(sizeof(RTTRACEBUFENTRY) <= RTTRACEBUF_ALIGNMENT);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Pointer to a trace buffer entry. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Trace buffer structure.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @remarks This structure must be context agnostic, i.e. no pointers or
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * other types that may differ between contexts (R3/R0/RC).
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** Magic value (RTTRACEBUF_MAGIC). */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The entry size. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The number of entries. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** Flags (always zero for now). */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The offset to the volatile members (RTTRACEBUFVOLATILE) (relative to
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * the start of this structure). */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** The offset to the entries (relative to the start of this structure). */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /** Reserved entries. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Pointer to a const trace buffer. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync* Defined Constants And Macros *
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync*******************************************************************************/
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync * Get the current CPU Id.
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync#if defined(IN_RING0) || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Calculates the address of the volatile trace buffer members. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#define RTTRACEBUF_TO_VOLATILE(a_pThis) ((PRTTRACEBUFVOLATILE)((uint8_t *)(a_pThis) + (a_pThis)->offVolatile))
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** Calculates the address of a trace buffer entry. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync ((PRTTRACEBUFENTRY)( (uint8_t *)(a_pThis) + (a_pThis)->offEntries + (a_iEntry) * (a_pThis)->cbEntry ))
return VERR_NOT_FOUND; \
if (!cRefs) \
int rc; \
char *pszBuf; \
return VERR_NOT_FOUND; \
return VERR_INVALID_HANDLE; \
return VINF_SUCCESS; \
#define RTTRACEBUF_ADD_STORE_SRC_POS() \
#define RTTRACEBUF_ADD_EPILOGUE() \
if (!cRefs) \
return rc
RTDECL(int) RTTraceBufCreate(PRTTRACEBUF phTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags)
AssertReturn(!(fFlags & ~(RTTRACEBUF_FLAGS_MASK & ~ RTTRACEBUF_FLAGS_FREE_ME)), VERR_INVALID_PARAMETER);
if (!cbEntry)
if (!cEntries)
int rc;
if (pvBlock)
return rc;
RTDECL(int) RTTraceBufCarve(PRTTRACEBUF phTraceBuf, uint32_t cEntries, uint32_t cbEntry, uint32_t fFlags,
if (cbEntry)
if (!cbEntryBuf)
else if (cEntries)
if (!cEntries)
return VERR_BUFFER_OVERFLOW;
return VINF_SUCCESS;
#ifdef IN_RC
if (!cRefs)
return cRefs;
int rc;
return rc;
RTDECL(int) RTTraceBufAddPosMsgEx(RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsg, size_t cbMaxMsg)
int rc;
return rc;
RTDECL(int) RTTraceBufAddPosMsgV(RTTRACEBUF hTraceBuf, RT_SRC_POS_DECL, const char *pszMsgFmt, va_list va)
RTDECL(int) RTTraceBufEnumEntries(RTTRACEBUF hTraceBuf, PFNRTTRACEBUFCALLBACK pfnCallback, void *pvUser)
while (cLeft--)
return rc;
while (cLeft--)
return VINF_SUCCESS;
while (cLeft--)
return VINF_SUCCESS;