-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add timer around each metric * chore: add ts migration metrics * feat: warn if metrics take longer * ci: add comment
- Loading branch information
Showing
5 changed files
with
85 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const YELLOW = '\x1B[33m' | ||
const RESET = '\x1B[0m' | ||
|
||
export function warn(message) { | ||
console.warn(`${YELLOW}⚠️ ${message}${RESET}`) | ||
} |
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,37 @@ | ||
import { warn } from './console.js' | ||
|
||
let timers = {} | ||
|
||
/** | ||
* Executes a provided function block and measures its execution time. | ||
* Logs a message if the execution time exceeds 2 seconds. | ||
* | ||
* @param {Function} codeBlock - The block of code to execute. | ||
* @returns {*} The result of the executed code block. | ||
*/ | ||
export async function executeWithTiming(codeBlock, identifier) { | ||
const startTime = performance.now() | ||
|
||
const result = await codeBlock() | ||
|
||
const endTime = performance.now() | ||
const executionTime = endTime - startTime | ||
|
||
timers[identifier] = executionTime | ||
|
||
return result | ||
} | ||
|
||
/** | ||
* Logs a warning for each long running task. | ||
* A task is considered long running if it takes longer than the provided time limit. | ||
* | ||
* @param {number} timeLimitInMs - The time limit in milliseconds. | ||
*/ | ||
export function warnsAboutLongRunningTasks(timeLimitInMs) { | ||
for (const [identifier, executionTime] of Object.entries(timers).sort()) { | ||
if (executionTime > timeLimitInMs) { | ||
warn(`${identifier} took ${Math.round(executionTime)}ms`) | ||
} | ||
} | ||
} |
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