human/src/profile.ts

25 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-03-21 12:49:55 +01:00
import { log } from './helpers';
2020-12-08 15:00:44 +01:00
2021-02-08 17:39:09 +01:00
export const data = {};
2020-11-01 19:07:53 +01:00
2021-03-18 01:16:40 +01:00
export function run(name: string, raw: any): void {
2021-02-08 17:39:09 +01:00
if (!raw || !raw.kernels) return;
2020-11-01 19:07:53 +01:00
const maxResults = 5;
2021-02-08 17:39:09 +01:00
const time = raw.kernels
2020-11-01 19:07:53 +01:00
.filter((a) => a.kernelTimeMs > 0)
.reduce((a, b) => a += b.kernelTimeMs, 0);
2021-02-08 17:39:09 +01:00
const slowest = raw.kernels
2020-11-01 19:07:53 +01:00
.map((a, i) => { a.id = i; return a; })
.filter((a) => a.kernelTimeMs > 0)
.sort((a, b) => b.kernelTimeMs - a.kernelTimeMs);
2021-02-08 17:39:09 +01:00
const largest = raw.kernels
2020-11-01 19:07:53 +01:00
.map((a, i) => { a.id = i; return a; })
.filter((a) => a.totalBytesSnapshot > 0)
.sort((a, b) => b.totalBytesSnapshot - a.totalBytesSnapshot);
if (slowest.length > maxResults) slowest.length = maxResults;
if (largest.length > maxResults) largest.length = maxResults;
2021-02-08 17:39:09 +01:00
const res = { newBytes: raw.newBytes, newTensors: raw.newTensors, peakBytes: raw.peakBytes, numKernelOps: raw.kernels.length, timeKernelOps: time, slowestKernelOps: slowest, largestKernelOps: largest };
data[name] = res;
2020-12-08 15:00:44 +01:00
log('Human profiler', name, res);
2020-11-01 19:07:53 +01:00
}