This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation-scratchpad.js
830 lines (712 loc) · 29.2 KB
/
validation-scratchpad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/*
* This is to be used from a Firefox scratchpad:
* - enable chrome devtools: in about:config set "devtools.chrome.enabled" to true
* - open scratchpad: Tools -> Web Developer -> Scratchpad
* - make it run as chrome: choose Environment -> Browser
* - click "Run"
*
* After scanning the local archives this should open a new tab which highlights
* potential issues in color:
* - v2/v4 comparisons
* - v4 subsession consistency
*/
(function() {
Cu.import("resource://gre/modules/TelemetryArchive.jsm");
Cu.import("resource://gre/modules/TelemetryController.jsm");
Cu.import("resource://gre/modules/TelemetryUtils.jsm");
const BUILDID_CUTOFF = 20150722000000;
const MS_IN_A_DAY = 24 * 60 * 60 * 1000;
const SHOW_EXTENDED = false;
function getMainWindow() {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
}
function showTextInNewTab(str) {
let win = getMainWindow();
let tab = win.gBrowser.addTab("data:text/plain," + encodeURIComponent(str));
win.gBrowser.selectedTab = tab;
}
function showHtmlInNewTab(str) {
let win = getMainWindow();
let tab = win.gBrowser.addTab("data:text/html," + encodeURIComponent(str));
win.gBrowser.selectedTab = tab;
}
function mapToObject(m) {
let o = {};
for (let [k,v] of m) {
o[k] = m.get(k);
}
return o;
}
function lastElement(array) {
return array[array.length - 1];
}
function v2DefaultBrowserValueToV4(defaultValue) {
switch (defaultValue) {
case 1: return true;
case 0: return false;
default: return null;
}
}
function* extractDailyV2Measurement(dailyMap, measurement, name) {
let data = yield measurement.getValues();
for (let [day,value] of [...Iterator(data.days)]) {
day = day.toISOString();
if (!dailyMap.has(day)) {
dailyMap.set(day, {});
}
dailyMap.get(day)[name] = mapToObject(value);
}
}
function* getRawV2Data() {
const reporter = Cc["@mozilla.org/datareporting/service;1"].getService().wrappedJSObject.healthReporter;
yield reporter.onInit();
const payload = yield reporter.collectAndObtainJSONPayload(true);
return payload;
}
function getV2Extract(rawV2Data) {
const now = new Date();
const payload = rawV2Data;
const dailyMap = new Map();
for (let day of Object.keys(payload.data.days)) {
const data = payload.data.days[day];
let extract = {
isDefaultBrowser: null,
searchCounts: {},
totalTime: 0,
cleanTotalTime: 0,
cleanTotalTimes: [],
abortedTotalTime: 0,
abortedTotalTimes: [],
};
let dayHasData = false;
const counts = data["org.mozilla.searches.counts"];
if (counts) {
for (let k of Object.keys(counts)) {
if (k != "_v") {
extract.searchCounts[k] = counts[k];
dayHasData = true;
}
}
}
const appinfo = data["org.mozilla.appInfo.appinfo"];
if (appinfo) {
extract.isDefaultBrowser = appinfo.isDefaultBrowser;
dayHasData = true;
}
const previous = data["org.mozilla.appSessions.previous"];
if (previous) {
const sum = (array) => array.reduce((a,b) => a+b, 0);
extract.totalTime = sum(previous.cleanTotalTime || previous.abortedTotalTime);
extract.abortedTotalTimes = (previous.abortedTotalTime || []);
extract.abortedTotalTime = sum(extract.abortedTotalTimes);
extract.cleanTotalTimes = (previous.cleanTotalTime || []);
extract.cleanTotalTime = sum(extract.cleanTotalTimes);
dayHasData = true;
}
if (dayHasData) {
dailyMap.set(day + "T00:00:00Z", extract);
}
}
const twoDig = (n) => ((n > 9) ? "" : "0") + n;
const dateStr = `${now.getUTCFullYear()}-${twoDig(now.getUTCMonth()+1)}-${twoDig(now.getUTCDate())}T00:00:00Z`;
if (!dailyMap.has(dateStr)) {
dailyMap.set(dateStr, {
searchCounts: {},
totalTime: 0,
cleanTotalTime: 0,
cleanTotalTimes: [],
abortedTotalTime: 0,
abortedTotalTimes: [],
});
}
const extract = dailyMap.get(dateStr);
const current = payload.data.last["org.mozilla.appSessions.current"];
extract.totalTime += current.totalTime;
extract.cleanTotalTime += current.totalTime;
extract.cleanTotalTimes.push(current.totalTime);
return dailyMap;
}
function accumulateV2(dailyMap, cutoffTime) {
let r = {
searchCounts: {},
totalTime: 0,
cleanTotalTime: 0,
abortedTotalTime: 0,
};
for (let [day,v] of dailyMap) {
if ((new Date(day)).getTime() < cutoffTime) {
continue;
}
for (let k of Object.keys(v.searchCounts)) {
r.searchCounts[k] = (r.searchCounts[k] || 0) + v.searchCounts[k];
}
r.totalTime += v.totalTime;
r.cleanTotalTime += v.cleanTotalTime;
r.abortedTotalTime += v.abortedTotalTime;
}
return r;
}
function extractV4DataFromPing(p, isFromOldBuild = false) {
// Build up reduced and flat ping data to work on.
const info = p.payload.info;
const simpleMeasurements = p.payload.simpleMeasurements;
let data = {
pingId: p.id,
clientId: p.clientId,
reason: info.reason,
creationDate: p.creationDate,
channel: p.application.channel,
buildId: p.application.buildId,
version: p.application.version,
sessionId: info.sessionId,
subsessionId: info.subsessionId,
previousSessionId: info.previousSessionId,
previousSubsessionId: info.previousSubsessionId,
profileSubsessionCounter: info.profileSubsessionCounter,
subsessionCounter: info.subsessionCounter,
sessionLength: info.sessionLength,
subsessionLength: info.subsessionLength,
isFromOldBuild: isFromOldBuild,
totalTime: simpleMeasurements.totalTime,
searchCounts: {},
isDefaultBrowser: p.environment.settings.isDefaultBrowser,
};
// Extract search counts.
const h = p.payload.keyedHistograms["SEARCH_COUNTS"];
for (let k of Object.keys(h)) {
data.searchCounts[k] = h[k].sum;
}
return data;
}
function* getV4Extract() {
// Retrieve a list of the archived main pings.
let pings = yield TelemetryArchive.promiseArchivedPingList();
pings = pings.filter(p => p.type == "main");
// Load and extract data from the archived pings.
let data = [];
let foundNewerBuild = false;
for (let archived of pings) {
let p;
try {
p = yield TelemetryArchive.promiseArchivedPingById(archived.id);
} catch (e) {
// data.push({id: archived.id, timestampCreated: archived.timestampCreated, fileNotFound: true, isBroken: true});
continue;
}
// Skip all leading pings from build ids that are too old.
const isFromOldBuild = (parseInt(p.application.buildId, 10) < BUILDID_CUTOFF);
if (!foundNewerBuild && isFromOldBuild) {
continue;
}
foundNewerBuild = true;
data.push(extractV4DataFromPing(p, isFromOldBuild));
}
// Push the current data on the list, otherwise we are missing
// the measurements from the last subsession on.
let current = TelemetryController.getCurrentPingData(true);
data.push(extractV4DataFromPing(current));
let previous = null;
for (let current of data) {
const finalReasons = new Set(["shutdown", "aborted-session", "gather-subsession-payload"]);
current.isFinalFragment = finalReasons.has(current.reason);
// Check for consistency issues etc.
if (previous) {
const c = current;
const p = previous;
p.isLastFragment = (p.sessionId != c.sessionId);
c.channelSwitching = (c.channel != p.channel);
c.brokenSessionChain = p.isFinalFragment && (c.previousSessionId != p.sessionId);
c.brokenSubsessionChain = (c.previousSubsessionId != p.subsessionId);
c.brokenProfileSubsessionCounter = (c.profileSubsessionCounter != (p.profileSubsessionCounter + 1));
c.brokenSubsessionCounter = (p.isFinalFragment ?
(c.subsessionCounter != 1) :
(c.subsessionCounter != (p.subsessionCounter + 1)));
c.isBroken = !c.isFromOldBuild && !p.isFromOldBuild &&
!c.channelSwitching &&
(c.brokenSessionChain ||
c.brokenSubsessionChain ||
c.brokenProfileSubsessionCounter ||
c.brokenSubsessionCounter);
}
previous = current;
}
data[data.length-1].isLastFragment = true;
return data;
}
function accumulateV4(extracts, cutoffTime) {
let r = {
searchCounts: {},
totalTime: 0,
cleanTotalTime: 0,
abortedTotalTime: 0,
subsessionLength: 0,
sessionLength: 0,
};
for (let v of extracts) {
if ((new Date(v.creationDate)).getTime() < cutoffTime) {
continue;
}
for (let k of Object.keys(v.searchCounts)) {
r.searchCounts[k] = (r.searchCounts[k] || 0) + v.searchCounts[k];
}
r.subsessionLength += v.subsessionLength;
if (v.isLastFragment) {
r.totalTime += v.totalTime;
if (v.reason == "aborted-session") {
r.abortedTotalTime += v.totalTime;
} else {
r.cleanTotalTime += v.totalTime;
}
r.sessionLength += v.sessionLength || 0;
}
}
return r;
}
function validateV2V4BrowserDefault(v2, v4, cutoffTime) {
let sawBreakage = false;
for (let [day,v2Data] of v2) {
v2Data.brokenDefaultBrowser = false;
const v2Time = (new Date(day)).getTime();
if (v2Time < cutoffTime) {
continue;
}
// Skip this entry if v2 didn't have any useful data.
if (v2Data.isDefaultBrowser == null) {
continue;
}
// Check for matching default entries in v4 from the same day +/- one day.
// v2 & v4 don't match exactly, so we want to need to look
// for matches a bit more loosely.
// Also, v2 records this daily, v4 with every ping and hence potentially multiple
// times a day. The best criteria here thus is "for each v2 entry, check that v4
// also saw that value in a certain timeframe".
v2Data.brokenDefaultBrowser = !v4.some((ping) => {
const v4Time = (new Date(ping.creationDate)).getTime();
if ((v4Time < (v2Time - MS_IN_A_DAY)) || (v4Time > (v2Time + MS_IN_A_DAY))) {
return false;
}
return (ping.isDefaultBrowser === v2DefaultBrowserValueToV4(v2Data.isDefaultBrowser));
});
sawBreakage = sawBreakage || v2Data.brokenDefaultBrowser;
}
return sawBreakage;
}
function getV2V4Matchup(v2Extract, v4Extract, cutoffTime) {
// Lets preprocess the v4 data into a session-oriented format first.
let v4Data = new Map();
const sessions = v4Extract.filter(p => p.isLastFragment);
for (let p of sessions) {
let startTimeUtc = Date.now();
if (p.reason != "gather-subsession-payload") {
// We only insert the "current" session data on todays date, everything else
// gets attributed to the session start date.
startTimeUtc = (new Date(p.creationDate)).getTime() - (p.totalTime * 1000);
}
const startDate = new Date(startTimeUtc);
const twoDig = (n) => ((n > 9) ? "" : "0") + n;
const startDayUtc = `${startDate.getUTCFullYear()}-` +
`${twoDig(startDate.getUTCMonth() + 1)}-` +
`${twoDig(startDate.getUTCDate())}` +
`T00:00:00Z`;
if (!v4Data.has(startDayUtc)) {
v4Data.set(startDayUtc, []);
}
let entry = {
startTime: startTimeUtc,
sessionId: p.sessionId,
totalTime: p.totalTime,
aborted: p.reason == "aborted-session",
searchCounts: p.searchCounts,
sessionLength: p.sessionLength,
subsessionLength: v4Extract.reduce((prev, curr) => prev + ((curr.sessionId == p.sessionId) ? curr.subsessionLength : 0), 0),
};
// This fixes undefined sessionLength entries when the profile channel-switched to a build that
// didn't have sessionLength yet (pre bug 1188416).
if (entry.sessionLength === undefined) {
entry.sessionLength = entry.subsessionLength;
}
v4Data.get(startDayUtc).push(entry);
}
// Filter out the v2 data points that have session starts.
const v2Days = [for (v of v2Extract) if (v[1].totalTime > 0) v[0]];
// Get the set of days we have either v2 or v4 sessions for.
const days = [...(new Set([...v4Data.keys(), ...v2Days])).keys()];
days.sort();
days.reverse();
// Build per-day session & match data.
const data = new Map(); // day -> details
const matchedSessionIds = new Set();
let missingInV2Count = 0;
let missingInV4Count = 0;
for (let day of days) {
if ((cutoffTime > 0) && (new Date(day).getTime() < cutoffTime)) {
continue;
}
let v2 = v2Extract.get(day);
let v4 = v4Data.get(day) || [];
let sessions = [];
// Add v2 sessions and try to match them with the v4 data.
if (v2) {
let cleanTimes = [for (t of v2.cleanTotalTimes) {time: t, aborted: false}];
let abortedTimes = [for (t of v2.abortedTotalTimes) {time: t, aborted: true}];
for (let t of [...cleanTimes, ...abortedTimes]) {
// We match up sessions via time with a delta D we'd expect for
// totalTime matches for different collection times etc.
const D = 5;
let match = v4.find((p) => (p.aborted == t.aborted) &&
(p.aborted ||
(p.totalTime >= (t.time - D)) &&
(p.totalTime <= (t.time + D))) &&
!matchedSessionIds.has(p.sessionId));
if (match) {
matchedSessionIds.add(match.sessionId);
} else {
++missingInV4Count;
}
sessions.push({
startTime: match ? match.startTime : 0,
totalTimeV2: t.time,
totalTimeV4: match ? match.totalTime : null,
aborted: t.aborted,
broken: !match,
sessionId: match ? match.sessionId : null,
sessionLength: match ? match.sessionLength : null,
subsessionLength: match ? match.subsessionLength : null,
});
}
}
// Add unmatched v4 sessions.
const unmatchedV4Sessions = v4.filter(p => !matchedSessionIds.has(p.sessionId));
missingInV2Count += unmatchedV4Sessions.length;
for (let p of unmatchedV4Sessions) {
sessions.push({
startTime: p.startTime,
totalTimeV2: null,
totalTimeV4: p.totalTime,
aborted: p.aborted,
broken: true,
sessionId: p.sessionId,
sessionLength: p.sessionLength,
subsessionLength: p.subsessionLength,
});
}
// Add the session matchups to the daily map.
data.set(day, sessions);
}
const values = [].concat(...[...data.values()]);
return {
missingInV2Count: missingInV2Count,
missingInV4Count: missingInV4Count,
sessions: data,
totalTimes: [
values.reduce((p, c) => p + (c.totalTimeV2 || 0), 0),
values.reduce((p, c) => p + (c.totalTimeV4 || 0), 0),
],
matchedTotalTimes: [
values.reduce((p, c) => p + (!c.broken ? (c.totalTimeV2 || 0) : 0), 0),
values.reduce((p, c) => p + (!c.broken ? (c.totalTimeV4 || 0) : 0), 0),
],
cleanTotalTimes: [
values.reduce((p, c) => p + (!c.aborted ? (c.totalTimeV2 || 0) : 0), 0),
values.reduce((p, c) => p + (!c.aborted ? (c.totalTimeV4 || 0) : 0), 0),
],
matchedCleanTotalTimes: [
values.reduce((p, c) => p + ((!c.aborted && !c.broken) ? (c.totalTimeV2 || 0) : 0), 0),
values.reduce((p, c) => p + ((!c.aborted && !c.broken) ? (c.totalTimeV4 || 0) : 0), 0),
],
abortedTotalTimes: [
values.reduce((p, c) => p + (c.aborted ? (c.totalTimeV2 || 0) : 0), 0),
values.reduce((p, c) => p + (c.aborted ? (c.totalTimeV4 || 0) : 0), 0),
],
matchedAbortedTotalTimes: [
values.reduce((p, c) => p + ((c.aborted && !c.broken) ? (c.totalTimeV2 || 0) : 0), 0),
values.reduce((p, c) => p + ((c.aborted && !c.broken) ? (c.totalTimeV4 || 0) : 0), 0),
],
sessionLength: [
0,
values.reduce((p, c) => p + (c.sessionLength || 0), 0),
],
matchedCleanSessionLength: [
0,
values.reduce((p, c) => p + ((!c.aborted && !c.broken) ? (c.sessionLength || 0) : 0), 0),
],
subsessionLength: [
0,
values.reduce((p, c) => p + (c.subsessionLength || 0), 0),
],
matchedCleanSubsessionLength: [
0,
values.reduce((p, c) => p + ((!c.aborted && !c.broken) ? (c.subsessionLength || 0) : 0), 0),
],
};
}
function renderV4Extract(extract) {
// Fields to print in the order we want them listed.
const printFields = [
"creationDate",
"pingId", "clientId", "reason", "channel", "buildId",
"isDefaultBrowser",
"sessionLength", "subsessionLength", "totalTime",
"sessionId", "previousSessionId", "subsessionId", "previousSubsessionId",
"profileSubsessionCounter", "subsessionCounter",
"fileNotFound", "channelSwitching",
"brokenSessionChain", "brokenSubsessionChain", "brokenProfileSubsessionCounter", "brokenSubsessionCounter",
];
// Print an html table from the data.
let text = "";
text += "<table>";
text += "<tr>" + [for (f of printFields) `<th>${f}</th>`].join("") + "</tr>";
for (let d of extract) {
text += `<tr ${d.isBroken ? ' class="broken"' : ''}>`;
text += [for (f of printFields) `<td title="${f}">${d[f] != undefined ? d[f] : "-"}</td>`].join("");
text += "</tr>";
}
text += "</table>";
return text;
}
function renderV2Extract(data) {
let text = "";
text += "<table>";
text += `<tr><th>day</th><th>default</th><th>totalTime</th><th>cleanTotalTimes</th><th>abortedTotalTimes</th><th>brokenDefaultBrowser</th></tr>`;
for (let [day, value] of data) {
const broken = value.brokenDefaultBrowser;
text += `<tr ${broken ? ' class="broken"' : ''}>` +
`<td>${day}</td><td>${value.isDefaultBrowser}</td><td>${value.totalTime}</td>` +
`<td>${value.cleanTotalTime} = ${JSON.stringify(value.cleanTotalTimes)}</td>` +
`<td>${value.abortedTotalTime} = ${JSON.stringify(value.abortedTotalTimes)}</td>` +
`<td>${value.brokenDefaultBrowser}</td>` +
`</tr>`;
}
text += "</table>";
return text;
}
function renderV2V4Comparison(countsMap, v2, v4, cutoffTime, defaults) {
const delta = (a,b) => Math.abs(a - b);
const noInfinity = (number) => (number == Infinity) ? "-" : number;
let text = "";
// Some basic information.
text += "<h3>General Information</h3>";
text += "<table>";
text += `<tr><td>cutoff date for inspections</td>` +
`<td>${new Date(cutoffTime)} ${(cutoffTime == 0) ? "<i>(all v2 & v4 data is recent)</i>" : ""}</td></tr>`;
const currentBroken = (defaults.current.v2 != defaults.current.v4);
text += `<tr><td ${currentBroken ? ' class="broken"' : ''}>current browser defaults</td>` +
`<td>v2: ${defaults.current.v2}, v4: ${defaults.current.v4}</td></tr>`;
text += `<tr><td ${defaults.historicallyBroken ? ' class="broken"' : ''}>` +
`History of browser defaults broken</td><td>${defaults.historicallyBroken}` +
`</td></tr>`;
text += "</table>";
// Build comparison table.
text += "<h3>Search Counts</h3>";
text += "<div>Search counts should usually line up 1:1 on fresh profiles. " +
"However, on older profiles we can't exactly match when FHR & v4 measurements happened, " +
"so minor discrepancies are expected there (up to a day of measurements).</div>";
text += "<table>";
text += "<tr><th>what</th><th>v2</th><th>v4</th><th>v4 in % of v2</tr>";
for (let [k, v] of countsMap) {
const prop = v[1] / v[0];
const broken = (delta(prop, 1.0) > 0.01);
text += `<tr ${broken ? ' class="broken"' : ''}><td>${k}</td>`;
text += `<td>${v[0]}</td><td>${v[1]}</td>`;
text += `<td>${noInfinity(Math.round(prop * 1000) / 10)}%`;
text += "</tr>";
}
text += "</table>";
return text;
}
function renderV2V4Matchup(matchup) {
const delta = (a,b) => Math.abs(a - b);
const noInfinity = (number) => (number == Infinity) ? "-" : number;
let text = "<h3>Session Time Matchups</h3>";
text += "<div>The following table shows comparisons between times measured in FHR and Telemetry (all values in seconds):" +
"<ul>" +
"<li>matchedCleanTotalTimes - The sessions without crashes we can match from both systems. They should be very close to each other</li>" +
"<li>matchedAbortedTotalTimes - The crashed sessions we can match from both systems. The way FHR stores session times for detection seems to make it undercount them heavily, so Telemetry is expected to have a much higher value.</li>" +
"<li>matchedTotalTimes - The total time for sessions matched from both systems. This is expected to mismatch if there were any crashes, due to the aborted session time discrepancies.</li>" +
"<li>totalTimes - The total time for sessions in either system. This can mismatch due to the above caveats as well as sessions that are missing from either system.</li>" +
"<li>cleanTotalTimes - Same as above, except only for sessions without crashes.</li>" +
"<li>abortedTotalTimes - Same as above, except only for sessions with crashes.</li>" +
"</ul>" +
"</div>";
text += "<table>" +
`<tr><th>what</th><th>v2</th><th>v4</th><th>v4 in % of v2</th></tr>`;
let fields = [
["matchedCleanTotalTimes", "matchedCleanTotalTimes", 0.01],
["matchedAbortedTotalTimes", "matchedAbortedTotalTimes", 5.0],
["matchedTotalTimes", "matchedTotalTimes", 1.0],
["totalTimes", "totalTimes", 1.0],
["cleanTotalTimes", "cleanTotalTimes", 1.0],
["abortedTotalTimes", "abortedTotalTimes", 5.0],
];
if (SHOW_EXTENDED) {
fields = fields.concat([
["matchedTotalTimes", "matchedCleanSessionLength", 5.0],
["matchedTotalTimes", "matchedCleanSubsessionLength", 5.0],
["totalTimes", "sessionLength", 5.0],
["totalTimes", "subsessionLength", 5.0],
]);
}
for (let [fieldV2, fieldV4, tolerance] of fields) {
const valV2 = matchup[fieldV2][0];
const valV4 = matchup[fieldV4][1];
const prop = valV4 / valV2;
const broken = (delta(prop, 1.0) > tolerance);
text += `<tr ${broken ? ' class="broken"' : ''}>` +
`<td>${fieldV2}${(fieldV2 != fieldV4) ? ' vs. ' + fieldV4 : ''}</td>` +
`<td>${valV2}</td>` +
`<td>${valV4}</td>` +
`<td>${noInfinity(Math.round(prop * 1000) / 10)}%` +
`</tr>`;
}
text += "</table>";
text += "<h3>Individual Session Matchup</h3>";
text += "<div>Depending on bugs in either system, we might have sessions missing in Telemetry that are recorded " +
"in FHR or vice versa.</div>";
text += "<table>" +
`<tr><td>v2 sessions not matched in v4</td><td>${matchup.missingInV4Count}</td></tr>` +
`<tr><td>v4 sessions not matched in v2</td><td>${matchup.missingInV2Count}</td></tr>` +
"</table>";
text += "<div>The following table tries to match up individual sessions recorded in FHR " +
"and those in Telemetry with each other.<br>" +
"Entries that are missing in either are highlighted.</div>";
text += "<table>";
text += "<tr><th>day/field</th><th>v2 totalTime</th><th>v4 totalTime</th><th>aborted</th><th>v4 session id</th>";
if (SHOW_EXTENDED) {
text += "<th>sessionLength</th><th>subsessionLength</th>";
}
text += "</tr>";
for (let [day, values] of matchup.sessions) {
text += `<tr class='grey'><td>${day}</td><td></td><td></td><td></td><td></td>` +
(SHOW_EXTENDED ? "<td></td><td></td>" : "") + "</tr>";
for (let v of values) {
text += `<tr ${v.broken ? 'class="broken"' : ''}>` +
`<td>${v.startTime > 0 ? new Date(v.startTime) : 'no v4 start time'}</td>` +
`<td>${v.totalTimeV2 !== null ? v.totalTimeV2 : '-'}</td>` +
`<td>${v.totalTimeV4 !== null ? v.totalTimeV4 : '-'}</td>` +
`<td>${v.aborted}</td>` +
`<td>${v.sessionId || '-'}</td>` +
(SHOW_EXTENDED ? `<td>${v.sessionLength}</td><td>${v.subsessionLength}</td>` : "") +
`</tr>`;
}
}
text += "</table>";
return text;
}
Task.spawn(function*() {
try {
let v4Extract = yield* getV4Extract();
if (v4Extract.length == 0) {
alert("No v4 data to compare yet.");
return;
}
const rawV2Data = yield* getRawV2Data();
let v2Extract = getV2Extract(rawV2Data);
if (v2Extract.size == 0) {
alert("No v2 data to compare yet.");
return;
}
// Build a v2/v4 comparison for the best matching historic data we can find.
// If all v2 & v4 data is relatively recent, we use all available local data from both.
// If the v4 data has older pings or v2s or v4s history starts more than 1 day apart,
// we slice the data off at a roughly matching point.
const haveOldV4Pings = v4Extract.some((p) => (parseInt(p.buildId, 10) < BUILDID_CUTOFF) ||
(parseInt(p.version, 10) < 42));
const oldestV2 = TelemetryUtils.truncateToDays(new Date(lastElement([...v2Extract.keys()]))).getTime();
const oldestV4 = TelemetryUtils.truncateToDays(new Date(v4Extract[0].creationDate)).getTime();
let cutoffTime = Math.max(oldestV2, oldestV4);
if (Math.abs(oldestV2 - oldestV4) <= (MS_IN_A_DAY)) {
cutoffTime = 0;
}
const v2Accumulated = accumulateV2(v2Extract, cutoffTime);
const v4Accumulated = accumulateV4(v4Extract, cutoffTime);
const searchKeys = new Set([...Object.keys(v2Accumulated.searchCounts), ...Object.keys(v4Accumulated.searchCounts)]);
const counts = new Map([for (k of searchKeys) [
"search: " + k ,
[(v2Accumulated.searchCounts[k] || 0), (v4Accumulated.searchCounts[k] || 0)]
]]);
// Extract the current default browser.
const lastV4 = lastElement(v4Extract);
const lastV2 = v2Extract.values().next().value;
let defaults = {
current: {
v4: lastV4.isDefaultBrowser,
v2: v2DefaultBrowserValueToV4(lastV2.isDefaultBrowser),
},
historicallyBroken: validateV2V4BrowserDefault(v2Extract, v4Extract, cutoffTime),
};
// v2/v4 session matchup.
const v2v4Matchup = getV2V4Matchup(v2Extract, v4Extract, cutoffTime);
// Styling.
let text = "<style type='text/css'>" +
"table { border-collapse: collapse; margin-bottom: 10px; }" +
"th, td { border: solid 1px; }" +
"tr.broken { background-color: yellow; }" +
"div { margin-bottom: 10px; }" +
".grey { background-color: #E3E3E3; }" +
"</style>";
// Background text.
const email = "<a href='mailto:gfritzsche@mozilla.com'>gfritzsche@mozilla.com</a>";
text += "<h2>Overview</h2>";
text += "<h3>Background</h3>";
text += "<div>For the <a href='https://wiki.mozilla.org/Unified_Telemetry'>Unified Telemetry</a> project, we are moving over " +
"our data collection from <i>Firefox Health Report</i> (FHR) to an improved <i>Telemetry</i> system.<br>" +
"While the feature work was finished, this migrates critical measurements and deviates conceptually from the previous approach.<br>" +
"As a result we still need to improve our confidence into the client data.<br>" +
"One of the approaches is looking at the local data of a limited set of people and understand any potential problems they are seeing." +
"</div>";
text += "<h3>Submitting Data</h3>";
text += "<div>If there are problems with your data (shown by highlighting it in yellow), we would love to see it and investigate.<br>" +
"You could submit by:<ul>" +
"<li>(preferred) copy/paste everything into a google sheet, shared moco-only or similar and sharing it with " + email + "</li>" +
"<li>copy/paste the full URL or the contents into a mail to " + email + "</li>" +
"<li>send us the generated page</li>" +
"</ul></div>";
// Show the v2 & v4 data and data comparisons.
text += "<h2>V2/V4 Matchup</h2>";
text += "<div><i>Note:</i> v2 refers to the current FHR system, v4 to the improved Telemetry system.</div>"
text += renderV2V4Comparison(counts, v2Accumulated, v4Accumulated, cutoffTime, defaults);
text += renderV2V4Matchup(v2v4Matchup);
text += "<h2>Additional details</h2>";
text += "<div>This contains more detailed data dumps that can help us understand what is going on in individual histories.</div>";
// Enable this for some additional data dumping.
if (true) {
text += "<h3>V4 Extract</h3>";
v4Extract.reverse();
text += renderV4Extract(v4Extract);
text += "<h3>V2 Extract</h3>";
text += renderV2Extract(v2Extract);
v2v4Matchup.sessions = mapToObject(v2v4Matchup.sessions);
text += "<h3>Dumps</h3>" + "<pre>" +
"Accumulated v2 data:\n" +
JSON.stringify(v2Accumulated, null, 2) +
"\n\n" +
"Accumulated v4 data:\n" +
JSON.stringify(v4Accumulated, null, 2) +
"\n\n" +
"Accumulation comparison for cutoffTime " + new Date(cutoffTime) + "\n" +
"Oldest v2 date: " + new Date(oldestV2) + "\n" +
"Oldest v4 date: " + new Date(oldestV4) + "\n" +
JSON.stringify(mapToObject(counts), null, 2) +
"\n\n" +
"Historic v2 data:\n" +
JSON.stringify(mapToObject(v2Extract), null, 2) +
"\n\n" +
"v2/v4 matchup data:\n" +
JSON.stringify(v2v4Matchup, null, 2) +
"</pre>";
text += "<h3>Raw V2 Data</h3>" +
"<pre>" + JSON.stringify(rawV2Data, null, 2) + "</pre>";
text += "<h3>Raw V4 Data</h3>" +
"<pre>" + JSON.stringify(v4Extract, null, 2) + "</pre>";
}
showHtmlInNewTab(text);
} catch (e) {
alert(e + "\n" + e.stack);
}
});
})();