From 6d355c0abd6e09f69cd30f43c976183fafa136d2 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 23 Sep 2020 15:46:58 -0700 Subject: [PATCH] Sort logger alphabetically Summary: Rearranging to alphabetically sort, no functionality changes Changelog: [Internal] Reviewed By: rubennorte, motiz88 Differential Revision: D23836997 fbshipit-source-id: 00232b88379e44920ecb74fa6ff43f36d941d93b --- .../Utilities/createPerformanceLogger.js | 214 +++++++++--------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/Libraries/Utilities/createPerformanceLogger.js b/Libraries/Utilities/createPerformanceLogger.js index 195c1b30807..28e0c5ab149 100644 --- a/Libraries/Utilities/createPerformanceLogger.js +++ b/Libraries/Utilities/createPerformanceLogger.js @@ -37,20 +37,20 @@ export interface IPerformanceLogger { startExtras?: Extras, endExtras?: Extras, ): void; - startTimespan(key: string, extras?: Extras): void; - stopTimespan(key: string, extras?: Extras): void; clear(): void; clearCompleted(): void; currentTimestamp(): number; - getTimespans(): {[key: string]: Timespan, ...}; - hasTimespan(key: string): boolean; - setExtra(key: string, value: ExtraValue): void; getExtras(): {[key: string]: ExtraValue, ...}; - removeExtra(key: string): ExtraValue | void; - markPoint(key: string, timestamp?: number, extras?: Extras): void; getPoints(): {[key: string]: number, ...}; getPointExtras(): {[key: string]: Extras, ...}; + getTimespans(): {[key: string]: Timespan, ...}; + hasTimespan(key: string): boolean; logEverything(): void; + markPoint(key: string, timestamp?: number, extras?: Extras): void; + removeExtra(key: string): ExtraValue | void; + setExtra(key: string, value: ExtraValue): void; + startTimespan(key: string, extras?: Extras): void; + stopTimespan(key: string, extras?: Extras): void; } const _cookies: {[key: string]: number, ...} = {}; @@ -89,6 +89,106 @@ class PerformanceLogger implements IPerformanceLogger { }; } + clear() { + this._timespans = {}; + this._extras = {}; + this._points = {}; + if (PRINT_TO_CONSOLE) { + infoLog('PerformanceLogger.js', 'clear'); + } + } + + clearCompleted() { + for (const key in this._timespans) { + if (this._timespans[key].totalTime != null) { + delete this._timespans[key]; + } + } + this._extras = {}; + this._points = {}; + if (PRINT_TO_CONSOLE) { + infoLog('PerformanceLogger.js', 'clearCompleted'); + } + } + + currentTimestamp() { + return performanceNow(); + } + + getExtras() { + return this._extras; + } + + getPoints() { + return this._points; + } + + getPointExtras() { + return this._pointExtras; + } + + getTimespans() { + return this._timespans; + } + + hasTimespan(key: string) { + return !!this._timespans[key]; + } + + logEverything() { + if (PRINT_TO_CONSOLE) { + // log timespans + for (const key in this._timespans) { + if (this._timespans[key].totalTime != null) { + infoLog(key + ': ' + this._timespans[key].totalTime + 'ms'); + } + } + + // log extras + infoLog(this._extras); + + // log points + for (const key in this._points) { + infoLog(key + ': ' + this._points[key] + 'ms'); + } + } + } + + markPoint(key: string, timestamp?: number, extras?: Extras) { + if (this._points[key]) { + if (PRINT_TO_CONSOLE && __DEV__) { + infoLog( + 'PerformanceLogger: Attempting to mark a point that has been already logged ', + key, + ); + } + return; + } + this._points[key] = timestamp ?? performanceNow(); + if (extras) { + this._pointExtras[key] = extras; + } + } + + removeExtra(key: string): ExtraValue | void { + const value = this._extras[key]; + delete this._extras[key]; + return value; + } + + setExtra(key: string, value: ExtraValue) { + if (this._extras.hasOwnProperty(key)) { + if (PRINT_TO_CONSOLE && __DEV__) { + infoLog( + 'PerformanceLogger: Attempting to set an extra that already exists ', + {key, currentValue: this._extras[key], attemptedValue: value}, + ); + } + return; + } + this._extras[key] = value; + } + startTimespan(key: string, extras?: Extras) { if (this._timespans[key]) { if (PRINT_TO_CONSOLE && __DEV__) { @@ -143,106 +243,6 @@ class PerformanceLogger implements IPerformanceLogger { delete _cookies[key]; } } - - clear() { - this._timespans = {}; - this._extras = {}; - this._points = {}; - if (PRINT_TO_CONSOLE) { - infoLog('PerformanceLogger.js', 'clear'); - } - } - - clearCompleted() { - for (const key in this._timespans) { - if (this._timespans[key].totalTime != null) { - delete this._timespans[key]; - } - } - this._extras = {}; - this._points = {}; - if (PRINT_TO_CONSOLE) { - infoLog('PerformanceLogger.js', 'clearCompleted'); - } - } - - currentTimestamp() { - return performanceNow(); - } - - getTimespans() { - return this._timespans; - } - - hasTimespan(key: string) { - return !!this._timespans[key]; - } - - setExtra(key: string, value: ExtraValue) { - if (this._extras.hasOwnProperty(key)) { - if (PRINT_TO_CONSOLE && __DEV__) { - infoLog( - 'PerformanceLogger: Attempting to set an extra that already exists ', - {key, currentValue: this._extras[key], attemptedValue: value}, - ); - } - return; - } - this._extras[key] = value; - } - - getExtras() { - return this._extras; - } - - removeExtra(key: string): ExtraValue | void { - const value = this._extras[key]; - delete this._extras[key]; - return value; - } - - markPoint(key: string, timestamp?: number, extras?: Extras) { - if (this._points[key]) { - if (PRINT_TO_CONSOLE && __DEV__) { - infoLog( - 'PerformanceLogger: Attempting to mark a point that has been already logged ', - key, - ); - } - return; - } - this._points[key] = timestamp ?? performanceNow(); - if (extras) { - this._pointExtras[key] = extras; - } - } - - getPoints() { - return this._points; - } - - getPointExtras() { - return this._pointExtras; - } - - logEverything() { - if (PRINT_TO_CONSOLE) { - // log timespans - for (const key in this._timespans) { - if (this._timespans[key].totalTime != null) { - infoLog(key + ': ' + this._timespans[key].totalTime + 'ms'); - } - } - - // log extras - infoLog(this._extras); - - // log points - for (const key in this._points) { - infoLog(key + ': ' + this._points[key] + 'ms'); - } - } - } } /**