Skip to contentSkip to conversation

perf tools: fixes for Android

PATCH New Irina Tirdea 1 participant 7 messages Oct 22, 2012 perf events

lore
Share & tools
lore
#0 lore raw

v5 cover perf tools: fixes for Android

From: Irina Tirdea <[email protected]>

This is version 5 for the Android fixes. Previous version can be found at [1].

The patches are on top of current perf/core branch from Arnaldo's git tree (git.kernel.org/pub/scm/linux/kernel/git/acme/linux).

Changes v4->v5:
() make PERF_TMP_DIR and PERF_SHELL_PATH available to all source files (patch 1 & 2) (Arnaldo)
() split addr2line changes in 2 patches (patch 3 & 5) (Arnaldo)

Changes v3->v4:
() patch 1: fixed compilation issue when calling make from kernel root directory () patch 4: renamed try_binutils_path to perf_session_env__lookup_binutils_path () patch 4: replaced scnprintf + strdup with asprintf
() patch 4: handle errors and print messages in case cross-built objdump is not found
() patch 3,5: split patch with addr2line changes in 2 patches
() patch 6: set default ret to -ENOMEM in order to avoid setting it every time

Thanks,
Irina

[1] https://lkml.org/lkml/2012/10/15/633

Irina Tirdea (6):
perf tools: configure tmp path at build time perf tools: configure shell path at compile time perf tools: add --addr2line command line option perf tools: Try to find cross-built addr2line path perf tools: fix using --sysroot with addr2line perf stat: implement --big-num grouping

 tools/perf/Documentation/android.txt       |   19 +++++
 tools/perf/Documentation/jit-interface.txt |    4 +-
 tools/perf/Documentation/perf-annotate.txt |    2 +
 tools/perf/Documentation/perf-report.txt   |    2 +
 tools/perf/Makefile                        |   12 +++-
 tools/perf/arch/common.c                   |    6 ++
 tools/perf/arch/common.h                   |    2 +
 tools/perf/builtin-annotate.c              |    9 +++
 tools/perf/builtin-help.c                  |    2 +-
 tools/perf/builtin-report.c                |    9 +++
 tools/perf/builtin-script.c                |   12 ++--
 tools/perf/builtin-stat.c                  |  106 ++++++++++++++++++++++++++--
 tools/perf/config/feature-tests.mak        |   18 +++++
 tools/perf/perf-archive.sh                 |   13 +++-
 tools/perf/util/annotate.c                 |   13 +++-
 tools/perf/util/dso-test-data.c            |    2 +-
 tools/perf/util/map.c                      |    3 +-
 tools/perf/util/pmu.c                      |    2 +-
 tools/perf/util/sort.c                     |   17 ++++-
 tools/perf/util/symbol.c                   |    4 +-
 tools/perf/util/trace-event-info.c         |    2 +-
 tools/perf/util/vdso.c                     |    2 +-
 22 files changed, 233 insertions(+), 28 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 1/6 perf tools: configure tmp path at build time

From: Irina Tirdea <[email protected]>

Temporary perf files are hardcoded to point to /tmp. Android does not have a /tmp directory so it needs to set this path at compile time.

Add a compile-time definition (PERF_TMP_DIR) in the Makefile that sets the path to temp directory. By default it points to /tmp.

---
 tools/perf/Documentation/android.txt       |    1 +
 tools/perf/Documentation/jit-interface.txt |    4 +++-
 tools/perf/Makefile                        |    4 +++-
 tools/perf/perf-archive.sh                 |   13 +++++++++++--
 tools/perf/util/dso-test-data.c            |    2 +-
 tools/perf/util/map.c                      |    3 ++-
 tools/perf/util/pmu.c                      |    2 +-
 tools/perf/util/sort.c                     |    4 +++-
 tools/perf/util/symbol.c                   |    4 +++-
 tools/perf/util/trace-event-info.c         |    2 +-
 tools/perf/util/vdso.c                     |    2 +-
 11 files changed, 30 insertions(+), 11 deletions(-)
tools/perf/Documentation/android.txt +1 -0
index a39dbbb..24fd01c 100644
@@ -68,6 +68,7 @@ Some perf features need environment variables to run properly.
 You need to set these before running perf on the target:
   adb shell
   # PERF_PAGER=cat
+  # PERF_TMP_DIR=/data/local/tmp
 
 IV. Run perf
 ------------------------------------------------
tools/perf/Documentation/jit-interface.txt +3 -1
index a8656f5..10cb6ec 100644
@@ -1,7 +1,9 @@
 perf supports a simple JIT interface to resolve symbols for dynamic code generated
 by a JIT.
 
-The JIT has to write a /tmp/perf-%d.map  (%d = pid of process) file
+The JIT has to write a $PERF_TMP_DIR/perf-%d.map  (%d = pid of process) file.
+You can set $PERF_TMP_DIR at compile time in the Makefile.
+By default it is /tmp.
 
 This is a text file.
 
tools/perf/Makefile +3 -1
index 76190a7..5429b5b 100644
@@ -141,6 +141,7 @@ sysconfdir = $(prefix)/etc
 ETC_PERFCONFIG = etc/perfconfig
 endif
 lib = lib
+PERF_TMP_DIR = /tmp
 
 export prefix bindir sharedir sysconfdir
 
@@ -169,7 +170,7 @@ endif
 
 ### --- END CONFIGURATION SECTION ---
 
-BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DPERF_TMP_DIR='"$(PERF_TMP_DIR)"'
 BASIC_LDFLAGS =
 
 ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
@@ -177,6 +178,7 @@ ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
 	EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
 	EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
 	BASIC_CFLAGS += -I.
+	PERF_TMP_DIR = /data/local/tmp
 endif
 
 # Guard against environment variables
tools/perf/perf-archive.sh +11 -2
index e919306..058c3b7 100644
@@ -18,7 +18,16 @@ else
         PERF_BUILDID_DIR=$PERF_BUILDID_DIR/
 fi
 
-BUILDIDS=$(mktemp /tmp/perf-archive-buildids.XXXXXX)
+#
+# PERF_TMP_DIR environment variable set by perf
+# path to temp directory, default to /tmp
+#
+if [ -z $PERF_TMP_DIR ]; then
+	PERF_TMP_DIR=/tmp
+fi
+
+
+BUILDIDS=$(mktemp $PERF_TMP_DIR/perf-archive-buildids.XXXXXX)
 NOBUILDID=0000000000000000000000000000000000000000
 
 perf buildid-list -i $PERF_DATA --with-hits | grep -v "^$NOBUILDID " > $BUILDIDS
@@ -28,7 +37,7 @@ if [ ! -s $BUILDIDS ] ; then
 	exit 1
 fi
 
-MANIFEST=$(mktemp /tmp/perf-archive-manifest.XXXXXX)
+MANIFEST=$(mktemp $PERF_TMP_DIR/perf-archive-manifest.XXXXXX)
 PERF_BUILDID_LINKDIR=$(readlink -f $PERF_BUILDID_DIR)/
 
 cut -d ' ' -f 1 $BUILDIDS | \
tools/perf/util/dso-test-data.c +1 -1
index c6caede..ca81e65 100644
@@ -18,7 +18,7 @@ do { \
 
 static char *test_file(int size)
 {
-	static char buf_templ[] = "/tmp/test-XXXXXX";
+	static char buf_templ[] = PERF_TMP_DIR "/test-XXXXXX";
 	char *templ = buf_templ;
 	int fd, i;
 	unsigned char *buf;
tools/perf/util/map.c +2 -1
index 6109fa4..4e69b57 100644
@@ -59,7 +59,8 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
 		no_dso = is_no_dso_memory(filename);
 
 		if (anon) {
-			snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid);
+			snprintf(newfilename, sizeof(newfilename),
+				 PERF_TMP_DIR "/perf-%d.map", pid);
 			filename = newfilename;
 		}
 
tools/perf/util/pmu.c +1 -1
index 8a2229d..5ebde18 100644
@@ -637,7 +637,7 @@ static char *test_format_dir_get(void)
 	static char dir[PATH_MAX];
 	unsigned int i;
 
-	snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
+	snprintf(dir, PATH_MAX, PERF_TMP_DIR "/perf-pmu-test-format-XXXXXX");
 	if (!mkdtemp(dir))
 		return NULL;
 
tools/perf/util/sort.c +3 -1
index cfd1c0f..d579406 100644
@@ -263,7 +263,9 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
 	if (!self->ms.map)
 		goto out_ip;
 
-	if (!strncmp(self->ms.map->dso->long_name, "/tmp/perf-", 10))
+	if (!strncmp
+	    (self->ms.map->dso->long_name, PERF_TMP_DIR "/perf-",
+	     strlen(PERF_TMP_DIR "/perf-")))
 		goto out_ip;
 
 	snprintf(cmd, sizeof(cmd), "addr2line -e %s %016" PRIx64,
tools/perf/util/symbol.c +3 -1
index e2e8c69..d8aca82 100644
@@ -1051,7 +1051,9 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 
 	dso->adjust_symbols = 0;
 
-	if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
+	if (strncmp
+	    (dso->name, PERF_TMP_DIR "/perf-",
+	     strlen(PERF_TMP_DIR "/perf-")) == 0) {
 		struct stat st;
 
 		if (lstat(dso->name, &st) < 0)
tools/perf/util/trace-event-info.c +1 -1
index a8d81c3..e50ea61 100644
@@ -481,7 +481,7 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
 		int temp_fd;
 
 		snprintf(tdata->temp_file, sizeof(tdata->temp_file),
-			 "/tmp/perf-XXXXXX");
+			 PERF_TMP_DIR "/perf-XXXXXX");
 		if (!mkstemp(tdata->temp_file))
 			die("Can't make temp file");
 
tools/perf/util/vdso.c +1 -1
index e60951f..8b9613b 100644
@@ -14,7 +14,7 @@
 #include "linux/string.h"
 
 static bool vdso_found;
-static char vdso_file[] = "/tmp/perf-vdso.so-XXXXXX";
+static char vdso_file[] = PERF_TMP_DIR "/perf-vdso.so-XXXXXX";
 
 static int find_vdso_map(void **start, void **end)
 {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v5 2/6 perf tools: configure shell path at compile time

In reply to Irina Tirdea

From: Irina Tirdea <[email protected]>

Shell path /bin/sh is hardcoded in various places in perf. Android has a different folder structure and does not have /bin/sh.

Set the shell path at compile time in the Makefile by setting PERF_SHELL_PATH. By default it is set to /bin/sh.

---
 tools/perf/Makefile         |    4 +++-
 tools/perf/builtin-help.c   |    2 +-
 tools/perf/builtin-script.c |   12 ++++++------
 3 files changed, 10 insertions(+), 8 deletions(-)
tools/perf/Makefile +3 -1
index 5429b5b..78fc6b9 100644
@@ -142,6 +142,7 @@ ETC_PERFCONFIG = etc/perfconfig
 endif
 lib = lib
 PERF_TMP_DIR = /tmp
+PERF_SHELL_PATH = /bin/sh
 
 export prefix bindir sharedir sysconfdir
 
@@ -170,7 +171,7 @@ endif
 
 ### --- END CONFIGURATION SECTION ---
 
-BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DPERF_TMP_DIR='"$(PERF_TMP_DIR)"'
+BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DPERF_TMP_DIR='"$(PERF_TMP_DIR)"' -DPERF_SHELL_PATH='"$(PERF_SHELL_PATH)"'
 BASIC_LDFLAGS =
 
 ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
@@ -179,6 +180,7 @@ ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
 	EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
 	BASIC_CFLAGS += -I.
 	PERF_TMP_DIR = /data/local/tmp
+	PERF_SHELL_PATH = /system/bin/sh
 endif
 
 # Guard against environment variables
tools/perf/builtin-help.c +1 -1
index 411ee56..542b752 100644
@@ -154,7 +154,7 @@ static void exec_man_cmd(const char *cmd, const char *page)
 {
 	struct strbuf shell_cmd = STRBUF_INIT;
 	strbuf_addf(&shell_cmd, "%s %s", cmd, page);
-	execl("/bin/sh", "sh", "-c", shell_cmd.buf, NULL);
+	execl(PERF_SHELL_PATH, "sh", "-c", shell_cmd.buf, NULL);
 	warning("failed to exec '%s': %s", cmd, strerror(errno));
 }
 
tools/perf/builtin-script.c +6 -6
index 04ceb07..d0d3a21 100644
@@ -1320,7 +1320,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 				goto out;
 			}
 
-			__argv[j++] = "/bin/sh";
+			__argv[j++] = PERF_SHELL_PATH;
 			__argv[j++] = rec_script_path;
 			if (system_wide)
 				__argv[j++] = "-a";
@@ -1331,7 +1331,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 				__argv[j++] = argv[i];
 			__argv[j++] = NULL;
 
-			execvp("/bin/sh", (char **)__argv);
+			execvp(PERF_SHELL_PATH, (char **)__argv);
 			free(__argv);
 			exit(-1);
 		}
@@ -1347,7 +1347,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		}
 
 		j = 0;
