2021-05-18 13:31:00 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/restrict-plus-operands */
|
|
|
|
|
|
|
|
|
|
// parse-profiler
|
|
|
|
|
//
|
|
|
|
|
// this script is used to parse performance profiling result.
|
|
|
|
|
// usage:
|
|
|
|
|
// STEP.1 - profiling
|
|
|
|
|
// > npm test -- model test/test-data/{path-to-my-model} --backend={cpu/webgl/wasm} --profile > profile.raw.log
|
|
|
|
|
// STEP.2 - parse
|
|
|
|
|
// > node script/parse-profiler < profile.raw.log > profile.parsed.log
|
|
|
|
|
|
|
|
|
|
import * as readline from 'readline';
|
2024-08-14 23:51:22 +00:00
|
|
|
const lines = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false });
|
2021-05-18 13:31:00 +00:00
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-control-regex
|
|
|
|
|
const matcher = /Profiler\.([^[\s\x1b]+)(\x1b\[0m)? (\d.+Z)\|([\d.]+)ms on event '([^']+)' at (\d*\.*\d*)/;
|
|
|
|
|
|
|
|
|
|
const allEvents: any[] = [];
|
2024-08-14 23:51:22 +00:00
|
|
|
lines.on('line', (input) => {
|
2021-05-18 13:31:00 +00:00
|
|
|
const matches = matcher.exec(input);
|
|
|
|
|
if (matches) {
|
|
|
|
|
// console.log(matches);
|
|
|
|
|
const category = matches[1];
|
|
|
|
|
const logTimeStamp = new Date(matches[3]);
|
|
|
|
|
const ms = Number.parseFloat(matches[4]);
|
|
|
|
|
const event = matches[5];
|
|
|
|
|
const endTimeInNumber = matches[6];
|
2024-08-14 23:51:22 +00:00
|
|
|
allEvents.push({ event, ms, logTimeStamp, category, endTimeInNumber });
|
2021-05-18 13:31:00 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lines.on('close', () => {
|
|
|
|
|
for (const i of allEvents) {
|
2024-08-14 23:51:22 +00:00
|
|
|
console.log(
|
|
|
|
|
`${(i.category + ' ').substring(0, 12)} ${(i.ms + ' ').substring(0, 12)} ${(
|
|
|
|
|
i.event + ' '
|
|
|
|
|
).substring(0, 40)} ${i.endTimeInNumber}`,
|
|
|
|
|
);
|
2021-05-18 13:31:00 +00:00
|
|
|
}
|
|
|
|
|
});
|