From 2aa5a1d15eb8ddacf1e950f9ce4f099ad4a544f3 Mon Sep 17 00:00:00 2001 From: Nataniel Borges Date: Tue, 20 Jul 2021 21:19:53 +0200 Subject: [PATCH] Introduce a .winscope extension for all winscope files This extension will be used to better integrate winscope traces and ABT, allowing trace files to be opened directly from ABT or buganizer Bug: 192663722 Bug: 162813517 Test: (for winscope) build winscope, record traces, download traces, check if traces have the .winscope extension. (for flicker) run atest Flickertests. (for abt) on new extension, check if .winscope files show as "open in winscope" on buganizer Change-Id: Iab7a80d0675aefe1a80d10a0f8b512506d063bba --- tools/winscope/adb_proxy/winscope_proxy.py | 36 +++++++++++++--------- tools/winscope/src/mixins/SaveAsZip.js | 25 ++++++++++++++- tools/winscope/trace.sh | 13 ++++---- tools/winscope/webpack.spec.config.js | 2 +- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/tools/winscope/adb_proxy/winscope_proxy.py b/tools/winscope/adb_proxy/winscope_proxy.py index 5bfc531e2..09845f077 100755 --- a/tools/winscope/adb_proxy/winscope_proxy.py +++ b/tools/winscope/adb_proxy/winscope_proxy.py @@ -55,6 +55,12 @@ WINSCOPE_TOKEN_HEADER = "Winscope-Token" # Location to save the proxy security token WINSCOPE_TOKEN_LOCATION = os.path.expanduser('~/.config/winscope/.token') +# Winscope traces extension +WINSCOPE_EXT = ".winscope" + +# Winscope traces directory +WINSCOPE_DIR = "/data/misc/wmtrace/" + # Max interval between the client keep-alive requests in seconds KEEP_ALIVE_INTERVAL_S = 5 @@ -111,51 +117,51 @@ class TraceTarget: # Order of files matters as they will be expected in that order and decoded in that order TRACE_TARGETS = { "window_trace": TraceTarget( - File("/data/misc/wmtrace/wm_trace.pb", "window_trace"), + File(f'{WINSCOPE_DIR}wm_trace{WINSCOPE_EXT}', "window_trace"), 'su root cmd window tracing start\necho "WM trace started."', 'su root cmd window tracing stop >/dev/null 2>&1' ), "accessibility_trace": TraceTarget( - File("/data/misc/a11ytrace/a11y_trace.pb", "accessibility_trace"), + File(f'/data/misc/a11ytrace/a11y_trace{WINSCOPE_EXT}', "accessibility_trace"), 'su root cmd accessibility start-trace\necho "Accessibility trace started."', 'su root cmd accessibility stop-trace >/dev/null 2>&1' ), "layers_trace": TraceTarget( - File("/data/misc/wmtrace/layers_trace.pb", "layers_trace"), + File(f'{WINSCOPE_DIR}layers_trace{WINSCOPE_EXT}', "layers_trace"), 'su root service call SurfaceFlinger 1025 i32 1\necho "SF trace started."', 'su root service call SurfaceFlinger 1025 i32 0 >/dev/null 2>&1' ), "screen_recording": TraceTarget( - File("/data/local/tmp/screen.winscope.mp4", "screen_recording"), - 'screenrecord --bit-rate 8M /data/local/tmp/screen.winscope.mp4 >/dev/null 2>&1 &\necho "ScreenRecorder started."', + File(f'/data/local/tmp/screen{WINSCOPE_EXT}.mp4', "screen_recording"), + f'screenrecord --bit-rate 8M /data/local/tmp/screen{WINSCOPE_EXT}.mp4 >/dev/null 2>&1 &\necho "ScreenRecorder started."', 'pkill -l SIGINT screenrecord >/dev/null 2>&1' ), "transaction": TraceTarget( [ - File("/data/misc/wmtrace/transaction_trace.pb", "transactions"), - FileMatcher("/data/misc/wmtrace/", "transaction_merges_*.pb", + File(f'{WINSCOPE_DIR}transaction_trace{WINSCOPE_EXT}', "transactions"), + FileMatcher(WINSCOPE_DIR, f'transaction_merges_*{WINSCOPE_EXT}', "transaction_merges"), ], 'su root service call SurfaceFlinger 1020 i32 1\necho "SF transactions recording started."', 'su root service call SurfaceFlinger 1020 i32 0 >/dev/null 2>&1' ), "proto_log": TraceTarget( - File("/data/misc/wmtrace/wm_log.pb", "proto_log"), + File(f'{WINSCOPE_DIR}wm_log{WINSCOPE_EXT}', "proto_log"), 'su root cmd window logging start\necho "WM logging started."', 'su root cmd window logging stop >/dev/null 2>&1' ), "ime_trace_clients": TraceTarget( - File("/data/misc/wmtrace/ime_trace_clients.pb", "ime_trace_clients"), + File(f'{WINSCOPE_DIR}ime_trace_clients{WINSCOPE_EXT}', "ime_trace_clients"), 'su root ime tracing start\necho "Clients IME trace started."', 'su root ime tracing stop >/dev/null 2>&1' ), "ime_trace_service": TraceTarget( - File("/data/misc/wmtrace/ime_trace_service.pb", "ime_trace_service"), + File(f'{WINSCOPE_DIR}ime_trace_service{WINSCOPE_EXT}', "ime_trace_service"), 'su root ime tracing start\necho "Service IME trace started."', 'su root ime tracing stop >/dev/null 2>&1' ), "ime_trace_managerservice": TraceTarget( - File("/data/misc/wmtrace/ime_trace_managerservice.pb", "ime_trace_managerservice"), + File(f'{WINSCOPE_DIR}ime_trace_managerservice{WINSCOPE_EXT}', "ime_trace_managerservice"), 'su root ime tracing start\necho "ManagerService IME trace started."', 'su root ime tracing stop >/dev/null 2>&1' ), @@ -204,12 +210,12 @@ class DumpTarget: DUMP_TARGETS = { "window_dump": DumpTarget( - File("/data/local/tmp/wm_dump.pb", "window_dump"), - 'su root dumpsys window --proto > /data/local/tmp/wm_dump.pb' + File(f'/data/local/tmp/wm_dump{WINSCOPE_EXT}', "window_dump"), + f'su root dumpsys window --proto > /data/local/tmp/wm_dump{WINSCOPE_EXT}' ), "layers_dump": DumpTarget( - File("/data/local/tmp/sf_dump.pb", "layers_dump"), - 'su root dumpsys SurfaceFlinger --proto > /data/local/tmp/sf_dump.pb' + File(f'/data/local/tmp/sf_dump{WINSCOPE_EXT}', "layers_dump"), + f'su root dumpsys SurfaceFlinger --proto > /data/local/tmp/sf_dump{WINSCOPE_EXT}' ) } diff --git a/tools/winscope/src/mixins/SaveAsZip.js b/tools/winscope/src/mixins/SaveAsZip.js index 8b8b6e14c..dc575394b 100644 --- a/tools/winscope/src/mixins/SaveAsZip.js +++ b/tools/winscope/src/mixins/SaveAsZip.js @@ -33,14 +33,37 @@ export default { document.body.removeChild(a); }, + /** + * Returns the file name, if the file has an extension use its default, + * otherwise use ".mp4" for screen recording (name from proxy script) and + * ".winscope" for traces + * @param {*} fileName + */ + getFileName(fileName) { + var re = /(?:\.([^.]+))?$/; + var extension = re.exec(fileName)[1]; + if (!extension) { + extension = ""; + } + switch (extension) { + case "": { + if (fileName == "Screen recording") { + return fileName + ".mp4" + } + return fileName + ".winscope" + } + default: return fileName + } + }, async downloadAsZip(traces) { const zip = new JSZip(); for (const trace of traces) { const traceFolder = zip.folder(trace.type); for (const file of trace.files) { + var fileName = this.getFileName(file.filename); const blob = await fetch(file.blobUrl).then((r) => r.blob()); - traceFolder.file(file.filename, blob); + traceFolder.file(fileName, blob); } } diff --git a/tools/winscope/trace.sh b/tools/winscope/trace.sh index 3f5008d15..ff0174850 100755 --- a/tools/winscope/trace.sh +++ b/tools/winscope/trace.sh @@ -30,8 +30,9 @@ for arg in "$@"; do esac done -outfileTrans=${outfile}_transactiontrace.pb -outfileSurf=${outfile}_layerstrace.pb +WINSCOPE_EXT=.winscope +outfileTrans=${outfile}_transactiontrace$WINSCOPE_EXT +outfileSurf=${outfile}_layerstrace$WINSCOPE_EXT outfileTrans_abs="$(cd "$(dirname "$outfileTrans")"; pwd)/$(basename "$outfileTrans")" outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf")" @@ -39,8 +40,8 @@ outfileSurf_abs="$(cd "$(dirname "$outfileSurf")"; pwd)/$(basename "$outfileSurf if [ "$help" != "" ]; then echo "usage: $0 [-h | --help] [OUTFILE]" echo - echo "Records Transaction traces (default transactiontrace.pb)." - echo "Records Surface traces (default layerstrace.pb)." + echo "Records Transaction traces (default transactiontrace$WINSCOPE_EXT)." + echo "Records Surface traces (default layerstrace$WINSCOPE_EXT)." echo "To view the traces, use $WINSCOPE_URL." exit 1 fi @@ -75,8 +76,8 @@ start_tracing read -p "Press ENTER to stop recording" -s x echo stop_tracing -adb exec-out su root cat /data/misc/wmtrace/transaction_trace.pb >"$outfileTrans" -adb exec-out su root cat /data/misc/wmtrace/layers_trace.pb >"$outfileSurf" +adb exec-out su root cat /data/misc/wmtrace/transaction_trace$WINSCOPE_EXT >"$outfileTrans" +adb exec-out su root cat /data/misc/wmtrace/layers_trace$WINSCOPE_EXT >"$outfileSurf" echo echo "To view the trace, go to $WINSCOPE_URL, and open" diff --git a/tools/winscope/webpack.spec.config.js b/tools/winscope/webpack.spec.config.js index dcbcbf9e1..080da8005 100644 --- a/tools/winscope/webpack.spec.config.js +++ b/tools/winscope/webpack.spec.config.js @@ -64,7 +64,7 @@ module.exports = { }, }, { - test: /\.pb/, + test: /\.(pb|winscope)/, loader: 'file-loader', options: { paths: [