summaryrefslogtreecommitdiff
path: root/startop/scripts
diff options
context:
space:
mode:
authorYan Wang <yawanng@google.com>2019-08-08 18:28:32 -0700
committerYan Wang <yawanng@google.com>2019-08-08 18:34:36 -0700
commit2ae4f03578891bd51aab0d665955e268ff06b27a (patch)
tree4c3fca03cf629ae2a64a019e875ea511229748e2 /startop/scripts
parent72a487722f106bfc60f19f8e9fd6aedf3778b167 (diff)
startop: Change trace duration in compiler.py to timedelta.
The time in timestamp is second, while the trace duration is millisecond. Using timedelta to fix this ambiguity. Test: pytest compiler_test.py Change-Id: I6c445c3dac1b60aec77ead14df021b8a2dda7b5e
Diffstat (limited to 'startop/scripts')
-rw-r--r--startop/scripts/app_startup/lib/adb_utils.py2
-rwxr-xr-xstartop/scripts/iorap/compiler.py16
-rw-r--r--startop/scripts/iorap/compiler_test.py4
3 files changed, 14 insertions, 8 deletions
diff --git a/startop/scripts/app_startup/lib/adb_utils.py b/startop/scripts/app_startup/lib/adb_utils.py
index 1c60a17ada1b..e56a96848895 100644
--- a/startop/scripts/app_startup/lib/adb_utils.py
+++ b/startop/scripts/app_startup/lib/adb_utils.py
@@ -42,6 +42,8 @@ def logcat_save_timestamp() -> str:
def vm_drop_cache():
"""Free pagecache and slab object."""
cmd_utils.run_adb_shell_command('echo 3 > /proc/sys/vm/drop_caches')
+ # Sleep a little bit to provide enougth time for cache cleanup.
+ time.sleep(2)
def root():
"""Roots adb and successive adb commands will run under root."""
diff --git a/startop/scripts/iorap/compiler.py b/startop/scripts/iorap/compiler.py
index ef9b870b8113..c940fe988855 100755
--- a/startop/scripts/iorap/compiler.py
+++ b/startop/scripts/iorap/compiler.py
@@ -29,6 +29,7 @@ import re
import sys
import tempfile
from pathlib import Path
+from datetime import timedelta
from typing import Iterable, Optional, List
DIR = os.path.abspath(os.path.dirname(__file__))
@@ -173,7 +174,7 @@ def build_protobuf(page_runs, inode2filename, filters=[]):
return trace_file
def calc_trace_end_time(trace2db: Trace2Db,
- trace_duration: Optional[int]) -> float:
+ trace_duration: Optional[timedelta]) -> float:
"""
Calculates the end time based on the trace duration.
The start time is the first receiving mm file map event.
@@ -189,9 +190,9 @@ def calc_trace_end_time(trace2db: Trace2Db,
MmFilemapAddToPageCache.raw_ftrace_entry).order_by(
RawFtraceEntry.timestamp).first()
- return first_event.raw_ftrace_entry.timestamp + trace_duration
+ return first_event.raw_ftrace_entry.timestamp + trace_duration.total_seconds()
-def query_add_to_page_cache(trace2db: Trace2Db, trace_duration: Optional[int]):
+def query_add_to_page_cache(trace2db: Trace2Db, trace_duration: Optional[timedelta]):
end_time = calc_trace_end_time(trace2db, trace_duration)
# SELECT * FROM tbl ORDER BY id;
return trace2db.session.query(MmFilemapAddToPageCache).join(
@@ -210,7 +211,7 @@ def transform_perfetto_trace_to_systrace(path_to_perfetto_trace: str,
def run(sql_db_path:str,
trace_file:str,
- trace_duration:Optional[int],
+ trace_duration:Optional[timedelta],
output_file:str,
inode_table:str,
filter:List[str]) -> int:
@@ -292,11 +293,14 @@ def main(argv):
if options.sql_db:
sql_db_path = options.sql_db
+ trace_duration = timedelta(milliseconds=options.trace_duration) if \
+ options.trace_duration is not None else None
+
# if the input is systrace
if options.trace_file:
return run(sql_db_path,
options.trace_file,
- options.trace_duration,
+ trace_duration,
options.output_file,
inode_table,
options.filter)
@@ -308,7 +312,7 @@ def main(argv):
trace_file.name)
return run(sql_db_path,
trace_file.name,
- options.trace_duration,
+ trace_duration,
options.output_file,
inode_table,
options.filter)
diff --git a/startop/scripts/iorap/compiler_test.py b/startop/scripts/iorap/compiler_test.py
index b5d28b03a8d5..1a9f059fc6b6 100644
--- a/startop/scripts/iorap/compiler_test.py
+++ b/startop/scripts/iorap/compiler_test.py
@@ -70,9 +70,9 @@ def test_compiler_main(tmpdir):
# 10ms duration
expected = os.path.join(DIR,
'test_fixtures/compiler/test_result_with_duration.TraceFile.pb')
- assert_compile_result(output, expected, '--duration', '10')
+ assert_compile_result(output, expected, '--duration', '10000')
# 30ms duration
expected = os.path.join(DIR,
'test_fixtures/compiler/test_result_without_duration.TraceFile.pb')
- assert_compile_result(output, expected, '--duration', '30')
+ assert_compile_result(output, expected, '--duration', '30000')