support to profile a tick, move to /node

This commit is contained in:
Johannes Rieken
2017-05-17 15:59:13 +02:00
parent f4a351fc08
commit 84d4fc595c
5 changed files with 41 additions and 12 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ const vscodeResources = [
'out-build/bootstrap-amd.js',
'out-build/paths.js',
'out-build/vs/**/*.{svg,png,cur,html}',
'out-build/vs/base/common/startupTimers.js',
'out-build/vs/base/node/startupTimers.js',
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh}',
'out-build/vs/base/browser/ui/octiconLabel/octicons/**',
'out-build/vs/workbench/browser/media/*-theme.css',
+3 -3
View File
@@ -45,7 +45,7 @@ export function stopProfiling(dir: string, prefix: string): TPromise<string> {
});
}
function removePiiPaths(profile: Profile) {
export function removePiiPaths(profile: Profile) {
const stack = [profile.head];
while (stack.length > 0) {
const element = stack.pop();
@@ -66,14 +66,14 @@ declare interface Profiler {
stopProfiling(): Profile;
}
declare interface Profile {
export declare interface Profile {
title: string;
export(callback: (err, data) => void);
delete();
head: ProfileSample;
}
declare interface ProfileSample {
export declare interface ProfileSample {
// bailoutReason:""
// callUID:2333
// children:Array[39]
@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Profile } from './profiler'
declare interface TickStart {
name: string;
started: number;
@@ -14,6 +16,7 @@ export declare class Tick {
readonly name: string;
readonly started: number;
readonly stopped: number;
readonly profile: Profile;
static compareByStart(a: Tick, b: Tick): number;
}
@@ -29,4 +32,6 @@ export function stopTimer(name: string, stopped?: number);
export function ticks(): ReadonlyArray<Tick>;
export function setProfileList(names: string[]): void;
export function disable(): void;
@@ -5,20 +5,32 @@
'use strict';
if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {
var requireProfiler;
if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {
// this is commonjs, fake amd
global.define = function (dep, callback) {
module.exports = callback();
global.define = undefined;
}
requireProfiler = function () {
return require('v8-profiler');
}
} else {
// this is amd
requireProfiler = function () {
return require.__$__nodeRequire('v8-profiler');
}
}
define([], function () {
function Tick(name, started, stopped) {
this.name = name;
this.started = started;
this.stopped = stopped;
function Tick(name, started, stopped, profile) {
this.name = name
this.started = started
this.stopped = stopped
this.duration = stopped - started;
this.profile = profile;
}
Tick.compareByStart = function (a, b) {
if (a.started < b.started) {
@@ -35,9 +47,11 @@ define([], function () {
// we store them globally
global._perfStarts = global._perfStarts || new Map();
global._perfTicks = global._perfTicks || [];
global._perfToBeProfiled = global._perfToBeProfiled || new Set();
const _starts = global._perfStarts;
const _ticks = global._perfTicks;
const _toBeProfiled = global._perfToBeProfiled
function startTimer(name, started) {
if (typeof started !== 'number') {
@@ -46,6 +60,9 @@ define([], function () {
if (_starts.has(name)) {
throw new Error("${name}" + " already exists");
}
if (_toBeProfiled.has(name)) {
requireProfiler().startProfiling(name, true);
}
_starts.set(name, { name: name, started: started });
const stop = stopTimer.bind(undefined, name);
return {
@@ -61,8 +78,9 @@ define([], function () {
if (typeof stopped !== 'number') {
stopped = Date.now();
}
const profile = _toBeProfiled.has(name) ? requireProfiler().stopProfiling(name) : undefined;
const start = _starts.get(name);
const tick = new Tick(start.name, start.started, stopped);
const tick = new Tick(start.name, start.started, stopped, profile);
_ticks.push(tick);
_starts.delete(name);
}
@@ -71,12 +89,18 @@ define([], function () {
return _ticks;
}
function setProfileList(names) {
_toBeProfiled.clear();
names.forEach(function (name) { _toBeProfiled.add(name) });
}
const exports = {
Tick: Tick,
startTimer: startTimer,
stopTimer: stopTimer,
ticks: ticks,
disable: disable
setProfileList: setProfileList,
disable: disable,
};
function disable() {
@@ -16,7 +16,7 @@ import { Delayer } from 'vs/base/common/async';
import * as browser from 'vs/base/browser/browser';
import assert = require('vs/base/common/assert');
import { StopWatch } from 'vs/base/common/stopwatch';
import { startTimer } from 'vs/base/common/startupTimers';
import { startTimer } from 'vs/base/node/startupTimers';
import errors = require('vs/base/common/errors');
import { BackupFileService } from 'vs/workbench/services/backup/node/backupFileService';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';