Commit 3ecb92e3 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[tools] Fix callstats

- 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/+/3471856Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79155}
parent 9bfa2aa6
...@@ -46,7 +46,7 @@ fi ...@@ -46,7 +46,7 @@ fi
OUT=out.json OUT=out.json
if [[ -e $OUT ]]; then if [[ -e $OUT ]]; then
echo "# Creating backup for $OUT" echo "# Creating backup for $OUT"
cp --backup=numbered $OUT $OUT.bak cp $OUT $OUT.bak
fi fi
echo "# Writing to $OUT" echo "# Writing to $OUT"
...@@ -54,11 +54,14 @@ echo "# Writing to $OUT" ...@@ -54,11 +54,14 @@ echo "# Writing to $OUT"
function convert { function convert {
NAME=$1 NAME=$1
JSON=$2 JSON=$2
du -sh $JSON; # Check if any json file exists:
echo "Converting NAME=$NAME"; if ls $JSON 1> /dev/null 2>&1; then
echo "," >> $OUT; du -sh $JSON;
echo "\"$NAME\": " >> $OUT; echo "Converting NAME=$NAME";
jq '[.traceEvents[].args | select(."runtime-call-stats" != null) | ."runtime-call-stats"]' $JSON >> $OUT; echo "," >> $OUT;
echo "\"$NAME\": " >> $OUT;
jq '[.traceEvents[].args | select(."runtime-call-stats" != null) | ."runtime-call-stats"]' $JSON >> $OUT;
fi
} }
......
...@@ -1543,23 +1543,27 @@ code is governed by a BSD-style license that can be found in the LICENSE file. ...@@ -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: // Instead of the default multi-page JSON:
// {"Version 1": { "Page 1": ..., ...}, "Version 2": {...}, ...} // {"Version 1": { "Page 1": ..., ...}, "Version 2": {...}, ...}
// In this case insert a single "Default" version as top-level entry. // 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]; for (let key in object) return object[key];
}; };
let maybePage = firstProperty(json); const maybeMetrics = firstProperty(json);
let maybeMetrics = firstProperty(maybePage); const maybeMetric = firstProperty(maybeMetrics);
let tempName = name ? name : new Date().toISOString(); const tempName = name ? name : new Date().toISOString();
tempName = window.prompt('Enter a name for the loaded file:', tempName); const getFileName =
if ('count' in maybeMetrics && 'duration' in maybeMetrics) { () => window.prompt('Enter a name for the loaded file:', tempName);
if ('count' in maybeMetric && 'duration' in maybeMetric) {
return { return {
[tempName]: json [getFileName()]: json
} }
} }
// Legacy fallback where the metrics are encoded as arrays: // Legacy fallback where the metrics are encoded as arrays:
// { PAGE: [[metric_name, ...], [...], ]} // { 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 { return {
[tempName]: json [getFileName()]: json
} }
} }
return json return json
...@@ -2705,4 +2709,4 @@ code is governed by a BSD-style license that can be found in the LICENSE file. ...@@ -2705,4 +2709,4 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -494,11 +494,9 @@ def print_stats(S, args): ...@@ -494,11 +494,9 @@ def print_stats(S, args):
def extract_domain(filename): def extract_domain(filename):
print(filename)
# Extract domain name: domain#123.txt or domain_123.txt # Extract domain name: domain#123.txt or domain_123.txt
match = re.match(r'^(.*?)[^a-zA-Z]?[0-9]+?.txt', filename) match = re.match(r'^(.*?)[^a-zA-Z]?[0-9]+?.txt', filename)
domain = match.group(1) domain = match.group(1)
print(domain)
return domain return domain
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment