summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-10-25 12:42:11 -0700
committerYabin Cui <yabinc@google.com>2017-10-25 14:58:10 -0700
commit45f61314ae070697a2ae15ad15198458880fcae8 (patch)
tree7c1b400bcf169c3162f64f74995377b6a36650a9
parentb2595e8e85ee3a3963133737be97780d74351a15 (diff)
downloadextras-45f61314ae070697a2ae15ad15198458880fcae8.tar.gz
simpleperf: fix scripts.
Fixed scripts based on test results on different platforms: 1. Decrease sample frequency from 4000 to 1000 when using -g option. Because using -f 4000 sometimes makes a high loss rate >= 50%. 2. Use kill when am force-stop can't kill the app process, this happens when testing on Android N. 3. In app_profiler.py, only download native libs when profiling an app. 4. Fix some small errors. Bug: http://b/32834638 Test: run python test.py on linux/windows/darwin Test: with Android N/O devices. Change-Id: If8f7ab0195e87014c3ad4ab0d007d0eac8b6f528
-rw-r--r--simpleperf/scripts/annotate.py2
-rw-r--r--simpleperf/scripts/app_profiler.py19
-rw-r--r--simpleperf/scripts/test.py16
-rw-r--r--simpleperf/scripts/utils.py1
4 files changed, 24 insertions, 14 deletions
diff --git a/simpleperf/scripts/annotate.py b/simpleperf/scripts/annotate.py
index 56b83e1e..740a17ce 100644
--- a/simpleperf/scripts/annotate.py
+++ b/simpleperf/scripts/annotate.py
@@ -550,7 +550,7 @@ class SourceFileAnnotator(object):
elif suffix_len == best_suffix_len:
best_path_count += 1
if best_path_count > 1:
- log_warning('multiple source for %s, select %s' % (file, result))
+ log_warning('multiple source for %s, select %s' % (file, best_path))
return best_path
diff --git a/simpleperf/scripts/app_profiler.py b/simpleperf/scripts/app_profiler.py
index c089bbe8..3a8f0b50 100644
--- a/simpleperf/scripts/app_profiler.py
+++ b/simpleperf/scripts/app_profiler.py
@@ -163,8 +163,17 @@ class AppProfiler(object):
self.config['launch_activity'] = '.MainActivity'
self.adb.check_run(['shell', 'am', 'force-stop', self.config['app_package_name']])
- while self._find_app_process():
+ count = 0
+ while True:
time.sleep(1)
+ pid = self._find_app_process()
+ if pid is None:
+ break
+ # When testing on Android N, `am force-stop` sometimes can't kill
+ # com.example.simpleperf.simpleperfexampleofkotlin. So use kill when this happens.
+ count += 1
+ if count >= 3:
+ self.run_in_app_dir(['kill', '-9', str(pid)], check_result=False, log_output=False)
if self.config['profile_from_launch']:
self._download_simpleperf()
@@ -257,7 +266,7 @@ class AppProfiler(object):
def _download_native_libs(self):
- if not self.config['native_lib_dir']:
+ if not self.config['native_lib_dir'] or not self.config['app_package_name']:
return
filename_dict = dict()
for root, _, files in os.walk(self.config['native_lib_dir']):
@@ -417,8 +426,8 @@ It restarts the app if the app is already running.""")
parser.add_argument('--arch', help=
"""Select which arch the app is running on, possible values are:
arm, arm64, x86, x86_64. If not set, the script will try to detect it.""")
- parser.add_argument('-r', '--record_options', default="-e cpu-cycles:u -g --duration 10", help=
-"""Set options for `simpleperf record` command.""")
+ parser.add_argument('-r', '--record_options', default="-e cpu-cycles:u -g -f 1000 --duration 10", help=
+"""Set options for `simpleperf record` command. Default is '-e cpu-cycles:u -g -f 1000 --duration 10'.""")
parser.add_argument('-o', '--perf_data_path', default="perf.data", help=
"""The path to store profiling data.""")
parser.add_argument('-nb', '--skip_collect_binaries', action='store_true', help=
@@ -455,4 +464,4 @@ already running, download simpleperf on device, start simpleperf record, and sta
profiler.profile()
if __name__ == '__main__':
- main() \ No newline at end of file
+ main()
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index 50298f70..ab744d71 100644
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -155,7 +155,7 @@ class TestExampleBase(TestBase):
self.__class__.test_result = result
super(TestBase, self).run(result)
- def run_app_profiler(self, record_arg = "-g --duration 3 -e cpu-cycles:u",
+ def run_app_profiler(self, record_arg = "-g -f 1000 --duration 3 -e cpu-cycles:u",
build_binary_cache=True, skip_compile=False, start_activity=True,
native_lib_dir=None, profile_from_launch=False, add_arch=False):
args = ["app_profiler.py", "--app", self.package_name, "--apk", self.apk_path,
@@ -282,7 +282,7 @@ class TestExampleBase(TestBase):
self.run_cmd(["report_sample.py"])
output = self.run_cmd(["report_sample.py", "perf.data"], return_output=True)
self.check_strings_in_content(output, check_strings)
- self.run_app_profiler(record_arg="-g --duration 3 -e cpu-cycles:u --no-dump-symbols")
+ self.run_app_profiler(record_arg="-g -f 1000 --duration 3 -e cpu-cycles:u --no-dump-symbols")
output = self.run_cmd(["report_sample.py", "--symfs", "binary_cache"], return_output=True)
self.check_strings_in_content(output, check_strings)
@@ -443,7 +443,7 @@ class TestExamplePureJavaTraceOffCpu(TestExampleBase):
".SleepActivity")
def test_smoke(self):
- self.run_app_profiler(record_arg = "-g --duration 3 -e cpu-cycles:u --trace-offcpu")
+ self.run_app_profiler(record_arg="-g -f 1000 --duration 3 -e cpu-cycles:u --trace-offcpu")
self.run_cmd(["report.py", "-g", "-o", "report.txt"])
self.check_strings_in_file("report.txt",
["com.example.simpleperf.simpleperfexamplepurejava.SleepActivity$1.run()",
@@ -548,7 +548,7 @@ class TestExampleWithNativeTraceOffCpu(TestExampleBase):
".SleepActivity")
def test_smoke(self):
- self.run_app_profiler(record_arg = "-g --duration 3 -e cpu-cycles:u --trace-offcpu")
+ self.run_app_profiler(record_arg="-g -f 1000 --duration 3 -e cpu-cycles:u --trace-offcpu")
self.run_cmd(["report.py", "-g", "--comms", "SleepThread", "-o", "report.txt"])
self.check_strings_in_file("report.txt",
["SleepThread(void*)",
@@ -596,8 +596,8 @@ class TestExampleWithNativeJniCall(TestExampleBase):
[("MixActivity.java", 80, 0),
("run", 80, 0),
("line 26", 20, 0),
- ("native-lib.cpp", 10, 0),
- ("line 40", 10, 0)])
+ ("native-lib.cpp", 5, 0),
+ ("line 40", 5, 0)])
self.run_cmd([inferno_script, "-sc"])
@@ -706,7 +706,7 @@ class TestExampleOfKotlinTraceOffCpu(TestExampleBase):
".SleepActivity")
def test_smoke(self):
- self.run_app_profiler(record_arg = "-g --duration 3 -e cpu-cycles:u --trace-offcpu")
+ self.run_app_profiler(record_arg="-g -f 1000 --duration 3 -e cpu-cycles:u --trace-offcpu")
self.run_cmd(["report.py", "-g", "-o", "report.txt"])
self.check_strings_in_file("report.txt",
["void com.example.simpleperf.simpleperfexampleofkotlin.SleepActivity$createRunSleepThread$1.run()",
@@ -742,7 +742,7 @@ class TestProfilingNativeProgram(TestExampleBase):
return
remove("perf.data")
self.run_cmd(["app_profiler.py", "-np", "surfaceflinger",
- "-r", "-g --duration 3 -e cpu-cycles:u"])
+ "-r", "-g -f 1000 --duration 3 -e cpu-cycles:u"])
self.run_cmd(["report.py", "-g", "-o", "report.txt"])
diff --git a/simpleperf/scripts/utils.py b/simpleperf/scripts/utils.py
index bf960849..4404c21c 100644
--- a/simpleperf/scripts/utils.py
+++ b/simpleperf/scripts/utils.py
@@ -611,6 +611,7 @@ class Objdump(object):
return None
result = []
for line in stdoutdata.split('\n'):
+ line = line.rstrip() # Remove '\r' on Windows.
items = line.split(':', 1)
try:
addr = int(items[0], 16)