diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-09-21 01:14:34 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-09-21 01:14:34 +0000 |
commit | a9e5b352f6f2ac60e0ff18d64120b8b7a48eb297 (patch) | |
tree | 7b4a8f9a87cfe067188f8292db69153d5a4dbe1c | |
parent | 797da605d06d86b09232c37e2aefe98382a8b2b6 (diff) | |
parent | e01b2b6c536e42fc95ab9c1da34536a11a84c23f (diff) | |
download | extras-a9e5b352f6f2ac60e0ff18d64120b8b7a48eb297.tar.gz |
Merge "simpleperf: allow inferno to run from any dir."
-rw-r--r-- | simpleperf/scripts/inferno.bat | 1 | ||||
-rwxr-xr-x | simpleperf/scripts/inferno.sh | 2 | ||||
-rw-r--r-- | simpleperf/scripts/inferno/inferno.py | 15 | ||||
-rw-r--r-- | simpleperf/scripts/test.py | 20 |
4 files changed, 27 insertions, 11 deletions
diff --git a/simpleperf/scripts/inferno.bat b/simpleperf/scripts/inferno.bat index a2d18a7b..5818f986 100644 --- a/simpleperf/scripts/inferno.bat +++ b/simpleperf/scripts/inferno.bat @@ -1 +1,2 @@ +set PYTHONPATH=%PYTHONPATH%;%~dp0 python -m inferno.inferno %* diff --git a/simpleperf/scripts/inferno.sh b/simpleperf/scripts/inferno.sh index 8ba5097c..d30ee317 100755 --- a/simpleperf/scripts/inferno.sh +++ b/simpleperf/scripts/inferno.sh @@ -1,2 +1,4 @@ #!/bin/bash +SCRIPTPATH=$(dirname "$0") +export PYTHONPATH=$SCRIPTPATH:$PYTHONPATH python -m inferno.inferno "$@" diff --git a/simpleperf/scripts/inferno/inferno.py b/simpleperf/scripts/inferno/inferno.py index a7c60faa..5060a357 100644 --- a/simpleperf/scripts/inferno/inferno.py +++ b/simpleperf/scripts/inferno/inferno.py @@ -36,19 +36,17 @@ import subprocess import sys import webbrowser -try: - from simpleperf_report_lib import ReportLib - from utils import log_exit, log_info, AdbHelper -except: - print("Please go to the parent directory, and run inferno.sh or inferno.bat.") - sys.exit(1) +scripts_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +sys.path.append(scripts_path) +from simpleperf_report_lib import ReportLib +from utils import log_exit, log_info, AdbHelper from data_types import * from svg_renderer import * def collect_data(args): - app_profiler_args = [sys.executable, "app_profiler.py", "-nb"] + app_profiler_args = [sys.executable, os.path.join(scripts_path, "app_profiler.py"), "-nb"] if args.app: app_profiler_args += ["-p", args.app] elif args.native_program: @@ -141,7 +139,7 @@ def output_report(process, args): :param process: Process object :return: str, absolute path to the file """ - f = open('report.html', 'w') + f = open(args.report_path, 'w') filepath = os.path.realpath(f.name) f.write("<html>") f.write("<head>") @@ -274,6 +272,7 @@ def main(): default="") parser.add_argument('--disable_adb_root', action='store_true', help="""Force adb to run in non root mode.""") + parser.add_argument('-o', '--report_path', default='report.html', help="Set report path.") args = parser.parse_args() process = Process("", 0) diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py index cbdd27b3..e75a328b 100644 --- a/simpleperf/scripts/test.py +++ b/simpleperf/scripts/test.py @@ -51,7 +51,7 @@ try: except: has_google_protobuf = False -inferno_script = "inferno.bat" if is_windows() else "./inferno.sh" +inferno_script = os.path.join(get_script_dir(), "inferno.bat" if is_windows() else "./inferno.sh") support_trace_offcpu = None @@ -225,8 +225,7 @@ class TestExampleBase(TestBase): fulfilled[i] = True self.assertEqual(len(fulfilled), sum([int(x) for x in fulfilled]), fulfilled) - def check_inferno_report_html(self, check_entries): - file = "report.html" + def check_inferno_report_html(self, check_entries, file="report.html"): self.check_exist(file=file) with open(file, 'r') as fh: data = fh.read() @@ -403,6 +402,21 @@ class TestExamplePureJava(TestExampleBase): self.run_cmd([inferno_script, "-sc"]) self.check_inferno_report_html( [('com.example.simpleperf.simpleperfexamplepurejava.MainActivity$1.run()', 80)]) + self.run_cmd([inferno_script, "-sc", "-o", "report2.html"]) + self.check_inferno_report_html( + [('com.example.simpleperf.simpleperfexamplepurejava.MainActivity$1.run()', 80)], + "report2.html") + remove("report2.html") + + def test_inferno_in_another_dir(self): + test_dir = 'inferno_testdir' + saved_dir = os.getcwd() + remove(test_dir) + os.mkdir(test_dir) + os.chdir(test_dir) + self.run_cmd([inferno_script]) + os.chdir(saved_dir) + remove(test_dir) class TestExamplePureJavaRoot(TestExampleBase): |