From 3ecb92e3b7e9c0ae449d52dd484058ddc00d9159 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Thu, 17 Feb 2022 16:56:09 +0100 Subject: [PATCH] [tools] Fix callstats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove debug printing in callstats.py - Handle non-version nested JSON files better in callstats.html - Harden RCS extraction from telemetry JSON files Change-Id: Ied921e54e6281a456c0a6369d797c21785080036 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3471856 Reviewed-by: Marja Hölttä Commit-Queue: Camillo Bruni Cr-Commit-Position: refs/heads/main@{#79155} --- tools/callstats-from-telemetry.sh | 15 +++++++++------ tools/callstats.html | 24 ++++++++++++++---------- tools/callstats.py | 2 -- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tools/callstats-from-telemetry.sh b/tools/callstats-from-telemetry.sh index cea471cde8..3572b7e6ba 100755 --- a/tools/callstats-from-telemetry.sh +++ b/tools/callstats-from-telemetry.sh @@ -46,7 +46,7 @@ fi OUT=out.json if [[ -e $OUT ]]; then echo "# Creating backup for $OUT" - cp --backup=numbered $OUT $OUT.bak + cp $OUT $OUT.bak fi echo "# Writing to $OUT" @@ -54,11 +54,14 @@ echo "# Writing to $OUT" function convert { NAME=$1 JSON=$2 - du -sh $JSON; - echo "Converting NAME=$NAME"; - echo "," >> $OUT; - echo "\"$NAME\": " >> $OUT; - jq '[.traceEvents[].args | select(."runtime-call-stats" != null) | ."runtime-call-stats"]' $JSON >> $OUT; + # Check if any json file exists: + if ls $JSON 1> /dev/null 2>&1; then + du -sh $JSON; + echo "Converting NAME=$NAME"; + echo "," >> $OUT; + echo "\"$NAME\": " >> $OUT; + jq '[.traceEvents[].args | select(."runtime-call-stats" != null) | ."runtime-call-stats"]' $JSON >> $OUT; + fi } diff --git a/tools/callstats.html b/tools/callstats.html index d00f48d8b5..2a797680bc 100644 --- a/tools/callstats.html +++ b/tools/callstats.html @@ -1543,23 +1543,27 @@ code is governed by a BSD-style license that can be found in the LICENSE file. // Instead of the default multi-page JSON: // {"Version 1": { "Page 1": ..., ...}, "Version 2": {...}, ...} // In this case insert a single "Default" version as top-level entry. - let firstProperty = (object) => { + const firstProperty = (object) => { for (let key in object) return object[key]; }; - let maybePage = firstProperty(json); - let maybeMetrics = firstProperty(maybePage); - let tempName = name ? name : new Date().toISOString(); - tempName = window.prompt('Enter a name for the loaded file:', tempName); - if ('count' in maybeMetrics && 'duration' in maybeMetrics) { + const maybeMetrics = firstProperty(json); + const maybeMetric = firstProperty(maybeMetrics); + const tempName = name ? name : new Date().toISOString(); + const getFileName = + () => window.prompt('Enter a name for the loaded file:', tempName); + if ('count' in maybeMetric && 'duration' in maybeMetric) { return { - [tempName]: json + [getFileName()]: json } } // Legacy fallback where the metrics are encoded as arrays: // { PAGE: [[metric_name, ...], [...], ]} - if (Array.isArray(maybeMetrics)) { + // Also, make sure we don't have the versioned array-style: + // { VERSION: { PAGE: [[metric_name, ...], [...], ]}, ...} + const innerArray = firstProperty(maybeMetrics); + if (Array.isArray(maybeMetric) && !Array.isArray(innerArray)) { return { - [tempName]: json + [getFileName()]: json } } return json @@ -2705,4 +2709,4 @@ code is governed by a BSD-style license that can be found in the LICENSE file. - \ No newline at end of file + diff --git a/tools/callstats.py b/tools/callstats.py index a5e6bfe69c..1b76d0c166 100755 --- a/tools/callstats.py +++ b/tools/callstats.py @@ -494,11 +494,9 @@ def print_stats(S, args): def extract_domain(filename): - print(filename) # Extract domain name: domain#123.txt or domain_123.txt match = re.match(r'^(.*?)[^a-zA-Z]?[0-9]+?.txt', filename) domain = match.group(1) - print(domain) return domain