diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 08:58:03 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-07 22:43:37 -0400 |
commit | fcf65bf149afa91b875ffde4455967cb63ee0be9 (patch) | |
tree | 9b6137e60d4142b1aa00f9e20860bdd8374035d3 /tools/perf/builtin-sched.c | |
parent | 8b6ee4c5d48d93527dcf6e36c51cbb7703d7fffb (diff) |
perf evsel: Cache associated event_format
We already lookup the associated event_format when reading the perf.data
header, so that we can cache the tracepoint name in evsel->name, so do
it a little further and save the event_format itself, so that we can
avoid relookups in tools that need to access it.
Change the tools to take the most obvious advantage, when they were
using pevent_find_event directly. More work is needed for further
removing the need of a pointer to pevent, such as when asking for event
field values ("common_pid" and the other common fields and per
event_format fields).
This is something that was planned but only got actually done when
Andrey Wagin needed to do this lookup at perf_tool->sample() time, when
we don't have access to pevent (session->pevent) to use with
pevent_find_event().
Cc: Andrey Wagin <avagin@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/n/tip-txkvew2ckko0b594ae8fbnyk@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-sched.c')
-rw-r--r-- | tools/perf/builtin-sched.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 7a9ad2b1ee76..30ef82aca885 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -43,11 +43,6 @@ static u64 sleep_measurement_overhead; | |||
43 | 43 | ||
44 | static unsigned long nr_tasks; | 44 | static unsigned long nr_tasks; |
45 | 45 | ||
46 | struct perf_sched { | ||
47 | struct perf_tool tool; | ||
48 | struct perf_session *session; | ||
49 | }; | ||
50 | |||
51 | struct sched_atom; | 46 | struct sched_atom; |
52 | 47 | ||
53 | struct task_desc { | 48 | struct task_desc { |
@@ -1596,14 +1591,12 @@ typedef void (*tracepoint_handler)(struct perf_tool *tool, struct event_format * | |||
1596 | struct machine *machine, | 1591 | struct machine *machine, |
1597 | struct thread *thread); | 1592 | struct thread *thread); |
1598 | 1593 | ||
1599 | static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | 1594 | static int perf_sched__process_tracepoint_sample(struct perf_tool *tool __used, |
1600 | union perf_event *event __used, | 1595 | union perf_event *event __used, |
1601 | struct perf_sample *sample, | 1596 | struct perf_sample *sample, |
1602 | struct perf_evsel *evsel, | 1597 | struct perf_evsel *evsel, |
1603 | struct machine *machine) | 1598 | struct machine *machine) |
1604 | { | 1599 | { |
1605 | struct perf_sched *sched = container_of(tool, struct perf_sched, tool); | ||
1606 | struct pevent *pevent = sched->session->pevent; | ||
1607 | struct thread *thread = machine__findnew_thread(machine, sample->pid); | 1600 | struct thread *thread = machine__findnew_thread(machine, sample->pid); |
1608 | 1601 | ||
1609 | if (thread == NULL) { | 1602 | if (thread == NULL) { |
@@ -1617,25 +1610,18 @@ static int perf_sched__process_tracepoint_sample(struct perf_tool *tool, | |||
1617 | 1610 | ||
1618 | if (evsel->handler.func != NULL) { | 1611 | if (evsel->handler.func != NULL) { |
1619 | tracepoint_handler f = evsel->handler.func; | 1612 | tracepoint_handler f = evsel->handler.func; |
1620 | 1613 | f(tool, evsel->tp_format, sample, machine, thread); | |
1621 | if (evsel->handler.data == NULL) | ||
1622 | evsel->handler.data = pevent_find_event(pevent, | ||
1623 | evsel->attr.config); | ||
1624 | |||
1625 | f(tool, evsel->handler.data, sample, machine, thread); | ||
1626 | } | 1614 | } |
1627 | 1615 | ||
1628 | return 0; | 1616 | return 0; |
1629 | } | 1617 | } |
1630 | 1618 | ||
1631 | static struct perf_sched perf_sched = { | 1619 | static struct perf_tool perf_sched = { |
1632 | .tool = { | 1620 | .sample = perf_sched__process_tracepoint_sample, |
1633 | .sample = perf_sched__process_tracepoint_sample, | 1621 | .comm = perf_event__process_comm, |
1634 | .comm = perf_event__process_comm, | 1622 | .lost = perf_event__process_lost, |
1635 | .lost = perf_event__process_lost, | 1623 | .fork = perf_event__process_task, |
1636 | .fork = perf_event__process_task, | 1624 | .ordered_samples = true, |
1637 | .ordered_samples = true, | ||
1638 | }, | ||
1639 | }; | 1625 | }; |
1640 | 1626 | ||
1641 | static void read_events(bool destroy, struct perf_session **psession) | 1627 | static void read_events(bool destroy, struct perf_session **psession) |
@@ -1652,18 +1638,15 @@ static void read_events(bool destroy, struct perf_session **psession) | |||
1652 | }; | 1638 | }; |
1653 | struct perf_session *session; | 1639 | struct perf_session *session; |
1654 | 1640 | ||
1655 | session = perf_session__new(input_name, O_RDONLY, 0, false, | 1641 | session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_sched); |
1656 | &perf_sched.tool); | ||
1657 | if (session == NULL) | 1642 | if (session == NULL) |
1658 | die("No Memory"); | 1643 | die("No Memory"); |
1659 | 1644 | ||
1660 | perf_sched.session = session; | ||
1661 | |||
1662 | err = perf_session__set_tracepoints_handlers(session, handlers); | 1645 | err = perf_session__set_tracepoints_handlers(session, handlers); |
1663 | assert(err == 0); | 1646 | assert(err == 0); |
1664 | 1647 | ||
1665 | if (perf_session__has_traces(session, "record -R")) { | 1648 | if (perf_session__has_traces(session, "record -R")) { |
1666 | err = perf_session__process_events(session, &perf_sched.tool); | 1649 | err = perf_session__process_events(session, &perf_sched); |
1667 | if (err) | 1650 | if (err) |
1668 | die("Failed to process events, error %d", err); | 1651 | die("Failed to process events, error %d", err); |
1669 | 1652 | ||