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 committed by Facebook Github Bot
parent 0ee23d0beb
commit 77e6c5e7cf

View File

@ -26,6 +26,7 @@ type Timespan = {
let timespans: {[key: string]: Timespan} = {}; let timespans: {[key: string]: Timespan} = {};
let extras: {[key: string]: any} = {}; let extras: {[key: string]: any} = {};
let points: {[key: string]: number} = {};
const cookies: {[key: string]: number} = {}; const cookies: {[key: string]: number} = {};
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`; const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
@ -107,6 +108,7 @@ const PerformanceLogger = {
clear() { clear() {
timespans = {}; timespans = {};
extras = {}; extras = {};
points = {};
if (PRINT_TO_CONSOLE) { if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clear'); infoLog('PerformanceLogger.js', 'clear');
} }
@ -119,6 +121,7 @@ const PerformanceLogger = {
} }
} }
extras = {}; extras = {};
points = {};
if (PRINT_TO_CONSOLE) { if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clearCompleted'); infoLog('PerformanceLogger.js', 'clearCompleted');
} }
@ -132,6 +135,7 @@ const PerformanceLogger = {
return previous; return previous;
}, {}); }, {});
extras = {}; extras = {};
points = {};
if (PRINT_TO_CONSOLE) { if (PRINT_TO_CONSOLE) {
infoLog('PerformanceLogger.js', 'clearExceptTimespans', keys); infoLog('PerformanceLogger.js', 'clearExceptTimespans', keys);
} }
@ -188,6 +192,29 @@ const PerformanceLogger = {
logExtras() { logExtras() {
infoLog(extras); 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; module.exports = PerformanceLogger;