Skip to contentSkip to conversation

Simpletrace v2: Code cleanup, refactoring.

PATCH Applied Harsh Prateek Bora 2 participants 6 messages Jul 20, 2012 – Jul 30, 2012

lore
Share & tools
lore
#0 lore raw

cover Simpletrace v2: Code cleanup, refactoring.

Minor code cleanups, refactoring for Simpletrace v2.

Harsh Prateek Bora (4):
trace/simple.c: rename TraceRecordHeader to TraceLogHeader as
appropriate.
trace/simple.c: remove unnecessary typecasting trace/simple.c: remove obsolete code trace/simple.c: minor code refactoring

 trace/simple.c |   21 +++++++++------------
 trace/simple.h |    1 -
 2 files changed, 9 insertions(+), 13 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 trace/simple.c: rename TraceRecordHeader to TraceLogHeader as appropriate.

---
 trace/simple.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
trace/simple.c +2 -2
index b700ea3..5d92939 100644
@@ -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);
@@ -295,7 +295,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 */
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/4 trace/simple.c: remove unnecessary typecasting

In reply to Harsh Prateek Bora
---
 trace/simple.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
trace/simple.c +3 -3
index 5d92939..a0e0f05 100644
@@ -235,9 +235,9 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
     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*)&timestamp_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, &timestamp_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;
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/4 trace/simple.c: remove obsolete code

In reply to Harsh Prateek Bora
---
 trace/simple.c |    2 --
 trace/simple.h |    1 -
 2 files changed, 3 deletions(-)
trace/simple.c +0 -2
index a0e0f05..4fed07f 100644
@@ -231,8 +231,6 @@ 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, &event, sizeof(event));
trace/simple.h +0 -1
index 7e521c1..2ab96a8 100644
@@ -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;
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 4/4 trace/simple.c: minor code refactoring

In reply to Harsh Prateek Bora
---
 trace/simple.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
trace/simple.c +4 -5
index 4fed07f..8e175ec 100644
@@ -269,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);
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to Harsh Prateek Bora
Quoted 9 lines · Harsh Prateek Bora

Minor code cleanups, refactoring for Simpletrace v2.

Harsh Prateek Bora (4):
trace/simple.c: rename TraceRecordHeader to TraceLogHeader as
appropriate.
trace/simple.c: remove unnecessary typecasting trace/simple.c: remove obsolete code trace/simple.c: minor code refactoring

Quoted 7 lines
 trace/simple.c |   21 +++++++++------------
 trace/simple.h |    1 -
 2 files changed, 9 insertions(+), 13 deletions(-)
Signature · 1 line
1.7.10.4

Thanks, applied to the tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan