summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-09-20 16:20:04 -0700
committerYabin Cui <yabinc@google.com>2017-09-20 16:20:04 -0700
commite01b2b6c536e42fc95ab9c1da34536a11a84c23f (patch)
tree7b4a8f9a87cfe067188f8292db69153d5a4dbe1c
parent797da605d06d86b09232c37e2aefe98382a8b2b6 (diff)
downloadextras-e01b2b6c536e42fc95ab9c1da34536a11a84c23f.tar.gz
simpleperf: allow inferno to run from any dir.
Previously inferno.sh/.bat can only run from scripts/, this CL removes the restriction. Also add -o option to select report path. Bug: http://b/32834638 Test: run test.py. Change-Id: Ib1651dcd1beedac5be00249150e0b74fea906924
-rw-r--r--simpleperf/scripts/inferno.bat1
-rwxr-xr-xsimpleperf/scripts/inferno.sh2
-rw-r--r--simpleperf/scripts/inferno/inferno.py15
-rw-r--r--simpleperf/scripts/test.py20
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):