From aa619260fc350dff0ac87301d07db8a61be856d5 Mon Sep 17 00:00:00 2001 From: Hassan Sufi Date: Mon, 11 Dec 2023 16:47:21 -0800 Subject: [PATCH] Track js compilation time (#9794) --- pxtrunner/runner.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pxtrunner/runner.ts b/pxtrunner/runner.ts index d9f56c031e15..273c711cd109 100644 --- a/pxtrunner/runner.ts +++ b/pxtrunner/runner.ts @@ -213,6 +213,7 @@ namespace pxt.runner { function initInnerAsync() { pxt.setAppTarget((window as any).pxtTargetBundle) + pxt.analytics.enable(pxt.Util.userLanguage()); Util.assert(!!pxt.appTarget); const href = window.location.href; @@ -468,7 +469,13 @@ namespace pxt.runner { export async function fetchSimJsInfo(simOptions: SimulateOptions): Promise { try { - return await pxt.Cloud.downloadBuiltSimJsInfoAsync(simOptions.id); + const start = Date.now(); + const result = await pxt.Cloud.downloadBuiltSimJsInfoAsync(simOptions.id); + pxt.tickEvent("perfMeasurement", { + durationMs: Date.now() - start, + operation: "fetchSimJsInfo", + }); + return result; } catch (e) { // This exception will happen in the majority of cases, so we don't want to log it unless for debugging. pxt.debug(e.toString()); @@ -477,6 +484,7 @@ namespace pxt.runner { } export async function buildSimJsInfo(simOptions: SimulateOptions): Promise { + const start = Date.now(); await loadPackageAsync(simOptions.id, simOptions.code, simOptions.dependencies); let didUpgrade = false; @@ -539,6 +547,10 @@ namespace pxt.runner { const res = pxtc.buildSimJsInfo(compileResult); res.parts = compileResult.usedParts; + pxt.tickEvent("perfMeasurement", { + durationMs: Date.now() - start, + operation: "buildSimJsInfo", + }); return res; }