Created
January 13, 2021 17:48
-
-
Save jasonLaster/eeeedaaa6dd217e73d0f6a51af5cf8b8 to your computer and use it in GitHub Desktop.
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
diff --git a/metrics.js b/metrics.js | |
index e9fbfac..b49715a 100644 | |
--- a/metrics.js | |
+++ b/metrics.js | |
@@ -96,16 +96,59 @@ function computeErrorMetrics(platform) { | |
return metrics; | |
} | |
+function computeControllerRequests() { | |
+ const metricsControllerMap = {}; | |
+ | |
+ for (const { | |
+ name, | |
+ duration, | |
+ timestamp, | |
+ connectionId, | |
+ sessionId, | |
+ forTest, | |
+ } of getRequests()) { | |
+ if (forTest || isTestConnection(connectionId)) { | |
+ continue; | |
+ } | |
+ | |
+ if (!metrics.has(name)) { | |
+ let durations = []; | |
+ for (let i = 0; i < MetricAges.length; i++) { | |
+ durations.push([]); | |
+ } | |
+ | |
+ metrics.set(name, durations); | |
+ } | |
+ | |
+ if (!metricsControllerMap[name]) { | |
+ metricsControllerMap[name] = {}; | |
+ } | |
+ | |
+ const controlId = sessionId?.split("/")[0] || null; | |
+ if (!metricsControllerMap[name][controlId]) { | |
+ metricsControllerMap[name][controlId] = []; | |
+ } | |
+ | |
+ if (timestampAge(now, timestamp) < MetricAges[-1]) { | |
+ metricsControllerMap[name][controlId].push(duration); | |
+ } | |
+ } | |
+ | |
+ return metricsControllerMap; | |
+} | |
+ | |
function computeRequestMetrics(wantTest) { | |
log(`Computing ${wantTest ? "Test " : ""}Request Metrics `); | |
const now = Date.now(); | |
const metrics = new Map(); | |
+ const metricsControllerMap = {}; | |
for (const { | |
name, | |
duration, | |
timestamp, | |
connectionId, | |
+ sessionId, | |
forTest, | |
} of getRequests()) { | |
if (wantTest != !!(forTest || isTestConnection(connectionId))) { | |
@@ -119,6 +162,20 @@ function computeRequestMetrics(wantTest) { | |
metrics.set(name, durations); | |
} | |
+ | |
+ if (!metricsControllerMap[name]) { | |
+ metricsControllerMap[name] = {}; | |
+ } | |
+ | |
+ const controlId = sessionId?.split("/")[0] || null; | |
+ if (!metricsControllerMap[name][controlId]) { | |
+ metricsControllerMap[name][controlId] = []; | |
+ } | |
+ | |
+ if (timestampAge(now, timestamp) < MetricAges[-1]) { | |
+ metricsControllerMap[name][controlId].push(duration); | |
+ } | |
+ | |
const durations = metrics.get(name); | |
MetricAges.forEach((age, i) => { | |
if (timestampAge(now, timestamp) < age) { | |
@@ -271,6 +328,7 @@ async function computeMetrics(platform, shouldRecompute = true) { | |
const replayers = Object.fromEntries(getReplayers()); | |
const requests = computeRequestMetrics(false /*wantTest*/); | |
const testRequests = computeRequestMetrics(true /*wantTest*/); | |
+ const controllerRequests = computeControllerRequests(); | |
const buckets = await computeErrorBuckets(platform); | |
const groupedBuckets = groupErrorBuckets(buckets); | |
@@ -280,6 +338,7 @@ async function computeMetrics(platform, shouldRecompute = true) { | |
replayers, | |
requests, | |
testRequests, | |
+ controllerRequests, | |
buckets: groupedBuckets, | |
Descriptions, | |
RecorderCrashDescriptions, | |
@@ -293,7 +352,7 @@ module.exports = { computeMetrics }; | |
if (process.argv[1].includes("metrics.js")) { | |
(async () => { | |
await loadLogs(); | |
- const metrics = computeMetrics("macOS", true); | |
- fs.writeFileSync("./metrics.json", JSON.stringify(metrics, null, 2)); | |
+ // const metrics = computeMetrics("macOS", true); | |
+ // fs.writeFileSync("./metrics.json", JSON.stringify(metrics, null, 2)); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment