-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d792e86
commit 1916650
Showing
6 changed files
with
209 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export enum MetricOperation { | ||
FETCH_SHEET_DATA = 'FETCH_SHEET_DATA', | ||
FETCH_SHEET_DETAILS = 'FETCH_SHEET_DETAILS', | ||
/** | ||
* Includes delete & deleteAll operations | ||
*/ | ||
FETCH_SHEET_HEADERS = 'FETCH_SHEET_HEADERS', | ||
/** | ||
* Includes create & createAll operations. | ||
*/ | ||
SHEET_APPEND = 'SHEET_APPEND', | ||
/** | ||
* Includes delete & deleteAll operations. | ||
*/ | ||
SHEET_DELETE = 'SHEET_DELETE', | ||
/** | ||
* Includes update & updateAll operations. | ||
*/ | ||
SHEET_UPDATE = 'SHEET_UPDATE', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MetricOperation } from './MetricOperation'; | ||
|
||
export type MilliSecondsByOperation = { | ||
[x: string]: number[]; | ||
}; | ||
|
||
export class Metrics { | ||
constructor(private readonly msByOperation: Map<MetricOperation, number[]> = new Map<MetricOperation, number[]>()) {} | ||
|
||
public async trackExecutionTime<T>(op: MetricOperation, func: () => Promise<T>): Promise<T> { | ||
const startTime = Date.now(); | ||
const result = await func(); | ||
const executionTime = Date.now() - startTime; | ||
this.report(op, executionTime); | ||
return result; | ||
} | ||
|
||
private report(op: MetricOperation, millis: number): void { | ||
if (this.msByOperation.has(op)) { | ||
this.msByOperation.get(op)!.push(millis); | ||
} else { | ||
this.msByOperation.set(op, [millis]); | ||
} | ||
} | ||
|
||
public toObject(): MilliSecondsByOperation { | ||
return Object.fromEntries(this.msByOperation.entries()); | ||
} | ||
} |
Oops, something went wrong.