2009-08-17 14:18:08 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
|
|
|
|
#include "util/util.h"
|
|
|
|
#include "util/cache.h"
|
|
|
|
#include "util/symbol.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/header.h"
|
|
|
|
|
|
|
|
#include "util/parse-options.h"
|
|
|
|
|
|
|
|
#include "perf.h"
|
|
|
|
#include "util/debug.h"
|
|
|
|
|
|
|
|
#include "util/trace-event.h"
|
2009-10-07 10:47:31 +00:00
|
|
|
#include "util/data_map.h"
|
2009-08-17 14:18:08 +00:00
|
|
|
|
|
|
|
static char const *input_name = "perf.data";
|
|
|
|
|
|
|
|
static unsigned long total = 0;
|
|
|
|
static unsigned long total_comm = 0;
|
|
|
|
|
|
|
|
static struct perf_header *header;
|
|
|
|
static u64 sample_type;
|
|
|
|
|
2009-10-07 10:47:31 +00:00
|
|
|
static char *cwd;
|
|
|
|
static int cwdlen;
|
|
|
|
|
2009-08-17 14:18:08 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
process_comm_event(event_t *event, unsigned long offset, unsigned long head)
|
|
|
|
{
|
2009-10-13 14:16:29 +00:00
|
|
|
struct thread *thread = threads__findnew(event->comm.pid);
|
2009-08-17 14:18:08 +00:00
|
|
|
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 10:02:48 +00:00
|
|
|
dump_printf("%p [%p]: PERF_RECORD_COMM: %s:%d\n",
|
2009-08-17 14:18:08 +00:00
|
|
|
(void *)(offset + head),
|
|
|
|
(void *)(long)(event->header.size),
|
|
|
|
event->comm.comm, event->comm.pid);
|
|
|
|
|
|
|
|
if (thread == NULL ||
|
|
|
|
thread__set_comm(thread, event->comm.comm)) {
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 10:02:48 +00:00
|
|
|
dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
|
2009-08-17 14:18:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
total_comm++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
process_sample_event(event_t *event, unsigned long offset, unsigned long head)
|
|
|
|
{
|
|
|
|
u64 ip = event->ip.ip;
|
2009-09-03 10:00:22 +00:00
|
|
|
u64 timestamp = -1;
|
2009-09-02 18:20:38 +00:00
|
|
|
u32 cpu = -1;
|
2009-08-17 14:18:08 +00:00
|
|
|
u64 period = 1;
|
|
|
|
void *more_data = event->ip.__more_data;
|
2009-10-13 14:16:29 +00:00
|
|
|
struct thread *thread = threads__findnew(event->ip.pid);
|
2009-08-17 14:18:08 +00:00
|
|
|
|
2009-09-03 10:00:22 +00:00
|
|
|
if (sample_type & PERF_SAMPLE_TIME) {
|
|
|
|
timestamp = *(u64 *)more_data;
|
|
|
|
more_data += sizeof(u64);
|
|
|
|
}
|
|
|
|
|
2009-09-02 18:20:38 +00:00
|
|
|
if (sample_type & PERF_SAMPLE_CPU) {
|
|
|
|
cpu = *(u32 *)more_data;
|
|
|
|
more_data += sizeof(u32);
|
|
|
|
more_data += sizeof(u32); /* reserved */
|
|
|
|
}
|
|
|
|
|
2009-08-17 14:18:08 +00:00
|
|
|
if (sample_type & PERF_SAMPLE_PERIOD) {
|
|
|
|
period = *(u64 *)more_data;
|
|
|
|
more_data += sizeof(u64);
|
|
|
|
}
|
|
|
|
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 10:02:48 +00:00
|
|
|
dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
|
2009-08-17 14:18:08 +00:00
|
|
|
(void *)(offset + head),
|
|
|
|
(void *)(long)(event->header.size),
|
|
|
|
event->header.misc,
|
|
|
|
event->ip.pid, event->ip.tid,
|
|
|
|
(void *)(long)ip,
|
|
|
|
(long long)period);
|
|
|
|
|
|
|
|
if (thread == NULL) {
|
|
|
|
eprintf("problem processing %d event, skipping it.\n",
|
|
|
|
event->header.type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-17 06:43:17 +00:00
|
|
|
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
|
|
|
|
|
2009-08-17 14:18:08 +00:00
|
|
|
if (sample_type & PERF_SAMPLE_RAW) {
|
|
|
|
struct {
|
|
|
|
u32 size;
|
|
|
|
char data[0];
|
|
|
|
} *raw = more_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: better resolve from pid from the struct trace_entry
|
|
|
|
* field, although it should be the same than this perf
|
|
|
|
* event pid
|
|
|
|
*/
|
2009-09-03 10:00:22 +00:00
|
|
|
print_event(cpu, raw->data, raw->size, timestamp, thread->comm);
|
2009-08-17 14:18:08 +00:00
|
|
|
}
|
|
|
|
total += period;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-07 10:47:31 +00:00
|
|
|
static int sample_type_check(u64 type)
|
2009-08-17 14:18:08 +00:00
|
|
|
{
|
2009-10-07 10:47:31 +00:00
|
|
|
sample_type = type;
|
2009-08-17 14:18:08 +00:00
|
|
|
|
2009-10-07 10:47:31 +00:00
|
|
|
if (!(sample_type & PERF_SAMPLE_RAW)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"No trace sample to read. Did you call perf record "
|
|
|
|
"without -R?");
|
2009-08-17 14:18:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-07 10:47:31 +00:00
|
|
|
static struct perf_file_handler file_handler = {
|
|
|
|
.process_sample_event = process_sample_event,
|
|
|
|
.process_comm_event = process_comm_event,
|
|
|
|
.sample_type_check = sample_type_check,
|
|
|
|
};
|
|
|
|
|
2009-08-17 14:18:08 +00:00
|
|
|
static int __cmd_trace(void)
|
|
|
|
{
|
2009-10-13 14:16:29 +00:00
|
|
|
register_idle_thread();
|
2009-10-07 10:47:31 +00:00
|
|
|
register_perf_file_handler(&file_handler);
|
2009-08-17 14:18:08 +00:00
|
|
|
|
2009-10-07 10:47:31 +00:00
|
|
|
return mmap_dispatch_perf_file(&header, input_name, 0, 0, &cwdlen, &cwd);
|
2009-08-17 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const annotate_usage[] = {
|
|
|
|
"perf trace [<options>] <command>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
|
|
|
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
|
|
|
|
"dump raw trace in ASCII"),
|
|
|
|
OPT_BOOLEAN('v', "verbose", &verbose,
|
|
|
|
"be more verbose (show symbol address, etc)"),
|
2009-10-14 19:43:42 +00:00
|
|
|
OPT_BOOLEAN('l', "latency", &latency_format,
|
|
|
|
"show latency attributes (irqs/preemption disabled, etc)"),
|
2009-08-21 18:56:03 +00:00
|
|
|
OPT_END()
|
2009-08-17 14:18:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int cmd_trace(int argc, const char **argv, const char *prefix __used)
|
|
|
|
{
|
|
|
|
symbol__init();
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, options, annotate_usage, 0);
|
|
|
|
if (argc) {
|
|
|
|
/*
|
|
|
|
* Special case: if there's an argument left then assume tha
|
|
|
|
* it's a symbol filter:
|
|
|
|
*/
|
|
|
|
if (argc > 1)
|
|
|
|
usage_with_options(annotate_usage, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_pager();
|
|
|
|
|
|
|
|
return __cmd_trace();
|
|
|
|
}
|