-		__argv[j++] = "/bin/sh";
+		__argv[j++] = PERF_SHELL_PATH;
 		__argv[j++] = rep_script_path;
 		for (i = 1; i < rep_args + 1; i++)
 			__argv[j++] = argv[i];
@@ -1355,7 +1355,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		__argv[j++] = "-";
 		__argv[j++] = NULL;
 
-		execvp("/bin/sh", (char **)__argv);
+		execvp(PERF_SHELL_PATH, (char **)__argv);
 		free(__argv);
 		exit(-1);
 	}
@@ -1384,7 +1384,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			goto out;
 		}
 
-		__argv[j++] = "/bin/sh";
+		__argv[j++] = PERF_SHELL_PATH;
 		__argv[j++] = script_path;
 		if (system_wide)
 			__argv[j++] = "-a";
@@ -1392,7 +1392,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 			__argv[j++] = argv[i];
 		__argv[j++] = NULL;
 
-		execvp("/bin/sh", (char **)__argv);
+		execvp(PERF_SHELL_PATH, (char **)__argv);
 		free(__argv);
 		exit(-1);
 	}
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v5 3/6 perf tools: add --addr2line command line option

In reply to Irina Tirdea

From: Irina Tirdea <[email protected]>

When analyzing data recorded on a target with a different architecture than the host, we must use addr2line from the toolchain for that architecture.

Add a command line option to allow setting addr2line at runtime.

---
 tools/perf/Documentation/perf-annotate.txt |    2 ++
 tools/perf/Documentation/perf-report.txt   |    2 ++
 tools/perf/builtin-annotate.c              |    3 +++
 tools/perf/builtin-report.c                |    3 +++
 tools/perf/util/annotate.c                 |    5 ++++-
 tools/perf/util/sort.c                     |    3 ++-
 tools/perf/util/sort.h                     |    1 +
 7 files changed, 17 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-annotate.txt +2 -0
index c8ffd9f..177906a 100644
@@ -87,6 +87,8 @@ OPTIONS
 
 --objdump=<path>::
         Path to objdump binary.
+--addr2line=<path>::
+        Path to addr2line binary.
 
 SEE ALSO
 --------
tools/perf/Documentation/perf-report.txt +2 -0
index f4d91be..b6bb26e 100644
@@ -170,6 +170,8 @@ OPTIONS
 
 --objdump=<path>::
         Path to objdump binary.
+--addr2line=<path>::
+        Path to addr2line binary.
 
 SEE ALSO
 --------
tools/perf/builtin-annotate.c +3 -0
index c4bb645..e4df5da 100644
@@ -292,6 +292,9 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_STRING(0, "objdump", &objdump_path, "path",
 		   "objdump binary to use for disassembly and annotations"),
