-
Notifications
You must be signed in to change notification settings - Fork 1
performanceUtils
measureCpuUsage<
TRunner>(runner,usesOneThread,startTime):Promise<readonly [Awaited<TRunner>,number]>
Defined in: src/performanceUtils.mts:19
Measure the CPU usage in percent of the provided runner function.
| Type Parameter |
|---|
TRunner |
| Parameter | Type | Default value | Description |
|---|---|---|---|
runner |
() => TRunner | Promise<TRunner> |
undefined |
Function whose CPU usage to measure. |
usesOneThread |
boolean |
false |
Optional boolean to decide if 1 or all threads should be used to compute the percent value. |
startTime |
number |
... |
Optional time in milliseconds when the elapsed time starts counting. |
Promise<readonly [Awaited<TRunner>, number]>
A tuple containing the return value of the passed-in function and the CPU usage in percent.
const [computationResult, cpuUsagePercent] = await measureCpuUsage(() => expensiveComputation());measurePerformanceMetrics<
TRunner>(metricName,request,runner,metricDescription?,usesOneThread?):Promise<readonly [Awaited<TRunner>,number,number]>
Defined in: src/performanceUtils.mts:47
Measure performance metrics of the provided runner function. Specifically, Server-Timing
duration and CPU usage percent is computed.
| Type Parameter |
|---|
TRunner |
| Parameter | Type | Default value | Description |
|---|---|---|---|
metricName |
string |
undefined |
Name of the Server-Timing metric being measured. |
request |
Request |
undefined |
Request object to which the Server-Timing header will be appended. |
runner |
() => TRunner | Promise<TRunner> |
undefined |
Function whose execution duration and CPU usage percentage will be computed. |
metricDescription? |
string |
undefined |
Optional description of the Server-Timing metric being measured. |
usesOneThread? |
boolean |
false |
Optional boolean to decide if 1 or all threads should be used to compute the percent value. |
Promise<readonly [Awaited<TRunner>, number, number]>
A tuple containing the return value of the passed-in function, the execution duration, and the CPU usage in percent.