VirtualBox

source: vbox/trunk/include/iprt/formats/tracelog.h@ 71492

Last change on this file since 71492 was 71492, checked in by vboxsync, 7 years ago

Runtime: Introduce RTTraceLog* API for creating and parsing binary trace log files. The format and API is designed with the

following goals in mind:

  1. Allow streaming the data via network or write it to a file.
  2. Embed the structure of the traced data into the log allowing arbitrary structured data to be embedded without requiring adaptions on the parsing side.
  3. Allow grouping of traced data belonging together to easily follow chains of events later on.
  4. Trace events can have a parent assigned to check where an event originally originated from.
  5. Low overhead on the creation side.

The current state implements the absolute basics on the creation and parsing side and is work in progress. This will
be used later on in the device emulation fuzzer to capture device and examine device states and changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/* $Id: tracelog.h 71492 2018-03-24 22:23:10Z vboxsync $ */
2/** @file
3 * IPRT, Binary trace log format.
4 */
5
6/*
7 * Copyright (C) 2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_formats_tracelog_h
28#define ___iprt_formats_tracelog_h
29
30#include <iprt/assert.h>
31#include <iprt/cdefs.h>
32#include <iprt/types.h>
33
34
35/** @defgroup grp_rt_formats_tracelog Binary trace log structures and definitions
36 * @ingroup grp_rt_formats
37 * @{
38 */
39
40/** Size of the record magic in bytes. */
41#define TRACELOG_MAGIC_SZ 8
42
43/**
44 * Trace log identification and options header.
45 */
46typedef struct TRACELOGHDR
47{
48 /** Identifiaction magic. */
49 uint8_t szMagic[8];
50 /** Endianess indicator. */
51 uint32_t u32Endianess;
52 /** File version indicator. */
53 uint32_t u32Version;
54 /** File flags (MBZ for now). */
55 uint32_t fFlags;
56 /** Size of the trace log description in bytes following this header. */
57 uint32_t cbStrDesc;
58 /** Size of a pointer item in bytes. */
59 uint8_t cbTypePtr;
60 /** size of the size_t item in bytes. */
61 uint8_t cbTypeSize;
62 /** Padding to an 4 byte boundary. */
63 uint16_t u16Reserved0;
64 /** Padding to an 8 byte boundary. */
65 uint32_t u32Reserved0;
66 /** Starting timestamp when the log was initialised. */
67 uint64_t u64TsStart;
68 /** Padding to 64byte boundary, reserved for future use. */
69 uint64_t au64Reserved[3];
70} TRACELOGHDR;
71AssertCompileSize(TRACELOGHDR, 64);
72/** Pointer to a trace log header. */
73typedef TRACELOGHDR *PTRACELOGHDR;
74/** Pointer to a const trace log header. */
75typedef const TRACELOGHDR *PCTRACELOGHDR;
76
77/** Magic value for a trace log file (TRACELOG backwards). */
78#define TRACELOG_HDR_MAGIC "GOLECART"
79/** Endianess indicator. */
80#define TRACELOG_HDR_ENDIANESS 0xdeadc0de
81/** The default version (Higher 16bits major, low 16bits minor version). */
82#define TRACELOG_VERSION RT_MAKE_U32(1, 0)
83
84
85/**
86 * Trace log event structure descriptor.
87 */
88typedef struct TRACELOGEVTDESC
89{
90 /** Event descriptor magic. */
91 uint8_t szMagic[8];
92 /** Event structure descriptor ID for identification in events later. */
93 uint32_t u32Id;
94 /** Severity class of the event .*/
95 uint32_t u32Severity;
96 /** Size of the identifier string in bytes without terminator. */
97 uint32_t cbStrId;
98 /** Size of the description string in bytes without terminator. */
99 uint32_t cbStrDesc;
100 /** Number of event items following. */
101 uint32_t cEvtItems;
102 /** Padding to end the descriptor on a 32 byte boundary. */
103 uint32_t au32Padding0;
104} TRACELOGEVTDESC;
105AssertCompileSize(TRACELOGEVTDESC, 32);
106/** Pointer to a trace log event structure descriptor. */
107typedef TRACELOGEVTDESC *PTRACELOGEVTDESC;
108/** Pointer to a const trace log event structure descriptor. */
109typedef const TRACELOGEVTDESC *PCTRACELOGEVTDESC;
110
111/** Event descriptor magic. */
112#define TRACELOG_EVTDESC_MAGIC "\0CSEDTVE"
113
114/** Severity: Informational event*/
115#define TRACELOG_EVTDESC_SEVERITY_INFO UINT32_C(0)
116/** Severity: Warning event*/
117#define TRACELOG_EVTDESC_SEVERITY_WARNING UINT32_C(1)
118/** Severity: Error event*/
119#define TRACELOG_EVTDESC_SEVERITY_ERROR UINT32_C(2)
120/** Severity: Fatal event*/
121#define TRACELOG_EVTDESC_SEVERITY_FATAL UINT32_C(3)
122/** Severity: Debug event*/
123#define TRACELOG_EVTDESC_SEVERITY_DEBUG UINT32_C(4)
124
125
126/**
127 * Trace log event item descriptor.
128 */
129typedef struct TRACELOGEVTITEMDESC
130{
131 /** Event item descriptor magic. */
132 uint8_t szMagic[8];
133 /** Size of the item name string in bytes without terminator. */
134 uint32_t cbStrName;
135 /** Size of the optional description string in bytes without terminator. */
136 uint32_t cbStrDesc;
137 /** Item type */
138 uint32_t u32Type;
139 /** Size of the raw data type if static throughout. */
140 uint32_t cbRawData;
141 /** Padding to end the descriptor on a 32 byte boundary. */
142 uint32_t au32Padding0[2];
143} TRACELOGEVTITEMDESC;
144AssertCompileSize(TRACELOGEVTITEMDESC, 32);
145/** Pointer to a trace log event item descriptor. */
146typedef TRACELOGEVTITEMDESC *PTRACELOGEVTITEMDESC;
147/** Pointer to a const trace log event item descriptor. */
148typedef const TRACELOGEVTITEMDESC *PCTRACELOGEVTITEMDESC;
149
150/** Event item descriptor magic. */
151#define TRACELOG_EVTITEMDESC_MAGIC "CSEDMETI"
152/** Boolean type. */
153#define TRACELOG_EVTITEMDESC_TYPE_BOOL UINT32_C(1)
154/** Unsigned 8bit integer type. */
155#define TRACELOG_EVTITEMDESC_TYPE_UINT8 UINT32_C(2)
156/** Signed 8bit integer type. */
157#define TRACELOG_EVTITEMDESC_TYPE_INT8 UINT32_C(3)
158/** Unsigned 16bit integer type. */
159#define TRACELOG_EVTITEMDESC_TYPE_UINT16 UINT32_C(4)
160/** Signed 16bit integer type. */
161#define TRACELOG_EVTITEMDESC_TYPE_INT16 UINT32_C(5)
162/** Unsigned 32bit integer type. */
163#define TRACELOG_EVTITEMDESC_TYPE_UINT32 UINT32_C(6)
164/** Signed 32bit integer type. */
165#define TRACELOG_EVTITEMDESC_TYPE_INT32 UINT32_C(7)
166/** Unsigned 64bit integer type. */
167#define TRACELOG_EVTITEMDESC_TYPE_UINT64 UINT32_C(8)
168/** Signed 64bit integer type. */
169#define TRACELOG_EVTITEMDESC_TYPE_INT64 UINT32_C(9)
170/** 32bit floating point type. */
171#define TRACELOG_EVTITEMDESC_TYPE_FLOAT32 UINT32_C(10)
172/** 64bit floating point type. */
173#define TRACELOG_EVTITEMDESC_TYPE_FLOAT64 UINT32_C(11)
174/** Raw binary data type. */
175#define TRACELOG_EVTITEMDESC_TYPE_RAWDATA UINT32_C(12)
176/** Pointer data type. */
177#define TRACELOG_EVTITEMDESC_TYPE_POINTER UINT32_C(13)
178/** size_t data type. */
179#define TRACELOG_EVTITEMDESC_TYPE_SIZE UINT32_C(14)
180
181/**
182 * Trace log event marker.
183 */
184typedef struct TRACELOGEVT
185{
186 /** Event marker magic. */
187 uint8_t szMagic[8];
188 /** Trace log sequence number to identify the event uniquely. */
189 uint64_t u64SeqNo;
190 /** Timestamp for the marker (resolution is infered from the header). */
191 uint64_t u64Ts;
192 /** Event group ID for grouping different events together - for no grouped event. */
193 uint64_t u64EvtGrpId;
194 /** Parent group ID this event originated from. */
195 uint64_t u64EvtParentGrpId;
196 /** Overall number of bytes for the event data following including static and possibly variable data. */
197 uint32_t cbEvtData;
198 /** Number of size_t sized raw data size indicators before the raw event data follows. */
199 uint32_t cRawEvtDataSz;
200 /** Event flags. */
201 uint32_t fFlags;
202 /** Event structure descriptor ID to use for structuring the event data. */
203 uint32_t u32EvtDescId;
204 /** Reserved for future use. */
205 uint32_t u32Reserved0;
206} TRACELOGEVT;
207AssertCompileSize(TRACELOGEVT, 64);
208/** Pointer to a trace log event marker. */
209typedef TRACELOGEVT *PTRACELOGEVT;
210/** Pointer to a const trace log event marker. */
211typedef const TRACELOGEVT *PCTRACELOGEVT;
212
213/** Event marker descriptor magic. */
214#define TRACELOG_EVT_MAGIC "\0RKRMTVE"
215/** Flag indicating this is the start of an event group and all subsequent events
216 * with the same group ID belong to the same group. */
217#define TRACELOG_EVT_F_GRP_START RT_BIT_32(0)
218/** Flag indicating this is the end of an event group which was started earlier. */
219#define TRACELOG_EVT_F_GRP_END RT_BIT_32(1)
220/** Combination of valid flags. */
221#define TRACELOG_EVT_F_VALID (TRACELOG_EVT_F_GRP_START | TRACELOG_EVT_F_GRP_END)
222
223/** @} */
224
225#endif
226
Note: See TracBrowser for help on using the repository browser.

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