+	OPT_STRING(0, "addr2line", &addr2line_path, "path",
+		   "addr2line binary to use for obtaining "
+		   "file names and line numbers"),
 	OPT_END()
 	};
 
tools/perf/builtin-report.c +3 -0
index 90d1162..9c0fe68 100644
@@ -642,6 +642,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "use branch records for histogram filling", parse_branch_mode),
 	OPT_STRING(0, "objdump", &objdump_path, "path",
 		   "objdump binary to use for disassembly and annotations"),
+	OPT_STRING(0, "addr2line", &addr2line_path, "path",
+		   "addr2line binary to use for obtaining "
+		   "file names and line numbers"),
 	OPT_END()
 	};
 
tools/perf/util/annotate.c +4 -1
index f0a9103..9c0fa54 100644
@@ -18,6 +18,7 @@
 
 const char 	*disassembler_style;
 const char	*objdump_path;
+const char	*addr2line_path;
 
 static struct ins *ins__find(const char *name);
 static int disasm_line__parse(char *line, char **namep, char **rawp);
@@ -915,7 +916,9 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 			continue;
 
 		offset = start + i;
-		sprintf(cmd, "addr2line -e %s %016" PRIx64, filename, offset);
+		sprintf(cmd, "%s -e %s %016" PRIx64,
+			addr2line_path ? addr2line_path : "addr2line",
+			filename, offset);
 		fp = popen(cmd, "r");
 		if (!fp)
 			continue;
tools/perf/util/sort.c +2 -1
index d579406..19cc046 100644
@@ -268,7 +268,8 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
 	     strlen(PERF_TMP_DIR "/perf-")))
 		goto out_ip;
 
-	snprintf(cmd, sizeof(cmd), "addr2line -e %s %016" PRIx64,
+	snprintf(cmd, sizeof(cmd), "%s -e %s %016" PRIx64,
+		 addr2line_path ? addr2line_path : "addr2line",
 		 self->ms.map->dso->long_name, self->ip);
 	fp = popen(cmd, "r");
 	if (!fp)
tools/perf/util/sort.h +1 -0
index 13761d8..c8e58f6 100644
@@ -139,6 +139,7 @@ struct sort_entry {
 
 extern struct sort_entry sort_thread;
 extern struct list_head hist_entry__sort_list;
+extern const char *addr2line_path;
 
 void setup_sorting(const char * const usagestr[], const struct option *opts);
 extern int sort_dimension__add(const char *);
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v5 4/6 perf tools: Try to find cross-built addr2line path

In reply to Irina Tirdea

From: Irina Tirdea <[email protected]>

As we have architecture information of saved perf.data file, we can also try to find cross-built addr2line path. The predefined triplets include support for Android (arm, x86 and mips architectures).

---
 tools/perf/Documentation/android.txt |   18 ++++++++++++++++++
 tools/perf/arch/common.c             |    6 ++++++
 tools/perf/arch/common.h             |    2 ++
 tools/perf/builtin-annotate.c        |    6 ++++++
 tools/perf/builtin-report.c          |    6 ++++++
 tools/perf/util/sort.c               |    1 +
 tools/perf/util/sort.h               |    1 -
 7 files changed, 39 insertions(+), 1 deletion(-)
tools/perf/Documentation/android.txt +18 -0
index 24fd01c..c2a8017 100644
@@ -74,3 +74,21 @@ IV. Run perf
 ------------------------------------------------
 Run perf on your device/emulator to which you previously connected using adb:
   # ./data/perf
+
+V. Analyze data recorded in Android on the host
+------------------------------------------------
+perf report and perf annotate use objdump and addr2line tools from Linux.
+For analyzing data recorded for a different architecture you need to use the
+versions provided in the toolchain for that architecture. The detection of the
+proper toolchain is done at runtime; all you need to do is set some environment
+variables before running perf annotate/report:
+1. set CROSS_COMPILE
+  export CROSS_COMPILE=${NDK_TOOLCHAIN}
+or
+2. add the path to the toolchain to PATH
+  export PATH=$PATH:${ANDROID_TOOLCHAIN}
+or
+3. set the Android environment if you have the source tree
+(this will set $PATH for you as mentioned above)
+  source build/envsetup.sh
+  lunch
tools/perf/arch/common.c +6 -0
index 2367b25..18ea475 100644
@@ -176,3 +176,9 @@ int perf_session_env__lookup_objdump(struct perf_session_env *env)
 	return perf_session_env__lookup_binutils_path(env, "objdump",
 						      &objdump_path);
 }
+
+int perf_session_env__lookup_addr2line(struct perf_session_env *env)
+{
+	return perf_session_env__lookup_binutils_path(env, "addr2line",
+						      &addr2line_path);
+}
tools/perf/arch/common.h +2 -0
index ede246e..e78cebd 100644
@@ -4,7 +4,9 @@
 #include "../util/session.h"
 
 extern const char *objdump_path;
+extern const char *addr2line_path;
 
 int perf_session_env__lookup_objdump(struct perf_session_env *env);
+int perf_session_env__lookup_addr2line(struct perf_session_env *env);
 
 #endif /* ARCH_PERF_COMMON_H */
tools/perf/builtin-annotate.c +6 -0
index e4df5da..0f46ec6 100644
@@ -193,6 +193,12 @@ static int __cmd_annotate(struct perf_annotate *ann)
 			goto out_delete;
 	}
 
