提交 08d0aa59 编写于 作者: J Johannes Rieken

store marks and measurements flat, only create objects when needed

上级 0cb6309c
......@@ -21,9 +21,9 @@ export function time(name: string): { stop(): void };
/**
* All entries filtered by type and sorted by `startTime`.
*/
export function getEntries(type?: 'mark' | 'measure'): PerformanceEntry[];
export function getEntries(type: 'mark' | 'measure'): PerformanceEntry[];
/**
* Import entries
*/
export function importEntries(entries: PerformanceEntry[]): void;
type ExportData = any[];
export function importEntries(data: ExportData): void;
export function exportEntries(): ExportData;
......@@ -10,6 +10,7 @@
// This module can be loaded in an amd and commonjs-context.
// Because we want both instances to use the same perf-data
// we store them globally
// stores data as 'type','name','startTime','duration'
global._performanceEntries = global._performanceEntries || [];
if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {
......@@ -25,42 +26,35 @@ define([], function () {
// const _now = global.performance && performance.now ? performance.now : Date.now
const _now = Date.now;
class PerformanceEntry {
constructor(type, name, startTime, duration) {
this.type = type;
this.name = name;
this.startTime = startTime;
this.duration = duration;
}
function importEntries(entries) {
global._performanceEntries.splice(0, 0, ...entries);
}
function _getEntry(type, name) {
for (let i = global._performanceEntries.length - 1; i >= 0; i--) {
if (
(type === undefined || global._performanceEntries[i].type === type) &&
(name === undefined || global._performanceEntries[i].name === name)
) {
return global._performanceEntries[i];
}
}
function exportEntries() {
return global._performanceEntries.splice(0);
}
function importEntries(entries) {
global._performanceEntries.splice(0, 0, ...entries);
}
function getEntries(type) {
const result = [];
const entries = global._performanceEntries;
for (let i = 0; i < entries.length; i += 4) {
if (entries[i] === type) {
result.push({
type: entries[i],
name: entries[i + 1],
startTime: entries[i + 2],
duration: entries[i + 3],
});
}
}
function getEntries(type, name) {
return global._performanceEntries.filter(entry => {
return (type === undefined || entry.type === type) &&
(name === undefined || entry.name === name);
}).sort((a, b) => {
return result.sort((a, b) => {
return a.startTime - b.startTime;
});
}
function mark(name) {
const entry = new PerformanceEntry('mark', name, _now(), 0);
global._performanceEntries.push(entry);
global._performanceEntries.push('mark', name, _now(), 0);
if (typeof console.timeStamp === 'function') {
console.timeStamp(name);
}
......@@ -81,17 +75,27 @@ define([], function () {
if (!from) {
startTime = now;
} else {
startTime = _getEntry(undefined, from).startTime;
startTime = _getLastStartTime(from);
}
if (!to) {
duration = now - startTime;
} else {
duration = _getEntry(undefined, to).startTime - startTime;
duration = _getLastStartTime(to) - startTime;
}
global._performanceEntries.push('measure', name, startTime, duration);
}
function _getLastStartTime(name) {
const entries = global._performanceEntries;
for (let i = entries.length - 1; i >= 0; i -= 4) {
if (entries[i - 2] === name) {
return entries[i - 1];
}
}
const entry = new PerformanceEntry('measure', name, startTime, duration);
global._performanceEntries.push(entry);
throw new Error(name + ' not found');
}
var exports = {
......@@ -99,7 +103,8 @@ define([], function () {
measure: measure,
time: time,
getEntries: getEntries,
importEntries: importEntries
importEntries: importEntries,
exportEntries: exportEntries
};
return exports;
......
......@@ -26,7 +26,7 @@ import { ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { IWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces';
import { IBackupMainService } from 'vs/platform/backup/common/backup';
import { ICommandAction } from 'vs/platform/actions/common/actions';
import { mark, getEntries } from 'vs/base/common/performance';
import { mark, exportEntries } from 'vs/base/common/performance';
export interface IWindowState {
width?: number;
......@@ -580,7 +580,7 @@ export class CodeWindow implements ICodeWindow {
windowConfiguration.backgroundColor = this.getBackgroundColor();
// Perf Counters
windowConfiguration.perfEntries = getEntries();
windowConfiguration.perfEntries = exportEntries();
windowConfiguration.perfStartTime = global.perfStartTime;
windowConfiguration.perfAppReady = global.perfAppReady;
windowConfiguration.perfWindowLoadTime = Date.now();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册