diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2012-08-15 11:14:06 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-08-15 11:14:06 -0500 |
commit | 8fa27d21a993e261137d15def5475ba2c4d8985b (patch) | |
tree | acb9baa250763fe6befe5a3b928e9ab345b39fe7 | |
parent | 03834e22abafbc8dc4052d46a5ccd6dd135a54a3 (diff) | |
parent | 4552e41025af4694c55854448c3ae4d95e72c7f6 (diff) | |
download | qemu-8fa27d21a993e261137d15def5475ba2c4d8985b.zip qemu-8fa27d21a993e261137d15def5475ba2c4d8985b.tar.gz qemu-8fa27d21a993e261137d15def5475ba2c4d8985b.tar.bz2 |
Merge remote-tracking branch 'stefanha/tracing' into staging
* stefanha/tracing:
trace/simple: Replace asprintf by g_strdup_printf
trace/simple: Fix compiler warning for 32 bit hosts
trace: avoid pointer aliasing in trace_record_finish()
trace: drop unused TraceBufferRecord->next_tbuf_idx field
trace: remove unnecessary write_to_buffer() typecasting
trace: rename TraceRecordHeader to TraceLogHeader
-rw-r--r-- | scripts/tracetool/backend/simple.py | 2 | ||||
-rw-r--r-- | trace/simple.c | 35 | ||||
-rw-r--r-- | trace/simple.h | 1 |
3 files changed, 14 insertions, 24 deletions
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py index c7e47d6..e4b4a7f 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -79,7 +79,7 @@ def c(events): ) # pointer var (not string) elif type_.endswith('*'): - out(' trace_record_write_u64(&rec, (uint64_t)(uint64_t *)%(name)s);', + out(' trace_record_write_u64(&rec, (uintptr_t)(uint64_t *)%(name)s);', name = name, ) # primitive data type diff --git a/trace/simple.c b/trace/simple.c index b700ea3..d83681b 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -55,7 +55,7 @@ static unsigned int trace_idx; static unsigned int writeout_idx; static uint64_t dropped_events; static FILE *trace_fp; -static char *trace_file_name = NULL; +static char *trace_file_name; /* * Trace buffer entry */ typedef struct { @@ -70,7 +70,7 @@ typedef struct { uint64_t header_event_id; /* HEADER_EVENT_ID */ uint64_t header_magic; /* HEADER_MAGIC */ uint64_t header_version; /* HEADER_VERSION */ -} TraceRecordHeader; +} TraceLogHeader; static void read_from_buffer(unsigned int idx, void *dataptr, size_t size); @@ -231,13 +231,11 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi } idx = old_idx % TRACE_BUF_LEN; - /* To check later if threshold crossed */ - rec->next_tbuf_idx = new_idx % TRACE_BUF_LEN; rec_off = idx; - rec_off = write_to_buffer(rec_off, (uint8_t*)&event, sizeof(event)); - rec_off = write_to_buffer(rec_off, (uint8_t*)×tamp_ns, sizeof(timestamp_ns)); - rec_off = write_to_buffer(rec_off, (uint8_t*)&rec_len, sizeof(rec_len)); + rec_off = write_to_buffer(rec_off, &event, sizeof(event)); + rec_off = write_to_buffer(rec_off, ×tamp_ns, sizeof(timestamp_ns)); + rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len)); rec->tbuf_idx = idx; rec->rec_off = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN; @@ -271,12 +269,11 @@ static unsigned int write_to_buffer(unsigned int idx, void *dataptr, size_t size void trace_record_finish(TraceBufferRecord *rec) { - uint8_t temp_rec[sizeof(TraceRecord)]; - TraceRecord *record = (TraceRecord *) temp_rec; - read_from_buffer(rec->tbuf_idx, temp_rec, sizeof(TraceRecord)); + TraceRecord record; + read_from_buffer(rec->tbuf_idx, &record, sizeof(TraceRecord)); smp_wmb(); /* write barrier before marking as valid */ - record->event |= TRACE_RECORD_VALID; - write_to_buffer(rec->tbuf_idx, temp_rec, sizeof(TraceRecord)); + record.event |= TRACE_RECORD_VALID; + write_to_buffer(rec->tbuf_idx, &record, sizeof(TraceRecord)); if ((trace_idx - writeout_idx) > TRACE_BUF_FLUSH_THRESHOLD) { flush_trace_file(false); @@ -295,7 +292,7 @@ void st_set_trace_file_enabled(bool enable) flush_trace_file(true); if (enable) { - static const TraceRecordHeader header = { + static const TraceLogHeader header = { .header_event_id = HEADER_EVENT_ID, .header_magic = HEADER_MAGIC, /* Older log readers will check for version at next location */ @@ -332,18 +329,12 @@ bool st_set_trace_file(const char *file) { st_set_trace_file_enabled(false); - free(trace_file_name); + g_free(trace_file_name); if (!file) { - if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) { - trace_file_name = NULL; - return false; - } + trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, getpid()); } else { - if (asprintf(&trace_file_name, "%s", file) < 0) { - trace_file_name = NULL; - return false; - } + trace_file_name = g_strdup_printf("%s", file); } st_set_trace_file_enabled(true); diff --git a/trace/simple.h b/trace/simple.h index 7e521c1..2ab96a8 100644 --- a/trace/simple.h +++ b/trace/simple.h @@ -29,7 +29,6 @@ void st_flush_trace_buffer(void); typedef struct { unsigned int tbuf_idx; - unsigned int next_tbuf_idx; unsigned int rec_off; } TraceBufferRecord; |