Skip to content

Commit d9643e2

Browse files
alexeylangfacebook-github-bot
authored andcommitted
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
1 parent bc8dcbb commit d9643e2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Libraries/Utilities/PerformanceLogger.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Timespan = {
2626

2727
let timespans: {[key: string]: Timespan} = {};
2828
let extras: {[key: string]: any} = {};
29+
let points: {[key: string]: number} = {};
2930
const cookies: {[key: string]: number} = {};
3031

3132
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
@@ -107,6 +108,7 @@ const PerformanceLogger = {
107108
clear() {
108109
timespans = {};
109110
extras = {};
111+
points = {};
110112
if (PRINT_TO_CONSOLE) {
111113
infoLog('PerformanceLogger.js', 'clear');
112114
}
@@ -119,6 +121,7 @@ const PerformanceLogger = {
119121
}
120122
}
121123
extras = {};
124+
points = {};
122125
if (PRINT_TO_CONSOLE) {
123126
infoLog('PerformanceLogger.js', 'clearCompleted');
124127
}
@@ -132,6 +135,7 @@ const PerformanceLogger = {
132135
return previous;
133136
}, {});
134137
extras = {};
138+
points = {};
135139
if (PRINT_TO_CONSOLE) {
136140
infoLog('PerformanceLogger.js', 'clearExceptTimespans', keys);
137141
}
@@ -188,6 +192,29 @@ const PerformanceLogger = {
188192
logExtras() {
189193
infoLog(extras);
190194
},
195+
196+
markPoint(key: string) {
197+
if (points[key]) {
198+
if (__DEV__) {
199+
infoLog(
200+
'PerformanceLogger: Attempting to mark a point that has been already logged ',
201+
key,
202+
);
203+
}
204+
return;
205+
}
206+
points[key] = performanceNow();
207+
},
208+
209+
getPoints() {
210+
return points;
211+
},
212+
213+
logPoints() {
214+
for (const key in points) {
215+
infoLog(key + ': ' + points[key] + 'ms');
216+
}
217+
},
191218
};
192219

193220
module.exports = PerformanceLogger;

0 commit comments

Comments
 (0)