Skip to content

Commit

Permalink
trace-cmd: Show lost events if buffer supports it
Browse files Browse the repository at this point in the history
If the ring buffer in the kernel sends information via the commit
field of the sub buffer header. Than this patch will display
where events were lost.

If the sub buffer has space and can store the count of dropped events,
this patch will show the count as well.

Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Steven Rostedt authored and rostedt committed Apr 1, 2010
1 parent 9492113 commit 73effeb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
41 changes: 35 additions & 6 deletions parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -4041,11 +4041,16 @@ static void print_args(struct print_arg *args)
}

static void parse_header_field(const char *field,
int *offset, int *size)
int *offset, int *size, int mandatory)
{
unsigned long long save_input_buf_ptr;
unsigned long long save_input_buf_siz;
char *token;
int type;

save_input_buf_ptr = input_buf_ptr;
save_input_buf_siz = input_buf_siz;

if (read_expected(EVENT_ITEM, "field") < 0)
return;
if (read_expected(EVENT_OP, ":") < 0)
Expand All @@ -4056,8 +4061,20 @@ static void parse_header_field(const char *field,
goto fail;
free_token(token);

if (read_expected(EVENT_ITEM, field) < 0)
return;
/*
* If this is not a mandatory field, then test it first.
*/
if (mandatory) {
if (read_expected(EVENT_ITEM, field) < 0)
return;
} else {
if (read_expect_type(EVENT_ITEM, &token) < 0)
goto fail;
if (strcmp(token, field) != 0)
goto discard;
free_token(token);
}

if (read_expected(EVENT_OP, ";") < 0)
return;
if (read_expected(EVENT_ITEM, "offset") < 0)
Expand Down Expand Up @@ -4106,6 +4123,14 @@ static void parse_header_field(const char *field,
}
fail:
free_token(token);
return;

discard:
input_buf_ptr = save_input_buf_ptr;
input_buf_siz = save_input_buf_siz;
*offset = 0;
*size = 0;
free_token(token);
}

/**
Expand All @@ -4123,6 +4148,8 @@ static void parse_header_field(const char *field,
int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
int long_size)
{
int ignore;

if (!size) {
/*
* Old kernels did not have header page info.
Expand All @@ -4137,11 +4164,13 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz
init_input_buf(buf, size);

parse_header_field("timestamp", &pevent->header_page_ts_offset,
&pevent->header_page_ts_size);
&pevent->header_page_ts_size, 1);
parse_header_field("commit", &pevent->header_page_size_offset,
&pevent->header_page_size_size);
&pevent->header_page_size_size, 1);
parse_header_field("overwrite", &pevent->header_page_overwrite,
&ignore, 0);
parse_header_field("data", &pevent->header_page_data_offset,
&pevent->header_page_data_size);
&pevent->header_page_data_size, 1);

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions parse-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
struct record {
unsigned long long ts;
unsigned long long offset;
long long missed_events; /* buffer dropped events before */
int record_size; /* size of binary record */
int size; /* size of data */
void *data;
Expand Down Expand Up @@ -284,6 +285,7 @@ struct pevent {
int header_page_size_size;
int header_page_data_offset;
int header_page_data_size;
int header_page_overwrite;

int file_bigendian;
int host_bigendian;
Expand Down
40 changes: 37 additions & 3 deletions trace-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include "trace-cmd-local.h"
#include "list.h"

#define MISSING_EVENTS (1 << 31)
#define MISSING_STORED (1 << 30)

#define COMMIT_MASK ((1 << 27) - 1)

/* for debugging read instead of mmap */
static int force_read = 0;

Expand All @@ -48,6 +53,7 @@ struct page {
struct tracecmd_input *handle;
void *map;
int ref_count;
long long lost_events;
};

struct cpu_data {
Expand Down Expand Up @@ -679,6 +685,7 @@ static int update_page_info(struct tracecmd_input *handle, int cpu)
{
struct pevent *pevent = handle->pevent;
void *ptr = handle->cpu_data[cpu].page->map;
unsigned int flags;

/* FIXME: handle header page */
if (pevent->header_page_ts_size != 8) {
Expand All @@ -690,16 +697,39 @@ static int update_page_info(struct tracecmd_input *handle, int cpu)
ptr += 8;
switch (pevent->header_page_size_size) {
case 4:
handle->cpu_data[cpu].page_size = data2host4(pevent, ptr);
flags = data2host4(pevent, ptr);
ptr += 4;
break;
case 8:
handle->cpu_data[cpu].page_size = data2host8(pevent, ptr);
flags = (unsigned int)data2host8(pevent, ptr);
ptr += 8;
break;
default:
warning("bad long size");
return -1;
}

handle->cpu_data[cpu].page_size = flags & COMMIT_MASK;

if (flags & MISSING_EVENTS) {
breakpoint();
if (flags & MISSING_STORED) {
ptr += handle->cpu_data[cpu].page_size;
switch (pevent->header_page_size_size) {
case 4:
handle->cpu_data[cpu].page->lost_events =
data2host4(pevent, ptr);
break;
case 8:
handle->cpu_data[cpu].page->lost_events =
data2host8(pevent, ptr);
break;
}
} else
handle->cpu_data[cpu].page->lost_events = -1;
} else
handle->cpu_data[cpu].page->lost_events = 0;

handle->cpu_data[cpu].index = 0;

return 0;
Expand Down Expand Up @@ -1435,6 +1465,7 @@ tracecmd_peek_data(struct tracecmd_input *handle, int cpu)
void *ptr;
unsigned long long extend;
unsigned int type_len;
long long missed_events = 0;
int length;

if (index < 0)
Expand Down Expand Up @@ -1464,8 +1495,10 @@ tracecmd_peek_data(struct tracecmd_input *handle, int cpu)

ptr = page->map + index;

if (!index)
if (!index) {
missed_events = page->lost_events;
ptr = handle->cpu_data[cpu].page->map + pevent->header_page_data_offset;
}

read_again:
index = calc_index(handle, ptr, cpu);
Expand Down Expand Up @@ -1520,6 +1553,7 @@ tracecmd_peek_data(struct tracecmd_input *handle, int cpu)
record->cpu = cpu;
record->data = ptr;
record->offset = handle->cpu_data[cpu].offset + index;
record->missed_events = missed_events;

ptr += length;

Expand Down
6 changes: 6 additions & 0 deletions trace-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ static void show_data(struct tracecmd_input *handle,
test_save(record, cpu);

trace_seq_init(&s);
if (record->missed_events > 0)
trace_seq_printf(&s, "CPU:%d [%lld EVENTS DROPPED]\n",
record->cpu, record->missed_events);
else if (record->missed_events < 0)
trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n",
record->cpu);
pevent_print_event(pevent, &s, record);
trace_seq_do_printf(&s);

Expand Down

0 comments on commit 73effeb

Please sign in to comment.