Support logging points from JS

Summary: We want to be able to log individual points from JS.

Reviewed By: ejanzer

Differential Revision: D10050400

fbshipit-source-id: eadd81a8cf70082998950c19a98c3de979eb148a
This commit is contained in:
Alexey Lang 2018-09-27 12:15:38 -07:00 коммит произвёл Facebook Github Bot
Родитель 0ee23d0beb
Коммит 77e6c5e7cf
1 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@ -26,6 +26,7 @@ type Timespan = {
let timespans: {[key: string]: Timespan} = {};
let extras: {[key: string]: any} = {};
let points: {[key: string]: number} = {};
const cookies: {[key: string]: number} = {};
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
@ -107,6 +108,7 @@ const PerformanceLogger = {
clear() {
timespans = {};
extras = {};
points = {};
if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clear');
}
@ -119,6 +121,7 @@ const PerformanceLogger = {
}
}
extras = {};
points = {};
if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clearCompleted');
}
@ -132,6 +135,7 @@ const PerformanceLogger = {
return previous;
}, {});
extras = {};
points = {};
if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clearExceptTimespans', keys);
}
@ -188,6 +192,29 @@ const PerformanceLogger = {
logExtras() {
infoLog(extras);
},
markPoint(key: string) {
if (points[key]) {
if (__DEV__) {
infoLog(
'PerformanceLogger: Attempting to mark a point that has been already logged ',
key,
);
}
return;
}
points[key] = performanceNow();
},
getPoints() {
return points;
},
logPoints() {
for (const key in points) {
infoLog(key + ': ' + points[key] + 'ms');
}
},
};
module.exports = PerformanceLogger;