perf tools: improve perf support on Android
v2 cover perf tools: improve perf support on Android
From: Michael Lentine <[email protected]>
This short series of patches allow for the execution of perf natively on the android devices.
The following changes are implemented:
- Have cat be the default page. Android does not have less or more pager. this is a generic change which cleans up the code a bit
- Remap library paths to allow for data reporting on a linux pc with data collected from an android device.
In V2, we address the feedback from LKML. Use explicit path for less pager. Document Android system libraries better.
Michael Lentine (2):
perf tools: add a fallback for pager to use cat if less does not exist. perf tools: add automatic remapping of Android libraries
tools/perf/util/map.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/pager.c | 12 +++---- 2 files changed, 94 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1.423.g4596e3a
PATCH v2 1/2 perf tools: add cat as fallback pager
From: Michael Lentine <[email protected]>
This patch adds a fallback to cat for the pager. This is useful on environmnents, such as Android, where less does not exist. It is better to default to cat than to abort.
--- tools/perf/util/pager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/pager.c +6 -6
@@ -57,13 +57,13 @@ void setup_pager(void) }if (!pager) pager =getenv ("PAGER" ); -if (!pager) { -if (!access ("/usr/bin/pager" ,X_OK )) - pager ="/usr/bin/pager" ; - } +if (!(pager ||access ("/usr/bin/pager" ,X_OK ))) + pager ="/usr/bin/pager" ; +if (!(pager ||access ("/usr/bin/less" ,X_OK ))) + pager ="/usr/bin/less" ;if (!pager) - pager ="less" ; -else if (!*pager || !strcmp (pager,"cat" )) + pager ="cat" ; +if (!*pager || !strcmp (pager,"cat" ))return ; spawned_pager =1 ;/* means we are emitting to terminal */
Signature · 1 line
1.9.1.423.g4596e3a
tip-bot for Michael Lentine
merge bot[tip:perf/core] perf tools: Add cat as fallback pager
perf tools: Add cat as fallback pager
Commit-ID: 21cfc5e10395eba795c0610cf3cf7f0a4f6f33ff Gitweb: http://git.kernel.org/tip/21cfc5e10395eba795c0610cf3cf7f0a4f6f33ff Author: Michael Lentine <[email protected]> AuthorDate: Tue, 20 May 2014 11:48:49 +0200 Committer: Jiri Olsa <[email protected]> CommitDate: Wed, 21 May 2014 11:48:33 +0200
perf tools: Add cat as fallback pager
This patch adds a fallback to cat for the pager. This is useful on environments, such as Android, where less does not exist. It is better to default to cat than to abort.
--- tools/perf/util/pager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/pager.c +6 -6
@@ -57,13 +57,13 @@ void setup_pager(void) }if (!pager) pager =getenv ("PAGER" ); -if (!pager) { -if (!access ("/usr/bin/pager" ,X_OK )) - pager ="/usr/bin/pager" ; - } +if (!(pager ||access ("/usr/bin/pager" ,X_OK ))) + pager ="/usr/bin/pager" ; +if (!(pager ||access ("/usr/bin/less" ,X_OK ))) + pager ="/usr/bin/less" ;if (!pager) - pager ="less" ; -else if (!*pager || !strcmp (pager,"cat" )) + pager ="cat" ; +if (!*pager || !strcmp (pager,"cat" ))return ; spawned_pager =1 ;/* means we are emitting to terminal */
PATCH v2 2/2 perf tools: add automatic remapping of Android libraries
In reply to Stephane EranianFrom: Michael Lentine <[email protected]>
This patch automtically adjusts the path of MMAP records associated with Android system libraries.
The Android system is organized with system libraries found in /system/lib and user libraries in /data/app-lib. On the host system (not running Android), system libraries can be found in the downloaded NDK directory under ${NDK_ROOT}/platforms/${APP_PLATFORM}/arch-${ARCH}/usr/lib and the user libraries are installed under libs/${APP_ABI} within the apk build directory. This patch makes running the reporting tools possible on the host system using the libraries from the NDK.
--- tools/perf/util/map.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-)
tools/perf/util/map.c +94 -1
@@ -32,6 +32,93 @@ static inline int is_no_dso_memory(const char *filename) !strcmp (filename,"[heap]" ); } +static inline int is_android_lib (const char *filename) +{ +return !strncmp (filename,"/data/app-lib" ,13 ) || + !strncmp (filename,"/system/lib" ,11 ); +} + +static inline bool replace_android_lib (const char *filename,char *newfilename) +{ +const char *libname; +char *app_abi; +size_t app_abi_length, new_length; +size_t lib_length =0 ; + + libname =strrchr (filename,'/' ); +if (libname) + lib_length =strlen (libname); + + app_abi =getenv ("APP_ABI" ); +if (!app_abi) +return false; + + app_abi_length =strlen (app_abi); + +if (!strncmp (filename,"/data/app-lib" ,13 )) { +char *apk_path; + +if (!app_abi_length) +return false; + + new_length =7 + app_abi_length + lib_length; + + apk_path =getenv ("APK_PATH" ); +if (apk_path) { + new_length +=strlen (apk_path) +1 ; +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"%s/libs/%s/%s" , apk_path, app_abi, libname); + }else { +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"libs/%s/%s" , app_abi, libname); + } +return true; + } + +if (!strncmp (filename,"/system/lib/" ,11 )) { +char *ndk, *app; +const char *arch; +size_t ndk_length; +size_t app_length; + + ndk =getenv ("NDK_ROOT" ); + app =getenv ("APP_PLATFORM" ); + +if (!(ndk && app)) +return false; + + ndk_length =strlen (ndk); + app_length =strlen (app); + +if (!(ndk_length && app_length && app_abi_length)) +return false; + + arch = !strncmp (app_abi,"arm" ,3 ) ?"arm" : + !strncmp (app_abi,"mips" ,4 ) ?"mips" : + !strncmp (app_abi,"x86" ,3 ) ?"x86" :NULL ; + +if (!arch) +return false; + + new_length =27 + ndk_length + + app_length + lib_length + +strlen (arch); + +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"%s/platforms/%s/arch-%s/usr/lib/%s" , + ndk, app, arch, libname); + +return true; + } +return false; +} +void map__init (struct map *map,enum map_type type,u64 start,u64 end,u64 pgoff,struct dso *dso) {
@@ -59,8 +146,9 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,if (map !=NULL ) {char newfilename[PATH_MAX ];struct dso *dso; -int anon, no_dso, vdso; +int anon, no_dso, vdso, android; + android =is_android_lib (filename); anon =is_anon_memory (filename); vdso =is_vdso_map (filename); no_dso =is_no_dso_memory (filename);
@@ -75,6 +163,11 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, filename = newfilename; } +if (android) { +if (replace_android_lib (filename, newfilename)) + filename = newfilename; + } +if (vdso) { pgoff =0 ; dso =vdso__dso_findnew (dsos__list);
Signature · 1 line
1.9.1.423.g4596e3a
tip-bot for Michael Lentine
merge bot[tip:perf/core] perf tools: Add automatic remapping of Android libraries
perf tools: Add automatic remapping of Android libraries
Commit-ID: eca8183699964579ca8a0b8d116bd1f4da0136f7 Gitweb: http://git.kernel.org/tip/eca8183699964579ca8a0b8d116bd1f4da0136f7 Author: Michael Lentine <[email protected]> AuthorDate: Tue, 20 May 2014 11:48:50 +0200 Committer: Jiri Olsa <[email protected]> CommitDate: Wed, 21 May 2014 15:03:25 +0200
perf tools: Add automatic remapping of Android libraries
This patch automatically adjusts the path of MMAP records associated with Android system libraries.
The Android system is organized with system libraries found in /system/lib and user libraries in /data/app-lib. On the host system (not running Android), system libraries can be found in the downloaded NDK directory under ${NDK_ROOT}/platforms/${APP_PLATFORM}/arch-${ARCH}/usr/lib and the user libraries are installed under libs/${APP_ABI} within the apk build directory. This patch makes running the reporting tools possible on the host system using the libraries from the NDK.
--- tools/perf/util/map.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-)
tools/perf/util/map.c +94 -1
@@ -32,6 +32,93 @@ static inline int is_no_dso_memory(const char *filename) !strcmp (filename,"[heap]" ); } +static inline int is_android_lib (const char *filename) +{ +return !strncmp (filename,"/data/app-lib" ,13 ) || + !strncmp (filename,"/system/lib" ,11 ); +} + +static inline bool replace_android_lib (const char *filename,char *newfilename) +{ +const char *libname; +char *app_abi; +size_t app_abi_length, new_length; +size_t lib_length =0 ; + + libname =strrchr (filename,'/' ); +if (libname) + lib_length =strlen (libname); + + app_abi =getenv ("APP_ABI" ); +if (!app_abi) +return false; + + app_abi_length =strlen (app_abi); + +if (!strncmp (filename,"/data/app-lib" ,13 )) { +char *apk_path; + +if (!app_abi_length) +return false; + + new_length =7 + app_abi_length + lib_length; + + apk_path =getenv ("APK_PATH" ); +if (apk_path) { + new_length +=strlen (apk_path) +1 ; +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"%s/libs/%s/%s" , apk_path, app_abi, libname); + }else { +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"libs/%s/%s" , app_abi, libname); + } +return true; + } + +if (!strncmp (filename,"/system/lib/" ,11 )) { +char *ndk, *app; +const char *arch; +size_t ndk_length; +size_t app_length; + + ndk =getenv ("NDK_ROOT" ); + app =getenv ("APP_PLATFORM" ); + +if (!(ndk && app)) +return false; + + ndk_length =strlen (ndk); + app_length =strlen (app); + +if (!(ndk_length && app_length && app_abi_length)) +return false; + + arch = !strncmp (app_abi,"arm" ,3 ) ?"arm" : + !strncmp (app_abi,"mips" ,4 ) ?"mips" : + !strncmp (app_abi,"x86" ,3 ) ?"x86" :NULL ; + +if (!arch) +return false; + + new_length =27 + ndk_length + + app_length + lib_length + +strlen (arch); + +if (new_length >PATH_MAX ) +return false; +snprintf (newfilename, new_length, +"%s/platforms/%s/arch-%s/usr/lib/%s" , + ndk, app, arch, libname); + +return true; + } +return false; +} +void map__init (struct map *map,enum map_type type,u64 start,u64 end,u64 pgoff,struct dso *dso) {
@@ -59,8 +146,9 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,if (map !=NULL ) {char newfilename[PATH_MAX ];struct dso *dso; -int anon, no_dso, vdso; +int anon, no_dso, vdso, android; + android =is_android_lib (filename); anon =is_anon_memory (filename); vdso =is_vdso_map (filename); no_dso =is_no_dso_memory (filename);
@@ -75,6 +163,11 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, filename = newfilename; } +if (android) { +if (replace_android_lib (filename, newfilename)) + filename = newfilename; + } +if (vdso) { pgoff =0 ; dso =vdso__dso_findnew (dsos__list);