Skip to content

Commit 7abdd17

Browse files
authored
Use performance-now lib instead of perf-hooks to calc perf (#26)
* Log Telemetry from the Email Report Task * Fix telemetry logs * Add perfhooks * Use performance-now to calc performance numbers for telemetry
1 parent 9235bac commit 7abdd17

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

Tasks/emailReportTask/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"azure-pipelines-task-lib": "^2.8.0",
1212
"js2xmlparser": "^4.0.0",
1313
"nodemailer": "^6.3.0",
14+
"performance-now": "^2.1.0",
1415
"reflect-metadata": "^0.1.13",
1516
"xslt-processor": "^0.11.5"
1617
}
17-
}
18+
}d

Tasks/emailReportTask/providers/restclients/RetryablePromise.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { TelemetryLogger } from "../../telemetry/TelemetryLogger";
2-
const { performance } = require('perf_hooks');
2+
const now = require('performance-now');
33

44
export class RetryablePromise {
55

66
private static defaultRetryCount: number = 3;
77

88
public static async RetryAsync<T>(executor: () => Promise<T>, executorName: string, times: number = this.defaultRetryCount): Promise<T> {
9-
const perfStart = performance.now();
9+
const perfStart = now();
1010
let attemptNumber = 1;
1111
let lastError: Error;
1212
try {
@@ -31,7 +31,7 @@ export class RetryablePromise {
3131
finally {
3232
if (attemptNumber > 1) {
3333
// Log time taken after all retries
34-
TelemetryLogger.LogModulePerf(executorName, performance.now() - perfStart);
34+
TelemetryLogger.LogModulePerf(executorName, now() - perfStart);
3535
}
3636
}
3737
}

Tasks/emailReportTask/telemetry/TelemetryLogger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReportConfiguration } from "../config/ReportConfiguration";
22
import { PipelineType } from "../config/pipeline/PipelineType";
33
import { EnumUtils } from "../utils/EnumUtils";
4-
const { performance } = require('perf_hooks');
4+
const now = require("performance-now")
55

66
export class TelemetryLogger {
77
public static readonly TELEMETRY_LINE =
@@ -87,14 +87,14 @@ export class TelemetryLogger {
8787
}
8888

8989
public static async InvokeWithPerfLogger<T>(executor: () => Promise<T>, executorName: string): Promise<T> {
90-
const perfStart = performance.now();
90+
const perfStart = now();
9191
let returnVal: T;
9292
try {
9393
returnVal = await executor();
9494
}
9595
finally {
9696
// Log time taken by the dataprovider
97-
TelemetryLogger.LogModulePerf(executorName, performance.now() - perfStart);
97+
TelemetryLogger.LogModulePerf(executorName, now() - perfStart);
9898
}
9999
return returnVal;
100100
}

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"azure-pipelines-task-lib": "^2.8.0",
3434
"js2xmlparser": "^4.0.0",
3535
"nodemailer": "^6.3.0",
36+
"performance-now": "^2.1.0",
3637
"reflect-metadata": "^0.1.13",
3738
"stats-lite": "^2.0.0",
3839
"ts-mockito": "^2.3.1",

0 commit comments

Comments
 (0)