v8/tools/system-analyzer/ic-model.mjs
Zeynep Cankara e8d24c66b9 [tools][system-analyzer] Support time logging for IC Events
This CL modifies the logging pipeline of V8 to track
timestamps of the IC events across the log file.

Modifies the current IC-explorer's code to make it
compatible with the IC event time processing.

Change-Id: I2a0f652e2657bdebe8cecd7862a7545f7b050cdb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2274613
Commit-Queue: Zeynep Cankara <zcankara@google.com>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68849}
2020-07-14 17:13:33 +00:00

59 lines
1.6 KiB
JavaScript

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import CustomIcProcessor from "./ic-processor.mjs";
// For compatibility with console scripts:
print = console.log;
export class Group {
constructor(property, key, entry) {
this.property = property;
this.key = key;
this.count = 1;
this.entries = [entry];
this.percentage = undefined;
this.groups = undefined;
}
add(entry) {
this.count++;
this.entries.push(entry)
}
createSubGroups() {
this.groups = {};
for (let i = 0; i < CustomIcProcessor.kProperties.length; i++) {
let subProperty = CustomIcProcessor.kProperties[i];
if (this.property == subProperty) continue;
this.groups[subProperty] = Group.groupBy(this.entries, subProperty);
}
}
static groupBy(entries, property) {
let accumulator = Object.create(null);
let length = entries.length;
for (let i = 0; i < length; i++) {
let entry = entries[i];
let key = entry[property];
if (accumulator[key] == undefined) {
accumulator[key] = new Group(property, key, entry);
} else {
let group = accumulator[key];
if (group.entries == undefined) console.log([group, entry]);
group.add(entry)
}
}
let result = [];
for (let key in accumulator) {
let group = accumulator[key];
group.percentage = Math.round(group.count / length * 100 * 100) / 100;
result.push(group);
}
result.sort((a, b) => {return b.count - a.count});
return result;
}
}