1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Add some perfomance logs (#3965)

* Add some perfomance logs

* missing return
This commit is contained in:
Valere
2023-12-18 15:35:45 +01:00
committed by GitHub
parent 2c13e133b7
commit a80e90b42d
6 changed files with 70 additions and 24 deletions

View File

@@ -25,6 +25,7 @@ import { Optional } from "matrix-events-sdk";
import { IEvent, MatrixEvent } from "./models/event";
import { M_TIMESTAMP } from "./@types/location";
import { ReceiptType } from "./@types/read_receipts";
import { Logger } from "./logger";
const interns = new Map<string, string>();
@@ -387,6 +388,23 @@ export function sleep<T>(ms: number, value?: T): Promise<T> {
});
}
/**
* Utility to log the duration of a promise.
*
* @param logger - The logger to log to.
* @param name - The name of the operation.
* @param block - The block to execute.
*/
export async function logDuration<T>(logger: Logger, name: string, block: () => Promise<T>): Promise<T> {
const start = Date.now();
try {
return await block();
} finally {
const end = Date.now();
logger.debug(`[Perf]: ${name} took ${end - start}ms`);
}
}
/**
* Promise/async version of {@link setImmediate}.
*/