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
This commit is contained in:
commit
8fa27d21a9
@ -79,7 +79,7 @@ def c(events):
|
|||||||
)
|
)
|
||||||
# pointer var (not string)
|
# pointer var (not string)
|
||||||
elif type_.endswith('*'):
|
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,
|
name = name,
|
||||||
)
|
)
|
||||||
# primitive data type
|
# primitive data type
|
||||||
|
@ -55,7 +55,7 @@ static unsigned int trace_idx;
|
|||||||
static unsigned int writeout_idx;
|
static unsigned int writeout_idx;
|
||||||
static uint64_t dropped_events;
|
static uint64_t dropped_events;
|
||||||
static FILE *trace_fp;
|
static FILE *trace_fp;
|
||||||
static char *trace_file_name = NULL;
|
static char *trace_file_name;
|
||||||
|
|
||||||
/* * Trace buffer entry */
|
/* * Trace buffer entry */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -70,7 +70,7 @@ typedef struct {
|
|||||||
uint64_t header_event_id; /* HEADER_EVENT_ID */
|
uint64_t header_event_id; /* HEADER_EVENT_ID */
|
||||||
uint64_t header_magic; /* HEADER_MAGIC */
|
uint64_t header_magic; /* HEADER_MAGIC */
|
||||||
uint64_t header_version; /* HEADER_VERSION */
|
uint64_t header_version; /* HEADER_VERSION */
|
||||||
} TraceRecordHeader;
|
} TraceLogHeader;
|
||||||
|
|
||||||
|
|
||||||
static void read_from_buffer(unsigned int idx, void *dataptr, size_t size);
|
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;
|
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 = idx;
|
||||||
rec_off = write_to_buffer(rec_off, (uint8_t*)&event, sizeof(event));
|
rec_off = write_to_buffer(rec_off, &event, sizeof(event));
|
||||||
rec_off = write_to_buffer(rec_off, (uint8_t*)×tamp_ns, sizeof(timestamp_ns));
|
rec_off = write_to_buffer(rec_off, ×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, &rec_len, sizeof(rec_len));
|
||||||
|
|
||||||
rec->tbuf_idx = idx;
|
rec->tbuf_idx = idx;
|
||||||
rec->rec_off = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN;
|
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)
|
void trace_record_finish(TraceBufferRecord *rec)
|
||||||
{
|
{
|
||||||
uint8_t temp_rec[sizeof(TraceRecord)];
|
TraceRecord record;
|
||||||
TraceRecord *record = (TraceRecord *) temp_rec;
|
read_from_buffer(rec->tbuf_idx, &record, sizeof(TraceRecord));
|
||||||
read_from_buffer(rec->tbuf_idx, temp_rec, sizeof(TraceRecord));
|
|
||||||
smp_wmb(); /* write barrier before marking as valid */
|
smp_wmb(); /* write barrier before marking as valid */
|
||||||
record->event |= TRACE_RECORD_VALID;
|
record.event |= TRACE_RECORD_VALID;
|
||||||
write_to_buffer(rec->tbuf_idx, temp_rec, sizeof(TraceRecord));
|
write_to_buffer(rec->tbuf_idx, &record, sizeof(TraceRecord));
|
||||||
|
|
||||||
if ((trace_idx - writeout_idx) > TRACE_BUF_FLUSH_THRESHOLD) {
|
if ((trace_idx - writeout_idx) > TRACE_BUF_FLUSH_THRESHOLD) {
|
||||||
flush_trace_file(false);
|
flush_trace_file(false);
|
||||||
@ -295,7 +292,7 @@ void st_set_trace_file_enabled(bool enable)
|
|||||||
flush_trace_file(true);
|
flush_trace_file(true);
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
static const TraceRecordHeader header = {
|
static const TraceLogHeader header = {
|
||||||
.header_event_id = HEADER_EVENT_ID,
|
.header_event_id = HEADER_EVENT_ID,
|
||||||
.header_magic = HEADER_MAGIC,
|
.header_magic = HEADER_MAGIC,
|
||||||
/* Older log readers will check for version at next location */
|
/* 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);
|
st_set_trace_file_enabled(false);
|
||||||
|
|
||||||
free(trace_file_name);
|
g_free(trace_file_name);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) {
|
trace_file_name = g_strdup_printf(CONFIG_TRACE_FILE, getpid());
|
||||||
trace_file_name = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (asprintf(&trace_file_name, "%s", file) < 0) {
|
trace_file_name = g_strdup_printf("%s", file);
|
||||||
trace_file_name = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
st_set_trace_file_enabled(true);
|
st_set_trace_file_enabled(true);
|
||||||
|
@ -29,7 +29,6 @@ void st_flush_trace_buffer(void);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int tbuf_idx;
|
unsigned int tbuf_idx;
|
||||||
unsigned int next_tbuf_idx;
|
|
||||||
unsigned int rec_off;
|
unsigned int rec_off;
|
||||||
} TraceBufferRecord;
|
} TraceBufferRecord;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user