-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
510 lines (419 loc) · 12.2 KB
/
index.html
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
<html>
<head>
<meta charset="utf-8">
<style>
body {
margin: 0px;
padding: 0px;
}
#content {
margin: 8px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
width: 960px;
height: 500px;
position: relative;
}
#details {
font-size: 85%;
}
.data {
margin: 10px;
}
table {
border-spacing: 3px;
}
tr:hover > td {
background-color: #F0F0F0;
}
td {
background-color: #F5F5F5;
padding: 5px;
}
.percentCell {
text-align: right;
}
.barCell {
vertical-align: center;
padding: 0px;
background-color: #FFFFFF;
}
.barCell > svg {
width: 400px;
height: 18px;
margin: 0px;
}
#loading-overlay {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
background: #000;
opacity: 0.7;
filter: alpha(opacity=70);
z-index: 14;
}
#loading-anim {
width: 220px;
height: 19px;
position: absolute;
top: 50%;
left: 50%;
margin: -9px 0 0 -110px;
}
.hidden {
display: none;
}
.infolink
{
display: inline-block;
font-family: sans-serif;
font-weight: bold;
text-align: center;
width: 1.5ex;
height: 1.5ex;
font-size: 1.0ex;
border-radius: 1.4ex;
margin-right: 0px;
padding: 2px;
color: black;
background: white;
border: 1px solid black;
text-decoration: none;
}
.infolink:hover
{
color: white;
background: black;
border-color: white;
text-decoration: none;
}
nav {
background-color: #F5F5F5;
overflow: hidden;
margin: 0 auto;
padding: 1em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: left;
}
nav #title {
color: grey;
font-weight: bold;
margin-right: 0.3em;
}
nav a {
color: #404040;
display: inline-block;
/* Adjust padding to increase/decrease the space between links. */
padding: 0 0.2em;
font-size: 90%;
}
nav a:visited {
color: #404040;
}
</style>
</head>
<body>
<div id="loading-overlay">
<img id="loading-anim" src="loading.gif">
</div>
<nav id="navbar">
<span id="title">Usecounters</span>
<a href="https://github.com/georgf/usecounters/issues/new">Report an issue</a>
<a href="https://github.com/georgf/usecounters">Contribute</a>
<a href="http://telemetry.mozilla.org/">Telemetry portal</a>
</nav>
<div id="content">
<p id="selection">
Show <a href="https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/use-counters.html">use counters</a>
for group
<select class="groups"></select>
relative to
<select class="kind">
<option value="page">page (toplevel)</option>
<option value="document">document</option>
</select>
counts.
</p>
<p id="details">
<form>
The data comes from Firefox
<select id="select_version">...</select>
<select id="select_channel">
<option value="beta">beta</option>
<option value="nightly">nightly</option>
</select>.
It was collected from <span id="page_count">...</span> top level page loads and <span id="document_count">...</span> individual document loads.
</form>
</p>
<div class="data"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://telemetry.mozilla.org/v2/telemetry.js"></script>
<script>
// Use counters are only collected from prerelease channels.
const gValidChannels = ["beta", "nightly"];
// Map() of (channel -> version).
var gAvailableVersions = null;
// Caching already loaded data in-memory to subsequently avoid outgoing requests.
var metricsCache = new Map();
var histogramSumCache = new Map();
function getChannel() {
return $("#select_channel").val();
}
function getVersion() {
if ($("#select_version option").length == 0) {
return null;
}
return $("#select_version").val();
}
async function getMetrics() {
let cacheId = `${getChannel()}/${getVersion()}`;
if (!metricsCache.get(cacheId)) {
let filterOptions = await new Promise(r => {
return Telemetry.getFilterOptions(getChannel(), getVersion(), r);
});
metricsCache.set(cacheId, filterOptions.metric);
}
return metricsCache.get(cacheId).filter(m => m.startsWith("USE_COUNTER2_"));
}
async function getHistogramSum(metric) {
let cacheId = `${getChannel()}/${getVersion()}/${metric}`;
if (histogramSumCache.has(cacheId)) {
return histogramSumCache.get(cacheId);
}
let filters = {};
let evo = await new Promise(r => Telemetry.getEvolution(getChannel(), getVersion(), metric, filters, false, r));
let sum = 0;
if ("" in evo) {
sum = evo[""].histogram().sum;
}
histogramSumCache.set(cacheId, sum);
return sum;
}
function strippedUseCounterName(uc) {
let kind = $('.kind').val();
let group = $('.groups').val();
let regexPrefix = new RegExp('^USE_COUNTER2_' + group + '_');
let regexSuffix = new RegExp('_' + kind.toUpperCase());
return uc.replace(regexPrefix, '')
.replace(regexSuffix, '');
}
function linkForProbeDetails(id) {
const base = `https://georgf.github.io/fx-data-explorer/`;
const params = {
searchtype: "in_any",
optout: "false",
constraint: "is_in",
version: "any",
detailView: `histogram/${id}`,
channel: getChannel(),
search: id,
};
return "https://georgf.github.io/fx-data-explorer/?" +
Object.entries(params)
.map(p => p[0] + "=" + encodeURIComponent(p[1]))
.join("&");
}
function createTable(data) {
let table = document.createElement('table');
for (let d of data) {
let tr = document.createElement('tr');
// Add name.
let td = document.createElement('td');
td.appendChild(document.createTextNode(d.shortName + " "));
let link = $('<a>', {
text: "?",
title: "More about this probe",
href: linkForProbeDetails(d.metric),
"class": "infolink",
});
link.appendTo(td);
td.setAttribute('title', d.metric);
tr.appendChild(td);
// Add percentage.
td = document.createElement('td');
td.appendChild(document.createTextNode(`${d.percentage.toFixed(3)}%`));
td.className += 'percentCell';
td.setAttribute('title', `${d.count.toLocaleString()} of total loads`);
tr.appendChild(td);
// Create bar cell.
td = document.createElement('td');
td.className += 'barCell';
td.setAttribute('title', `${d.percentage.toFixed(3)}%`);
const svgNs = "http://www.w3.org/2000/svg";
let svg = document.createElementNS(svgNs, "svg");
let usedRectWidth = Math.min(400, Math.round(4 * d.percentage));
let rect = document.createElementNS(svgNs, 'rect');
rect.setAttribute('x', 0);
rect.setAttribute('y', 0);
rect.setAttribute('width', usedRectWidth);
rect.setAttribute('height', 100);
rect.setAttribute('fill', 'steelblue');
svg.appendChild(rect);
if (usedRectWidth < 400) {
let rect = document.createElementNS(svgNs, 'rect');
rect.setAttribute('x', usedRectWidth);
rect.setAttribute('y', 0);
rect.setAttribute('width', 400 - usedRectWidth);
rect.setAttribute('height', 100);
rect.setAttribute('fill', '#F0F0F0');
svg.appendChild(rect);
}
td.appendChild(svg);
tr.appendChild(td);
table.appendChild(tr);
}
return table;
}
function pct(fraction, total) {
return 100 * (fraction / total);
}
async function getTotalCount() {
let totalMetric = ($('.kind').val() == "page") ?
"TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED" :
"CONTENT_DOCUMENTS_DESTROYED";
return await getHistogramSum(totalMetric);
}
async function addTable(metrics) {
let totalCount = await getTotalCount();
let promises = [];
let sums = [];
for (let m of metrics) {
let p = getHistogramSum(m).then(sum => sums.push({
shortName: strippedUseCounterName(m),
metric: m,
percentage: pct(sum, totalCount),
count: sum,
}));
promises.push(p);
}
await Promise.all(promises);
sums.sort((a, b) => a.shortName.localeCompare(b.shortName));
let table = createTable(sums);
$('.data').append(table);
}
function makeHash() {
window.location.hash = `#kind=${encodeURIComponent($('.kind').val())}` +
`&group=${encodeURIComponent($('.groups').val())}` +
`&channel=${getChannel()}` +
`&version=${getVersion()}`;
}
async function updateMetrics() {
$('.data').empty();
let kind = $('.kind').val();
let group = $('.groups').val();
let metrics = (await getMetrics())
.filter(m => m.endsWith("_" + kind.toUpperCase()))
.filter(m => m.startsWith("USE_COUNTER2_" + group + "_"));
console.log("metrics:", metrics.join(', '));
await addTable(metrics);
}
function parseQueryString() {
let params = new Map;
for (let pair of window.location.hash.substring(1).split('&')) {
let [key, value] = pair.split('=');
params.set(key, decodeURIComponent(value));
}
return params;
}
async function updateUI(params = null) {
var last = array => array[array.length - 1];
if (params && params.has('channel')) {
let channel = params.get('channel');
if (gValidChannels.includes(channel)) {
$('#select_channel').val(channel);
}
}
// Show only versions available for this channel.
const validVersions = gAvailableVersions.get(getChannel());
console.log("validVersions", validVersions);
$("#select_version > option").each(function() {
$(this).toggle(validVersions.includes(parseInt(this.value)));
});
// Use the closest valid version if an unavailable one was selected.
let version = (getVersion() != null) ? parseInt(getVersion()) : validVersions[0];
if (params && params.has('version')) {
version = parseInt(params.get('version'));
}
if (!validVersions.includes(version)) {
version = Math.max(last(validVersions), Math.min(validVersions[0], version));
}
$("#select_version").val(version);
// Update top level metrics.
let topLevelCount = await getHistogramSum("TOP_LEVEL_CONTENT_DOCUMENTS_DESTROYED");
let docCount = await getHistogramSum("CONTENT_DOCUMENTS_DESTROYED");
$('#page_count').text(topLevelCount.toLocaleString());
$('#document_count').text(docCount.toLocaleString());
// Add individual metrics.
let metrics = await getMetrics();
let groups = [...new Set(metrics.map(m => m.split('_')[2]))];
groups = groups.sort((a, b) => a.localeCompare(b));
$('.groups').empty();
for (let g of groups) {
$('.groups').append($('<option>', {
value: g,
text: g,
}));
}
if (params && params.has('kind')) {
$('.kind').val(params.get('kind'));
}
if (params && params.has('group')) {
$('.groups').val(params.get('group'));
}
}
async function update(params = null) {
document.getElementById("loading-overlay").classList.remove("hidden");
await updateUI(params);
makeHash();
await updateMetrics();
document.getElementById("loading-overlay").classList.add("hidden");
}
function initUI() {
// Build map of sorted valid versions per channel.
let versions = Telemetry.getVersions()
.map(v => v.split("/"))
.filter(v => gValidChannels.includes(v[0]));
gAvailableVersions = new Map();
for (let channel of gValidChannels) {
let vs = versions.filter(v => v[0] == channel)
.map(v => parseInt(v[1]))
.sort()
.reverse();
gAvailableVersions.set(channel, vs);
}
// Sanitize beta version range.
if (gAvailableVersions.get("beta")[0] == gAvailableVersions.get("nightly")[0]) {
gAvailableVersions.get("beta").shift();
}
// Fill version selector.
let select = $("#select_version");
let allVersions = [... (new Set(versions.map(v => parseInt(v[1])))).values()]
.sort()
.reverse();
for (var version of allVersions) {
select.append("<option value=\""+version+"\" >"+version+"</option>");
}
// Set up event handlers.
let handler = () => update();
let selectors = [
"#select_version",
"#select_channel",
".groups",
".kind",
];
for (let selector of selectors) {
$(selector).change(handler);
$(selector).keyup(handler);
}
}
async function start() {
await new Promise(r => Telemetry.init(r));
initUI();
await update(parseQueryString())
}
start();
</script>
</body>
</html>