Skip to contentSkip to conversation

perf: Make perf stat/record print fatal signals of the target program

PATCH In review Andi Kleen 2 participants 4 messages Sep 15, 2011 – Sep 16, 2011 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/3 perf: Make perf stat/record print fatal signals of the target program

From: Andi Kleen <[email protected]>

When a program crashes under perf there is no message about it, unlike when running it from bash. This can be confusing and lead to wrong actions during debugging.

Print fatal signals in perf stat/record.

Thanks to Furat Afram for finding the problem originally

---
 tools/perf/builtin-record.c |   19 +++++++++++++++++--
 tools/perf/builtin-stat.c   |    2 ++
 2 files changed, 19 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +17 -2
index 6b0519f..042117f 100644
@@ -73,6 +73,7 @@ static off_t			post_processing_offset;
 
 static struct perf_session	*session;
 static const char		*cpu_list;
+static const char               *progname;
 
 static void advance_output(size_t size)
 {
@@ -137,17 +138,29 @@ static void mmap_read(struct perf_mmap *md)
 
 static volatile int done = 0;
 static volatile int signr = -1;
+static volatile int child_finished = 0;
 
 static void sig_handler(int sig)
 {
+	if (sig == SIGCHLD)
+		child_finished = 1;
+
 	done = 1;
 	signr = sig;
 }
 
 static void sig_atexit(void)
 {
-	if (child_pid > 0)
-		kill(child_pid, SIGTERM);
+	int status;
+
+	if (child_pid > 0) {
+		if (!child_finished)
+			kill(child_pid, SIGTERM);
+
+		wait(&status);
+		if (WIFSIGNALED(status))
+			psignal(WTERMSIG(status), progname);
+	}
 
 	if (signr == -1 || signr == SIGUSR1)
 		return;
@@ -445,6 +458,8 @@ static int __cmd_record(int argc, const char **argv)
 	char buf;
 	struct machine *machine;
 
+	progname = argv[0];
+
 	page_size = sysconf(_SC_PAGE_SIZE);
 
 	atexit(sig_atexit);
tools/perf/builtin-stat.c +2 -0
index 5deb17d..69becc3 100644
@@ -487,6 +487,8 @@ static int run_perf_stat(int argc __used, const char **argv)
 	if (forks) {
 		close(go_pipe[1]);
 		wait(&status);
+		if (WIFSIGNALED(status))
+			psignal(WTERMSIG(status), argv[0]);
 	} else {
 		while(!done) sleep(1);
 	}
Signature · 1 line
1.7.4.4
author
#1 lore raw

PATCH 2/3 perf: Support setting the disassembler style

From: Andi Kleen <[email protected]>

Add -M option to report/annotate to pass directly to objdump. This allows to use -M intel for intel style disassembler syntax, which is useful for people who are very used to the Intel syntax.

---
 tools/perf/Documentation/perf-annotate.txt |    3 +++
 tools/perf/Documentation/perf-report.txt   |    3 +++
 tools/perf/builtin-annotate.c              |    2 ++
 tools/perf/builtin-report.c                |    2 ++
 tools/perf/util/annotate.c                 |    6 +++++-
 tools/perf/util/annotate.h                 |    2 ++
 6 files changed, 17 insertions(+), 1 deletions(-)
tools/perf/Documentation/perf-annotate.txt +3 -0
index 85c5f02..4a42c31 100644
@@ -72,6 +72,9 @@ OPTIONS
 	CPUs are specified with -: 0-2. Default is to report samples on all
 	CPUs.
 
+-M::
+--disassembler-style=:: Set disassembler style for objdump.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
tools/perf/Documentation/perf-report.txt +3 -0
index 04253c0..0407c8c 100644
@@ -134,6 +134,9 @@ OPTIONS
 	CPUs are specified with -: 0-2. Default is to report samples on all
 	CPUs.
 
+-m::
+--disassembler-style=:: Set disassembler style for objdump.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1]
tools/perf/builtin-annotate.c +2 -0
index 555aefd..5b0a0ac 100644
@@ -267,6 +267,8 @@ static const struct option options[] = {
 	OPT_BOOLEAN('P', "full-paths", &full_paths,
 		    "Don't shorten the displayed pathnames"),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
+	OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
+		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_END()
 };
 
tools/perf/builtin-report.c +2 -0
index d7ff277..a0673ee 100644
@@ -487,6 +487,8 @@ static const struct option options[] = {
 	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
 		    "Look for files with symbols relative to this directory"),
 	OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
+	OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
+		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_END()
 };
 
tools/perf/util/annotate.c +5 -1
index e01af2b..6495966 100644
@@ -16,6 +16,8 @@
 #include "annotate.h"
 #include <pthread.h>
 
