From 77e6c5e7cfc5c76e9d59484fe462eb4b5f6f898f Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Thu, 27 Sep 2018 12:15:38 -0700 Subject: [PATCH] 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 --- Libraries/Utilities/PerformanceLogger.js | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Libraries/Utilities/PerformanceLogger.js b/Libraries/Utilities/PerformanceLogger.js index 1eb7d9fae..fa140f060 100644 --- a/Libraries/Utilities/PerformanceLogger.js +++ b/Libraries/Utilities/PerformanceLogger.js @@ -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;