From ef4c9fc8542e06b1d567172c04b0c0377c7ab0c5 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 4 Oct 2016 14:35:49 +0100 Subject: trace: remove the TraceEventID and TraceEventVCPUID enums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TraceEventID and TraceEventVCPUID enums constants are no longer actually used for anything critical. The TRACE_EVENT_COUNT limit is used to determine the size of the TraceEvents array, and can be removed if we just NULL terminate the array instead. The TRACE_VCPU_EVENT_COUNT limit is used as a magic value for marking non-vCPU events, and also for declaring the size of the trace dstate mask in the CPUState struct. The former usage can be replaced by a dedicated constant TRACE_EVENT_VCPU_NONE, defined as (uint32_t)-1. For the latter usage, we can simply define a constant for the number of VCPUs, avoiding the need for the full enum. The only other usages of the enum values can be replaced by accesing the id/vcpu_id fields via the named TraceEvent structs. Reviewed-by: LluĂ­s Vilanova Reviewed-by: Stefan Hajnoczi Signed-off-by: Daniel P. Berrange Message-id: 1475588159-30598-11-git-send-email-berrange@redhat.com Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'trace/simple.c') diff --git a/trace/simple.c b/trace/simple.c index 2f09dafcbc..2ec32e159c 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -17,8 +17,8 @@ #include "trace/control.h" #include "trace/simple.h" -/** Trace file header event ID */ -#define HEADER_EVENT_ID (~(uint64_t)0) /* avoids conflicting with TraceEventIDs */ +/** Trace file header event ID, picked to avoid conflict with real event IDs */ +#define HEADER_EVENT_ID (~(uint64_t)0) /** Trace file magic number */ #define HEADER_MAGIC 0xf2b177cb0aa429b4ULL @@ -58,7 +58,7 @@ static char *trace_file_name; /* * Trace buffer entry */ typedef struct { - uint64_t event; /* TraceEventID */ + uint64_t event; /* event ID value */ uint64_t timestamp_ns; uint32_t length; /* in bytes */ uint32_t pid; @@ -202,7 +202,7 @@ void trace_record_write_str(TraceBufferRecord *rec, const char *s, uint32_t slen rec->rec_off = write_to_buffer(rec->rec_off, (void*)s, slen); } -int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasize) +int trace_record_start(TraceBufferRecord *rec, uint32_t event, size_t datasize) { unsigned int idx, rec_off, old_idx, new_idx; uint32_t rec_len = sizeof(TraceRecord) + datasize; -- cgit v1.2.3 From 7f1b588f20d027730676e627713ae3bbf6baab04 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 4 Oct 2016 14:35:50 +0100 Subject: trace: emit name <-> ID mapping in simpletrace header Currently simpletrace assumes that events are given IDs starting from 0, based on the order in which they appear in the trace-events file, with no gaps. When the trace-events file is split up, this assumption becomes problematic. To deal with this, extend the simpletrace format so that it outputs a table of event name <-> ID mappings. That will allow QEMU to assign arbitrary IDs to events without breaking simpletrace parsing. The v3 simple trace format was FILE HEADER EVENT TRACE RECORD 0 EVENT TRACE RECORD 1 ... EVENT TRACE RECORD N The v4 simple trace format is now FILE HEADER EVENT MAPPING RECORD 0 EVENT MAPPING RECORD 1 ... EVENT MAPPING RECORD M EVENT TRACE RECORD RECORD 0 EVENT TRACE RECORD RECORD 1 ... EVENT TRACE RECORD N Although this shows all the mapping records being emitted upfront, this is not required by the format. While the main simpletrace backend will emit all mappings at startup, the systemtap simpletrace.stp script will emit the mappings at first use. eg FILE HEADER ... EVENT MAPPING RECORD 0 EVENT TRACE RECORD RECORD 0 EVENT TRACE RECORD RECORD 1 EVENT MAPPING RECORD 1 EVENT TRACE RECORD RECORD 2 ... EVENT TRACE RECORD N This is more space efficient given that most trace records only include a subset of events. In modifying the systemtap simpletrace code, a 'begin' probe was added to emit the trace event header, so you no longer need to add '--no-header' when running simpletrace.py for systemtap generated trace files. Signed-off-by: Daniel P. Berrange Message-id: 1475588159-30598-12-git-send-email-berrange@redhat.com Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'trace/simple.c') diff --git a/trace/simple.c b/trace/simple.c index 2ec32e159c..b263622fa9 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -24,7 +24,7 @@ #define HEADER_MAGIC 0xf2b177cb0aa429b4ULL /** Trace file version number, bump if format changes */ -#define HEADER_VERSION 3 +#define HEADER_VERSION 4 /** Records were dropped event ID */ #define DROPPED_EVENT_ID (~(uint64_t)0 - 1) @@ -56,6 +56,9 @@ static uint32_t trace_pid; static FILE *trace_fp; static char *trace_file_name; +#define TRACE_RECORD_TYPE_MAPPING 0 +#define TRACE_RECORD_TYPE_EVENT 1 + /* * Trace buffer entry */ typedef struct { uint64_t event; /* event ID value */ @@ -160,6 +163,7 @@ static gpointer writeout_thread(gpointer opaque) unsigned int idx = 0; int dropped_count; size_t unused __attribute__ ((unused)); + uint64_t type = TRACE_RECORD_TYPE_EVENT; for (;;) { wait_for_trace_records_available(); @@ -174,10 +178,12 @@ static gpointer writeout_thread(gpointer opaque) } while (!g_atomic_int_compare_and_exchange(&dropped_events, dropped_count, 0)); dropped.rec.arguments[0] = dropped_count; + unused = fwrite(&type, sizeof(type), 1, trace_fp); unused = fwrite(&dropped.rec, dropped.rec.length, 1, trace_fp); } while (get_trace_record(idx, &recordptr)) { + unused = fwrite(&type, sizeof(type), 1, trace_fp); unused = fwrite(recordptr, recordptr->length, 1, trace_fp); writeout_idx += recordptr->length; free(recordptr); /* don't use g_free, can deadlock when traced */ @@ -273,6 +279,28 @@ void trace_record_finish(TraceBufferRecord *rec) } } +static int st_write_event_mapping(void) +{ + uint64_t type = TRACE_RECORD_TYPE_MAPPING; + TraceEventIter iter; + TraceEvent *ev; + + trace_event_iter_init(&iter, NULL); + while ((ev = trace_event_iter_next(&iter)) != NULL) { + uint64_t id = trace_event_get_id(ev); + const char *name = trace_event_get_name(ev); + uint32_t len = strlen(name); + if (fwrite(&type, sizeof(type), 1, trace_fp) != 1 || + fwrite(&id, sizeof(id), 1, trace_fp) != 1 || + fwrite(&len, sizeof(len), 1, trace_fp) != 1 || + fwrite(name, len, 1, trace_fp) != 1) { + return -1; + } + } + + return 0; +} + void st_set_trace_file_enabled(bool enable) { if (enable == !!trace_fp) { @@ -297,7 +325,8 @@ void st_set_trace_file_enabled(bool enable) return; } - if (fwrite(&header, sizeof header, 1, trace_fp) != 1) { + if (fwrite(&header, sizeof header, 1, trace_fp) != 1 || + st_write_event_mapping() < 0) { fclose(trace_fp); trace_fp = NULL; return; -- cgit v1.2.3