Commit 0331ee0c authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Arnaldo Carvalho de Melo

perf session: Cleanup __perf_session__process_events()

Replace the pseudo C++ self argument with session and give the mmap related
variables a sensible name. shift is a complete misnomer - it took me several
rounds of cursing to figure out that it's not a shift value.

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20101130163820.029687218@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 28990f75
...@@ -567,13 +567,13 @@ static int perf_session__process_sample(event_t *event, struct perf_session *s, ...@@ -567,13 +567,13 @@ static int perf_session__process_sample(event_t *event, struct perf_session *s,
static int perf_session__process_event(struct perf_session *self, static int perf_session__process_event(struct perf_session *self,
event_t *event, event_t *event,
struct perf_event_ops *ops, struct perf_event_ops *ops,
u64 offset, u64 head) u64 file_offset)
{ {
trace_event(event); trace_event(event);
if (event->header.type < PERF_RECORD_HEADER_MAX) { if (event->header.type < PERF_RECORD_HEADER_MAX) {
dump_printf("%#Lx [%#x]: PERF_RECORD_%s", dump_printf("%#Lx [%#x]: PERF_RECORD_%s",
offset + head, event->header.size, file_offset, event->header.size,
event__name[event->header.type]); event__name[event->header.type]);
hists__inc_nr_events(&self->hists, event->header.type); hists__inc_nr_events(&self->hists, event->header.type);
} }
...@@ -606,7 +606,7 @@ static int perf_session__process_event(struct perf_session *self, ...@@ -606,7 +606,7 @@ static int perf_session__process_event(struct perf_session *self,
return ops->event_type(event, self); return ops->event_type(event, self);
case PERF_RECORD_HEADER_TRACING_DATA: case PERF_RECORD_HEADER_TRACING_DATA:
/* setup for reading amidst mmap */ /* setup for reading amidst mmap */
lseek(self->fd, offset + head, SEEK_SET); lseek(self->fd, file_offset, SEEK_SET);
return ops->tracing_data(event, self); return ops->tracing_data(event, self);
case PERF_RECORD_HEADER_BUILD_ID: case PERF_RECORD_HEADER_BUILD_ID:
return ops->build_id(event, self); return ops->build_id(event, self);
...@@ -705,8 +705,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self, ...@@ -705,8 +705,7 @@ static int __perf_session__process_pipe_events(struct perf_session *self,
} }
if (size == 0 || if (size == 0 ||
(skip = perf_session__process_event(self, &event, ops, (skip = perf_session__process_event(self, &event, ops, head)) < 0) {
0, head)) < 0) {
dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n",
head, event.header.size, event.header.type); head, event.header.size, event.header.type);
/* /*
...@@ -735,19 +734,19 @@ static int __perf_session__process_pipe_events(struct perf_session *self, ...@@ -735,19 +734,19 @@ static int __perf_session__process_pipe_events(struct perf_session *self,
return err; return err;
} }
int __perf_session__process_events(struct perf_session *self, int __perf_session__process_events(struct perf_session *session,
u64 data_offset, u64 data_size, u64 data_offset, u64 data_size,
u64 file_size, struct perf_event_ops *ops) u64 file_size, struct perf_event_ops *ops)
{ {
u64 head, page_offset, file_offset;
int err, mmap_prot, mmap_flags; int err, mmap_prot, mmap_flags;
u64 head, shift; struct ui_progress *progress;
u64 offset = 0;
size_t page_size; size_t page_size;
event_t *event; event_t *event;
uint32_t size; uint32_t size;
char *buf; char *buf;
struct ui_progress *progress = ui_progress__new("Processing events...",
self->size); progress = ui_progress__new("Processing events...", session->size);
if (progress == NULL) if (progress == NULL)
return -1; return -1;
...@@ -755,21 +754,20 @@ int __perf_session__process_events(struct perf_session *self, ...@@ -755,21 +754,20 @@ int __perf_session__process_events(struct perf_session *self,
page_size = sysconf(_SC_PAGESIZE); page_size = sysconf(_SC_PAGESIZE);
head = data_offset; page_offset = page_size * (data_offset / page_size);
shift = page_size * (head / page_size); file_offset = page_offset;
offset += shift; head = data_offset - page_offset;
head -= shift;
mmap_prot = PROT_READ; mmap_prot = PROT_READ;
mmap_flags = MAP_SHARED; mmap_flags = MAP_SHARED;
if (self->header.needs_swap) { if (session->header.needs_swap) {
mmap_prot |= PROT_WRITE; mmap_prot |= PROT_WRITE;
mmap_flags = MAP_PRIVATE; mmap_flags = MAP_PRIVATE;
} }
remap: remap:
buf = mmap(NULL, page_size * self->mmap_window, mmap_prot, buf = mmap(NULL, page_size * session->mmap_window, mmap_prot,
mmap_flags, self->fd, offset); mmap_flags, session->fd, file_offset);
if (buf == MAP_FAILED) { if (buf == MAP_FAILED) {
pr_err("failed to mmap file\n"); pr_err("failed to mmap file\n");
err = -errno; err = -errno;
...@@ -778,36 +776,35 @@ int __perf_session__process_events(struct perf_session *self, ...@@ -778,36 +776,35 @@ int __perf_session__process_events(struct perf_session *self,
more: more:
event = (event_t *)(buf + head); event = (event_t *)(buf + head);
ui_progress__update(progress, offset); ui_progress__update(progress, file_offset);
if (self->header.needs_swap) if (session->header.needs_swap)
perf_event_header__bswap(&event->header); perf_event_header__bswap(&event->header);
size = event->header.size; size = event->header.size;
if (size == 0) if (size == 0)
size = 8; size = 8;
if (head + event->header.size >= page_size * self->mmap_window) { if (head + event->header.size >= page_size * session->mmap_window) {
int munmap_ret; int munmap_ret;
shift = page_size * (head / page_size); munmap_ret = munmap(buf, page_size * session->mmap_window);
munmap_ret = munmap(buf, page_size * self->mmap_window);
assert(munmap_ret == 0); assert(munmap_ret == 0);
offset += shift; page_offset = page_size * (head / page_size);
head -= shift; file_offset += page_offset;
head -= page_offset;
goto remap; goto remap;
} }
size = event->header.size; size = event->header.size;
dump_printf("\n%#Lx [%#x]: event: %d\n", dump_printf("\n%#Lx [%#x]: event: %d\n",
offset + head, event->header.size, event->header.type); file_offset + head, event->header.size, event->header.type);
if (size == 0 || if (size == 0 || perf_session__process_event(session, event, ops,
perf_session__process_event(self, event, ops, offset, head) < 0) { file_offset + head) < 0) {
dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n", dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n",
offset + head, event->header.size, file_offset + head, event->header.size,
event->header.type); event->header.type);
/* /*
* assume we lost track of the stream, check alignment, and * assume we lost track of the stream, check alignment, and
...@@ -821,34 +818,34 @@ int __perf_session__process_events(struct perf_session *self, ...@@ -821,34 +818,34 @@ int __perf_session__process_events(struct perf_session *self,
head += size; head += size;
if (offset + head >= data_offset + data_size) if (file_offset + head >= data_offset + data_size)
goto done; goto done;
if (offset + head < file_size) if (file_offset + head < file_size)
goto more; goto more;
done: done:
err = 0; err = 0;
/* do the final flush for ordered samples */ /* do the final flush for ordered samples */
self->ordered_samples.next_flush = ULLONG_MAX; session->ordered_samples.next_flush = ULLONG_MAX;
flush_sample_queue(self, ops); flush_sample_queue(session, ops);
out_err: out_err:
ui_progress__delete(progress); ui_progress__delete(progress);
if (ops->lost == event__process_lost && if (ops->lost == event__process_lost &&
self->hists.stats.total_lost != 0) { session->hists.stats.total_lost != 0) {
ui__warning("Processed %Lu events and LOST %Lu!\n\n" ui__warning("Processed %Lu events and LOST %Lu!\n\n"
"Check IO/CPU overload!\n\n", "Check IO/CPU overload!\n\n",
self->hists.stats.total_period, session->hists.stats.total_period,
self->hists.stats.total_lost); session->hists.stats.total_lost);
} }
if (self->hists.stats.nr_unknown_events != 0) { if (session->hists.stats.nr_unknown_events != 0) {
ui__warning("Found %u unknown events!\n\n" ui__warning("Found %u unknown events!\n\n"
"Is this an older tool processing a perf.data " "Is this an older tool processing a perf.data "
"file generated by a more recent tool?\n\n" "file generated by a more recent tool?\n\n"
"If that is not the case, consider " "If that is not the case, consider "
"reporting to linux-kernel@vger.kernel.org.\n\n", "reporting to linux-kernel@vger.kernel.org.\n\n",
self->hists.stats.nr_unknown_events); session->hists.stats.nr_unknown_events);
} }
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment