|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /** |
|
6 * Collects telemetry data for Tabview. |
|
7 */ |
|
8 let Telemetry = { |
|
9 TOPIC_GATHER_TELEMETRY: "gather-telemetry", |
|
10 |
|
11 /** |
|
12 * Initializes the object. |
|
13 */ |
|
14 init: function Telemetry_init() { |
|
15 Services.obs.addObserver(this, this.TOPIC_GATHER_TELEMETRY, false); |
|
16 }, |
|
17 |
|
18 /** |
|
19 * Uninitializes the object. |
|
20 */ |
|
21 uninit: function Telemetry_uninit() { |
|
22 Services.obs.removeObserver(this, this.TOPIC_GATHER_TELEMETRY); |
|
23 }, |
|
24 |
|
25 /** |
|
26 * Adds telemetry values to gather usage statistics. |
|
27 */ |
|
28 _collect: function Telemetry_collect() { |
|
29 let stackedGroupsCount = 0; |
|
30 let childCounts = []; |
|
31 |
|
32 GroupItems.groupItems.forEach(function (groupItem) { |
|
33 if (!groupItem.isEmpty()) { |
|
34 childCounts.push(groupItem.getChildren().length); |
|
35 |
|
36 if (groupItem.isStacked()) |
|
37 stackedGroupsCount++; |
|
38 } |
|
39 }); |
|
40 |
|
41 function addTelemetryValue(aId, aValue) { |
|
42 Services.telemetry.getHistogramById("PANORAMA_" + aId).add(aValue); |
|
43 } |
|
44 function median(aChildCounts) { |
|
45 aChildCounts.sort(function(x, y) { return x - y; }); |
|
46 let middle = Math.floor(aChildCounts.length / 2); |
|
47 return aChildCounts[middle]; |
|
48 } |
|
49 |
|
50 addTelemetryValue("GROUPS_COUNT", GroupItems.groupItems.length); |
|
51 addTelemetryValue("STACKED_GROUPS_COUNT", stackedGroupsCount); |
|
52 addTelemetryValue("MEDIAN_TABS_IN_GROUPS_COUNT", median(childCounts)); |
|
53 }, |
|
54 |
|
55 /** |
|
56 * Observes for gather telemetry topic. |
|
57 */ |
|
58 observe: function Telemetry_observe(aSubject, aTopic, aData) { |
|
59 if (!gWindow.PrivateBrowsingUtils.isWindowPrivate(gWindow)) |
|
60 this._collect(); |
|
61 } |
|
62 } |
|
63 |