+	if (!addr2line_path) {
+		ret = perf_session_env__lookup_addr2line(&session->header.env);
+		if (ret)
+			goto out_delete;
+	}
+
 	ret = perf_session__process_events(session, &ann->tool);
 	if (ret)
 		goto out_delete;
tools/perf/builtin-report.c +6 -0
index 9c0fe68..692462c 100644
@@ -682,6 +682,12 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 			goto error;
 	}
 
+	if (!addr2line_path) {
+		ret = perf_session_env__lookup_addr2line(&session->header.env);
+		if (ret)
+			goto error;
+	}
+
 	if (sort__branch_mode == -1 && has_br_stack)
 		sort__branch_mode = 1;
 
tools/perf/util/sort.c +1 -0
index 19cc046..f014bfa 100644
@@ -1,5 +1,6 @@
 #include "sort.h"
 #include "hist.h"
+#include "../arch/common.h"
 
 regex_t		parent_regex;
 const char	default_parent_pattern[] = "^sys_|^do_page_fault";
tools/perf/util/sort.h +0 -1
index c8e58f6..13761d8 100644
@@ -139,7 +139,6 @@ struct sort_entry {
 
 extern struct sort_entry sort_thread;
 extern struct list_head hist_entry__sort_list;
-extern const char *addr2line_path;
 
 void setup_sorting(const char * const usagestr[], const struct option *opts);
 extern int sort_dimension__add(const char *);
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v5 5/6 perf tools: fix using --sysroot with addr2line

In reply to Irina Tirdea

From: Irina Tirdea <[email protected]>

When cross-compiling --sysroot can be used to point to the directory with header files and libraries for the target architecture.

perf annotate -l and perf report --sort srcline call addr2line to get the source line number. addr2line will not prefix the libraries with sysroot and the symbols will not be found:
i686-linux-android-addr2line: '/system/lib/libpixelflinger.so': No such file

Add the sysroot prefix for addr2line so that the libraries are found.

---
 tools/perf/util/annotate.c |   10 +++++++++-
 tools/perf/util/sort.c     |    9 ++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)
tools/perf/util/annotate.c +9 -1
index 9c0fa54..bf5573f 100644
@@ -895,10 +895,18 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 	struct source_line *src_line;
 	struct annotation *notes = symbol__annotation(sym);
 	struct sym_hist *h = annotation__histogram(notes, evidx);
+	char symfs_filename[PATH_MAX];
 
 	if (!h->sum)
 		return 0;
 