+const char 	*disassembler_style;
+
 int symbol__annotate_init(struct map *map __used, struct symbol *sym)
 {
 	struct annotation *notes = symbol__annotation(sym);
@@ -323,8 +325,10 @@ fallback:
 		 dso, dso->long_name, sym, sym->name);
 
 	snprintf(command, sizeof(command),
-		 "objdump --start-address=0x%016" PRIx64
+		 "objdump %s%s --start-address=0x%016" PRIx64
 		 " --stop-address=0x%016" PRIx64 " -dS -C %s|grep -v %s|expand",
+		 disassembler_style ? "-M " : "",
+		 disassembler_style ? disassembler_style : "",
 		 map__rip_2objdump(map, sym->start),
 		 map__rip_2objdump(map, sym->end),
 		 symfs_filename, filename);
tools/perf/util/annotate.h +2 -0
index c2c2868..6ede128 100644
@@ -100,4 +100,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 			 int refresh);
 #endif
 
+extern const char	*disassembler_style;
+
 #endif	/* __PERF_ANNOTATE_H */
Signature · 1 line
1.7.4.4
#2 lore raw

Re: [PATCH 2/3] perf: Support setting the disassembler style

Em Thu, Sep 15, 2011 at 02:31:41PM -0700, Andi Kleen escreveu:

Quoted 12 lines

From: Andi Kleen <[email protected]>

Add -M option to report/annotate to pass directly to objdump. This allows to use -M intel for intel style disassembler syntax, which is useful for people who are very used to the Intel syntax.

linkperf:perf-record[1], linkperf:perf-report[1]

tools/perf/Documentation/perf-report.txt +0 -0
index 04253c0..0407c8c 100644

tools/perf/Documentation/perf-report.txt OPTIONS · line 139

Quoted 6 lines
tools/perf/Documentation/perf-report.txt +3 -0
@@ -134,6 +134,9 @@ OPTIONS
 	CPUs are specified with -: 0-2. Default is to report samples on all
 	CPUs.
 
+-m::
+--disassembler-style=:: Set disassembler style for objdump.
+

s/-m/-M/g

And adjusted it to cope with what is in perf/core, namely:

https://github.com/acmel/linux/commit/3e6a2a7f3b9d0e521bb3284573b696d0cbe1952c

<quote>
perf annotate: Make output more readable
This patch adds two new options to perf annotate:
- --no-asm-raw : Do not display raw instruction encodings
- --no-source : Do not interleave source code with assembly code

We believe those options make the output of annotate more readable. </>

- Arnaldo

author
#3 lore raw

PATCH 3/3 perf: Clarify -c help text

In reply to Andi Kleen

From: Andi Kleen <[email protected]>

Clarify what perf record/top -c actually does in the help text.

---
 tools/perf/Documentation/perf-record.txt |    6 +++---
 tools/perf/Documentation/perf-top.txt    |    2 +-
 tools/perf/builtin-record.c              |    2 +-
 tools/perf/builtin-top.c                 |    2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-record.txt +3 -3
index 5a520f8..f636cc8 100644
@@ -72,9 +72,9 @@ OPTIONS
 --force::
 	Overwrite existing data file. (deprecated)
 
--c::
---count=::
-	Event period to sample.
+-cN::
+--count=N::
+	Sample event every N occurrences.
 
 -o::
 --output=::
tools/perf/Documentation/perf-top.txt +1 -1
index f6eb1cd..b6043b0 100644
@@ -23,7 +23,7 @@ OPTIONS
 
 -c <count>::
 --count=<count>::
-	Event period to sample.
+	Sample event every COUNT occurrences.
 
 -C <cpu-list>::
 --cpu=<cpu>::
tools/perf/builtin-record.c +1 -1
index 042117f..22a9a27 100644
@@ -761,7 +761,7 @@ const struct option record_options[] = {
 		    "list of cpus to monitor"),
 	OPT_BOOLEAN('f', "force", &force,
 			"overwrite existing data file (deprecated)"),
-	OPT_U64('c', "count", &user_interval, "event period to sample"),
+	OPT_U64('c', "count", &user_interval, "sample every COUNTS events"),
 	OPT_STRING('o', "output", &output_name, "file",
 		    "output file name"),
 	OPT_BOOLEAN('i', "no-inherit", &no_inherit,
tools/perf/builtin-top.c +1 -1
index a43433f..79bfb5d 100644
@@ -992,7 +992,7 @@ static const struct option options[] = {
 		     "event selector. use 'perf list' to list available events",
 		     parse_events_option),
 	OPT_INTEGER('c', "count", &default_interval,
-		    "event period to sample"),
+		    "sample event every N occurrences"),
 	OPT_INTEGER('p', "pid", &top.target_pid,
 		    "profile events on existing process id"),
 	OPT_INTEGER('t', "tid", &top.target_tid,
Signature · 1 line
1.7.4.4