perf ordered_events: Untangle from perf_session

For use by tools that are not perf.data based, as maybe 'perf trace' in
live mode.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-nedqe7cmii5w82etfi36urfz@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 94ac003b
...@@ -153,10 +153,11 @@ void ordered_events__delete(struct ordered_events *oe, struct ordered_event *eve ...@@ -153,10 +153,11 @@ void ordered_events__delete(struct ordered_events *oe, struct ordered_event *eve
free_dup_event(oe, event->event); free_dup_event(oe, event->event);
} }
static int __ordered_events__flush(struct perf_session *s, static int __ordered_events__flush(struct ordered_events *oe,
struct machines *machines,
struct perf_evlist *evlist,
struct perf_tool *tool) struct perf_tool *tool)
{ {
struct ordered_events *oe = &s->ordered_events;
struct list_head *head = &oe->events; struct list_head *head = &oe->events;
struct ordered_event *tmp, *iter; struct ordered_event *tmp, *iter;
struct perf_sample sample; struct perf_sample sample;
...@@ -179,12 +180,12 @@ static int __ordered_events__flush(struct perf_session *s, ...@@ -179,12 +180,12 @@ static int __ordered_events__flush(struct perf_session *s,
if (iter->timestamp > limit) if (iter->timestamp > limit)
break; break;
ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample); ret = perf_evlist__parse_sample(evlist, iter->event, &sample);
if (ret) if (ret)
pr_err("Can't parse sample, err = %d\n", ret); pr_err("Can't parse sample, err = %d\n", ret);
else { else {
ret = perf_session__deliver_event(s, iter->event, &sample, tool, ret = machines__deliver_event(machines, evlist, iter->event,
iter->file_offset); &sample, tool, iter->file_offset);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -204,10 +205,10 @@ static int __ordered_events__flush(struct perf_session *s, ...@@ -204,10 +205,10 @@ static int __ordered_events__flush(struct perf_session *s,
return 0; return 0;
} }
int ordered_events__flush(struct perf_session *s, struct perf_tool *tool, int ordered_events__flush(struct ordered_events *oe, struct machines *machines,
struct perf_evlist *evlist, struct perf_tool *tool,
enum oe_flush how) enum oe_flush how)
{ {
struct ordered_events *oe = &s->ordered_events;
static const char * const str[] = { static const char * const str[] = {
"NONE", "NONE",
"FINAL", "FINAL",
...@@ -251,7 +252,7 @@ int ordered_events__flush(struct perf_session *s, struct perf_tool *tool, ...@@ -251,7 +252,7 @@ int ordered_events__flush(struct perf_session *s, struct perf_tool *tool,
str[how], oe->nr_events); str[how], oe->nr_events);
pr_oe_time(oe->max_timestamp, "max_timestamp\n"); pr_oe_time(oe->max_timestamp, "max_timestamp\n");
err = __ordered_events__flush(s, tool); err = __ordered_events__flush(oe, machines, evlist, tool);
if (!err) { if (!err) {
if (how == OE_FLUSH__ROUND) if (how == OE_FLUSH__ROUND)
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
#define __ORDERED_EVENTS_H #define __ORDERED_EVENTS_H
#include <linux/types.h> #include <linux/types.h>
#include "tool.h"
struct perf_session; struct perf_tool;
struct perf_evlist;
struct machines;
struct ordered_event { struct ordered_event {
u64 timestamp; u64 timestamp;
...@@ -40,7 +41,8 @@ struct ordered_events { ...@@ -40,7 +41,8 @@ struct ordered_events {
struct ordered_event *ordered_events__new(struct ordered_events *oe, u64 timestamp, struct ordered_event *ordered_events__new(struct ordered_events *oe, u64 timestamp,
union perf_event *event); union perf_event *event);
void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event); void ordered_events__delete(struct ordered_events *oe, struct ordered_event *event);
int ordered_events__flush(struct perf_session *s, struct perf_tool *tool, int ordered_events__flush(struct ordered_events *oe, struct machines *machines,
struct perf_evlist *evlist, struct perf_tool *tool,
enum oe_flush how); enum oe_flush how);
void ordered_events__init(struct ordered_events *oe); void ordered_events__init(struct ordered_events *oe);
void ordered_events__free(struct ordered_events *oe); void ordered_events__free(struct ordered_events *oe);
......
...@@ -512,7 +512,11 @@ static int process_finished_round(struct perf_tool *tool, ...@@ -512,7 +512,11 @@ static int process_finished_round(struct perf_tool *tool,
union perf_event *event __maybe_unused, union perf_event *event __maybe_unused,
struct perf_session *session) struct perf_session *session)
{ {
return ordered_events__flush(session, tool, OE_FLUSH__ROUND); struct ordered_events *oe = &session->ordered_events;
struct perf_evlist *evlist = session->evlist;
struct machines *machines = &session->machines;
return ordered_events__flush(oe, machines, evlist, tool, OE_FLUSH__ROUND);
} }
int perf_session_queue_event(struct perf_session *s, union perf_event *event, int perf_session_queue_event(struct perf_session *s, union perf_event *event,
...@@ -520,6 +524,9 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event, ...@@ -520,6 +524,9 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
u64 file_offset) u64 file_offset)
{ {
struct ordered_events *oe = &s->ordered_events; struct ordered_events *oe = &s->ordered_events;
struct perf_evlist *evlist = s->evlist;
struct machines *machines = &s->machines;
u64 timestamp = sample->time; u64 timestamp = sample->time;
struct ordered_event *new; struct ordered_event *new;
...@@ -536,7 +543,7 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event, ...@@ -536,7 +543,7 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
new = ordered_events__new(oe, timestamp, event); new = ordered_events__new(oe, timestamp, event);
if (!new) { if (!new) {
ordered_events__flush(s, tool, OE_FLUSH__HALF); ordered_events__flush(oe, machines, evlist, tool, OE_FLUSH__HALF);
new = ordered_events__new(oe, timestamp, event); new = ordered_events__new(oe, timestamp, event);
} }
...@@ -886,12 +893,12 @@ static int ...@@ -886,12 +893,12 @@ static int
&sample->read.one, machine); &sample->read.one, machine);
} }
int perf_session__deliver_event(struct perf_session *session, int machines__deliver_event(struct machines *machines,
struct perf_evlist *evlist,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_tool *tool, u64 file_offset) struct perf_tool *tool, u64 file_offset)
{ {
struct perf_evlist *evlist = session->evlist;
struct perf_evsel *evsel; struct perf_evsel *evsel;
struct machine *machine; struct machine *machine;
...@@ -899,7 +906,7 @@ int perf_session__deliver_event(struct perf_session *session, ...@@ -899,7 +906,7 @@ int perf_session__deliver_event(struct perf_session *session,
evsel = perf_evlist__id2evsel(evlist, sample->id); evsel = perf_evlist__id2evsel(evlist, sample->id);
machine = machines__find_for_cpumode(&session->machines, event, sample); machine = machines__find_for_cpumode(machines, event, sample);
switch (event->header.type) { switch (event->header.type) {
case PERF_RECORD_SAMPLE: case PERF_RECORD_SAMPLE:
...@@ -984,12 +991,14 @@ int perf_session__deliver_synth_event(struct perf_session *session, ...@@ -984,12 +991,14 @@ int perf_session__deliver_synth_event(struct perf_session *session,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_tool *tool) struct perf_tool *tool)
{ {
events_stats__inc(&session->evlist->stats, event->header.type); struct perf_evlist *evlist = session->evlist;
events_stats__inc(&evlist->stats, event->header.type);
if (event->header.type >= PERF_RECORD_USER_TYPE_START) if (event->header.type >= PERF_RECORD_USER_TYPE_START)
return perf_session__process_user_event(session, event, tool, 0); return perf_session__process_user_event(session, event, tool, 0);
return perf_session__deliver_event(session, event, sample, tool, 0); return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0);
} }
static void event_swap(union perf_event *event, bool sample_id_all) static void event_swap(union perf_event *event, bool sample_id_all)
...@@ -1090,8 +1099,8 @@ static s64 perf_session__process_event(struct perf_session *session, ...@@ -1090,8 +1099,8 @@ static s64 perf_session__process_event(struct perf_session *session,
return ret; return ret;
} }
return perf_session__deliver_event(session, event, &sample, tool, return machines__deliver_event(&session->machines, evlist, event,
file_offset); &sample, tool, file_offset);
} }
void perf_event_header__bswap(struct perf_event_header *hdr) void perf_event_header__bswap(struct perf_event_header *hdr)
...@@ -1167,6 +1176,9 @@ volatile int session_done; ...@@ -1167,6 +1176,9 @@ volatile int session_done;
static int __perf_session__process_pipe_events(struct perf_session *session, static int __perf_session__process_pipe_events(struct perf_session *session,
struct perf_tool *tool) struct perf_tool *tool)
{ {
struct ordered_events *oe = &session->ordered_events;
struct perf_evlist *evlist = session->evlist;
struct machines *machines = &session->machines;
int fd = perf_data_file__fd(session->file); int fd = perf_data_file__fd(session->file);
union perf_event *event; union perf_event *event;
uint32_t size, cur_size = 0; uint32_t size, cur_size = 0;
...@@ -1246,7 +1258,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session, ...@@ -1246,7 +1258,7 @@ static int __perf_session__process_pipe_events(struct perf_session *session,
goto more; goto more;
done: done:
/* do the final flush for ordered samples */ /* do the final flush for ordered samples */
err = ordered_events__flush(session, tool, OE_FLUSH__FINAL); err = ordered_events__flush(oe, machines, evlist, tool, OE_FLUSH__FINAL);
out_err: out_err:
free(buf); free(buf);
perf_tool__warn_about_errors(tool, &session->evlist->stats); perf_tool__warn_about_errors(tool, &session->evlist->stats);
...@@ -1298,6 +1310,9 @@ static int __perf_session__process_events(struct perf_session *session, ...@@ -1298,6 +1310,9 @@ static 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_tool *tool) u64 file_size, struct perf_tool *tool)
{ {
struct ordered_events *oe = &session->ordered_events;
struct perf_evlist *evlist = session->evlist;
struct machines *machines = &session->machines;
int fd = perf_data_file__fd(session->file); int fd = perf_data_file__fd(session->file);
u64 head, page_offset, file_offset, file_pos, size; u64 head, page_offset, file_offset, file_pos, size;
int err, mmap_prot, mmap_flags, map_idx = 0; int err, mmap_prot, mmap_flags, map_idx = 0;
...@@ -1391,7 +1406,7 @@ static int __perf_session__process_events(struct perf_session *session, ...@@ -1391,7 +1406,7 @@ static int __perf_session__process_events(struct perf_session *session,
out: out:
/* do the final flush for ordered samples */ /* do the final flush for ordered samples */
err = ordered_events__flush(session, tool, OE_FLUSH__FINAL); err = ordered_events__flush(oe, machines, evlist, tool, OE_FLUSH__FINAL);
out_err: out_err:
ui_progress__finish(); ui_progress__finish();
perf_tool__warn_about_errors(tool, &session->evlist->stats); perf_tool__warn_about_errors(tool, &session->evlist->stats);
......
...@@ -57,7 +57,8 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event, ...@@ -57,7 +57,8 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
void perf_tool__fill_defaults(struct perf_tool *tool); void perf_tool__fill_defaults(struct perf_tool *tool);
int perf_session__deliver_event(struct perf_session *session, int machines__deliver_event(struct machines *machines,
struct perf_evlist *evlist,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct perf_tool *tool, u64 file_offset); struct perf_tool *tool, u64 file_offset);
......
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