+	snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
+		symbol_conf.symfs, filename);
+	if (access(symfs_filename, R_OK)) {
+		snprintf(symfs_filename, sizeof(symfs_filename), "%s",
+			 filename);
+	}
+
 	src_line = notes->src->lines = calloc(len, sizeof(struct source_line));
 	if (!notes->src->lines)
 		return -1;
@@ -918,7 +926,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 		offset = start + i;
 		sprintf(cmd, "%s -e %s %016" PRIx64,
 			addr2line_path ? addr2line_path : "addr2line",
-			filename, offset);
+			symfs_filename, offset);
 		fp = popen(cmd, "r");
 		if (!fp)
 			continue;
tools/perf/util/sort.c +8 -1
index f014bfa..88e41b7 100644
@@ -257,6 +257,7 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
 	FILE *fp;
 	char cmd[PATH_MAX + 2], *path = self->srcline, *nl;
 	size_t line_len;
+	char symfs_dso_name[PATH_MAX];
 
 	if (path != NULL)
 		goto out_path;
@@ -269,9 +270,15 @@ static int hist_entry__srcline_snprintf(struct hist_entry *self, char *bf,
 	     strlen(PERF_TMP_DIR "/perf-")))
 		goto out_ip;
 
+	snprintf(symfs_dso_name, sizeof(symfs_dso_name), "%s%s",
+		 symbol_conf.symfs, self->ms.map->dso->long_name);
+	if (access(symfs_dso_name, R_OK))
+		snprintf(symfs_dso_name, sizeof(symfs_dso_name), "%s",
+			 self->ms.map->dso->long_name);
 	snprintf(cmd, sizeof(cmd), "%s -e %s %016" PRIx64,
 		 addr2line_path ? addr2line_path : "addr2line",
-		 self->ms.map->dso->long_name, self->ip);
+		 symfs_dso_name, self->ip);
+
 	fp = popen(cmd, "r");
 	if (!fp)
 		goto out_ip;
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v5 6/6 perf stat: implement --big-num grouping

In reply to Irina Tirdea

From: Irina Tirdea <[email protected]>

In glibc, printf supports ' to group numbers with thousands' grouping characters. Bionic does not support ' for printf.

Implement thousands's grouping for numbers according to locale. The implementation uses the algorithm from glibc
(http://www.gnu.org/software/libc/).

Bionic does not implement locales, so we need to add a configuration option LOCALE_SUPPORT. If it is not defined, default values for thousands separator and grouping are used.

---
 tools/perf/Makefile                 |    6 ++
 tools/perf/builtin-stat.c           |  106 ++++++++++++++++++++++++++++++++---
 tools/perf/config/feature-tests.mak |   18 ++++++
 3 files changed, 123 insertions(+), 7 deletions(-)
tools/perf/Makefile +6 -0
index 78fc6b9..40d73a8 100644
@@ -784,6 +784,12 @@ ifndef NO_BACKTRACE
        endif
 endif
 
+ifndef NO_LOCALE
+       ifeq ($(call try-cc,$(SOURCE_LOCALE),),y)
+               BASIC_CFLAGS += -DLOCALE_SUPPORT
+       endif
+endif
+
 ifdef ASCIIDOC8
 	export ASCIIDOC8
 endif
tools/perf/builtin-stat.c +99 -7

130 lines not on this page · raw message

tools/perf/config/feature-tests.mak +18 -0
index f5ac774..fe7a8cf 100644
@@ -225,3 +225,21 @@ int main(void)
 	return on_exit(NULL, NULL);
 }
 endef
+
+ifndef NO_LOCALE
+define SOURCE_LOCALE
+#include <locale.h>
+
+int main(void)
+{
+	char *thousands_sep, *grouping;
+
+	struct lconv *lc = localeconv();
+	if (lc != NULL) {
+		thousands_sep = lc->thousands_sep;
+		grouping = lc->grouping;
+	}
+	return 0;
+}
+endef
+endif
Signature · 1 line
1.7.9.5