Permalink
Browse files

Cleanup PerformanceLogger a bit

Summary: `prettier`, lint, etc.

Reviewed By: javache

Differential Revision: D5156709

fbshipit-source-id: a9e63602c10e6e413446660b32ff972f5591c6d1
  • Loading branch information...
sahrens authored and facebook-github-bot committed Jun 1, 2017
1 parent a93b7a2 commit 2a3de8f192a07623bed0a84b53e6d6204e896d47
Showing with 24 additions and 24 deletions.
  1. +24 −24 Libraries/Utilities/PerformanceLogger.js
@@ -8,13 +8,16 @@
*
* @providesModule PerformanceLogger
* @flow
* @format
*/
'use strict';
const BatchedBridge = require('BatchedBridge');
const Systrace = require('Systrace');
const performanceNow = global.nativePerformanceNow || require('fbjs/lib/performanceNow');
const infoLog = require('infoLog');
const performanceNow =
global.nativePerformanceNow || require('fbjs/lib/performanceNow');
type Timespan = {
description?: string,
@@ -23,9 +26,9 @@ type Timespan = {
endTime?: number,
};
let timespans: {[key:string]: Timespan} = {};
let extras: {[key:string]: any} = {};
const cookies: {[key:string]: number} = {};
let timespans: {[key: string]: Timespan} = {};
let extras: {[key: string]: any} = {};
const cookies: {[key: string]: number} = {};
const PRINT_TO_CONSOLE = false;
@@ -37,9 +40,9 @@ const PerformanceLogger = {
addTimespan(key: string, lengthInMs: number, description?: string) {
if (timespans[key]) {
if (__DEV__) {
console.log(
infoLog(
'PerformanceLogger: Attempting to add a timespan that already exists ',
key
key,
);
}
return;
@@ -54,7 +57,7 @@ const PerformanceLogger = {
startTimespan(key: string, description?: string) {
if (timespans[key]) {
if (__DEV__) {
console.log(
infoLog(
'PerformanceLogger: Attempting to start a timespan that already exists ',
key,
);
@@ -68,15 +71,15 @@ const PerformanceLogger = {
};
cookies[key] = Systrace.beginAsyncEvent(key);
if (__DEV__ && PRINT_TO_CONSOLE) {
console.log('PerformanceLogger.js', 'start: ' + key);
infoLog('PerformanceLogger.js', 'start: ' + key);
}
},
stopTimespan(key: string) {
const timespan = timespans[key];
if (!timespan || !timespan.startTime) {
if (__DEV__) {
console.log(
infoLog(
'PerformanceLogger: Attempting to end a timespan that has not started ',
key,
);
@@ -85,9 +88,9 @@ const PerformanceLogger = {
}
if (timespan.endTime) {
if (__DEV__) {
console.log(
infoLog(
'PerformanceLogger: Attempting to end a timespan that has already ended ',
key
key,
);
}
return;
@@ -96,7 +99,7 @@ const PerformanceLogger = {
timespan.endTime = performanceNow();
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
if (__DEV__ && PRINT_TO_CONSOLE) {
console.log('PerformanceLogger.js', 'end: ' + key);
infoLog('PerformanceLogger.js', 'end: ' + key);
}
Systrace.endAsyncEvent(key, cookies[key]);
@@ -142,28 +145,28 @@ const PerformanceLogger = {
logTimespans() {
for (const key in timespans) {
if (timespans[key].totalTime) {
console.log(key + ': ' + timespans[key].totalTime + 'ms');
infoLog(key + ': ' + timespans[key].totalTime + 'ms');
}
}
},
addTimespans(newTimespans: Array<number>, labels: Array<string>) {
for (let i = 0, l = newTimespans.length; i < l; i += 2) {
const label = labels[i / 2];
for (let ii = 0, l = newTimespans.length; ii < l; ii += 2) {
const label = labels[ii / 2];
PerformanceLogger.addTimespan(
label,
(newTimespans[i + 1] - newTimespans[i]),
label
newTimespans[ii + 1] - newTimespans[ii],
label,
);
}
},
setExtra(key: string, value: any) {
if (extras[key]) {
if (__DEV__) {
console.log(
infoLog(
'PerformanceLogger: Attempting to set an extra that already exists ',
key
{key, currentValue: extras[key], attemptedValue: value},
);
}
return;
@@ -173,12 +176,9 @@ const PerformanceLogger = {
getExtras() {
return extras;
}
},
};
BatchedBridge.registerCallableModule(
'PerformanceLogger',
PerformanceLogger
);
BatchedBridge.registerCallableModule('PerformanceLogger', PerformanceLogger);
module.exports = PerformanceLogger;

0 comments on commit 2a3de8f

Please sign in to comment.