mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 13:43:07 +00:00
store marks and measurements flat, only create objects when needed
This commit is contained in:
parent
0cb6309c78
commit
08d0aa5949
3 changed files with 44 additions and 39 deletions
10
src/vs/base/common/performance.d.ts
vendored
10
src/vs/base/common/performance.d.ts
vendored
|
@ -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 _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 importEntries(entries) {
|
||||
global._performanceEntries.splice(0, 0, ...entries);
|
||||
}
|
||||
|
||||
function getEntries(type, name) {
|
||||
return global._performanceEntries.filter(entry => {
|
||||
return (type === undefined || entry.type === type) &&
|
||||
(name === undefined || entry.name === name);
|
||||
}).sort((a, b) => {
|
||||
function exportEntries() {
|
||||
return global._performanceEntries.splice(0);
|
||||
}
|
||||
|
||||
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],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const entry = new PerformanceEntry('measure', name, startTime, duration);
|
||||
global._performanceEntries.push(entry);
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue