Files
azuredatastudio/src/vs/base/common/performance.js
Anthony Dresser 87765e8673 Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd

* fix issues with merges

* bump node version in azpipe

* replace license headers

* remove duplicate launch task

* fix build errors

* fix build errors

* fix tslint issues

* working through package and linux build issues

* more work

* wip

* fix packaged builds

* working through linux build errors

* wip

* wip

* wip

* fix mac and linux file limits

* iterate linux pipeline

* disable editor typing

* revert series to parallel

* remove optimize vscode from linux

* fix linting issues

* revert testing change

* add work round for new node

* readd packaging for extensions

* fix issue with angular not resolving decorator dependencies
2019-03-19 17:44:35 -07:00

109 lines
2.6 KiB
JavaScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
//@ts-check
function _factory(sharedObj) {
sharedObj._performanceEntries = sharedObj._performanceEntries || [];
const _dataLen = 2;
const _timeStamp = typeof console.timeStamp === 'function' ? console.timeStamp.bind(console) : () => { };
function importEntries(entries) {
sharedObj._performanceEntries.splice(0, 0, ...entries);
}
function exportEntries() {
return sharedObj._performanceEntries.slice(0);
}
function getEntries() {
const result = [];
const entries = sharedObj._performanceEntries;
for (let i = 0; i < entries.length; i += _dataLen) {
result.push({
name: entries[i],
timestamp: entries[i + 1],
});
}
return result;
}
function getEntry(name) {
const entries = sharedObj._performanceEntries;
for (let i = 0; i < entries.length; i += _dataLen) {
if (entries[i] === name) {
return {
name: entries[i],
timestamp: entries[i + 1],
};
}
}
}
function getDuration(from, to) {
const entries = sharedObj._performanceEntries;
let target = to;
let endIndex = 0;
for (let i = entries.length - _dataLen; i >= 0; i -= _dataLen) {
if (entries[i] === target) {
if (target === to) {
// found `to` (end of interval)
endIndex = i;
target = from;
} else {
// found `from` (start of interval)
return entries[endIndex + 1] - entries[i + 1];
}
}
}
return 0;
}
function mark(name) {
sharedObj._performanceEntries.push(name, Date.now());
_timeStamp(name);
}
const exports = {
mark: mark,
getEntries: getEntries,
getEntry: getEntry,
getDuration: getDuration,
importEntries: importEntries,
exportEntries: exportEntries
};
return exports;
}
// 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
let sharedObj;
if (typeof global === 'object') {
// nodejs
sharedObj = global;
} else if (typeof self === 'object') {
// browser
sharedObj = self;
} else {
sharedObj = {};
}
if (typeof define === 'function') {
// amd
define([], function () { return _factory(sharedObj); });
} else if (typeof module === "object" && typeof module.exports === "object") {
// commonjs
module.exports = _factory(sharedObj);
} else {
// invalid context...
}