Files
hiperiso/logging/hiperiso-log/simpletrace.h
T
2026-06-30 14:30:52 +03:00

69 lines
2.2 KiB
C

/*
* simpletrace.h - QEMU simpletrace binary format constants.
*
* Based on the actual QEMU source: scripts/simpletrace.py and trace/simple.c.
* The format is NOT documented as stable — trace files must be parsed with
* the matching simpletrace implementation.
*
* All fields are stored in native byte-order (little-endian on x86_64).
*
* File layout:
*
* File header (24 bytes, Python struct '=QQQ'):
* uint64_t header_event_id = TRACE_HEADER_EVENT_ID (sentinel)
* uint64_t header_magic = TRACE_HEADER_MAGIC
* uint64_t log_version = TRACE_HEADER_VERSION
*
* Records — each begins with a uint64 discriminator ("rectype"):
*
* rectype == TRACE_RECORD_TYPE_MAPPING (0):
* uint64_t event_id
* uint32_t name_length
* char name[name_length] (no NUL terminator on disk)
*
* rectype == TRACE_RECORD_TYPE_EVENT (1):
* uint64_t event_id
* uint64_t timestamp_ns
* uint32_t record_length (total: 24 + args payload length)
* uint32_t record_pid
* uint8_t args[record_length - 24]
*/
#ifndef SIMPLETRACE_H
#define SIMPLETRACE_H
#include <stdint.h>
/* --- File header constants --- */
/* First uint64 of the file header — identifies this as the header record. */
#define TRACE_HEADER_EVENT_ID 0xffffffffffffffffULL
/* Magic value in the second uint64 of the file header. */
#define TRACE_HEADER_MAGIC 0xf2b177cb0aa429b4ULL
/* Supported log format versions (0, 2, 3, 4 have existed; 4 is current). */
#define TRACE_HEADER_VERSION 4
/* Pseudo event-id used when QEMU drops events due to a full ring buffer. */
#define TRACE_DROPPED_EVENT_ID 0xfffffffffffffffeULL
/* --- Record type discriminators (first uint64 of each record) --- */
#define TRACE_RECORD_TYPE_MAPPING 0
#define TRACE_RECORD_TYPE_EVENT 1
/* --- Field / header sizes --- */
/* File header: 3 x uint64 = 24 bytes. */
#define TRACE_LOG_HEADER_LEN 24
/* Event-record body after the rectype uint64 (Python '=QQII'): 24 bytes.
* uint64 event_id + uint64 timestamp_ns + uint32 record_length + uint32 pid */
#define TRACE_REC_HEADER_LEN 24
/* Record-type discriminator field. */
#define TRACE_REC_TYPE_LEN 8
#endif /* SIMPLETRACE_H */