mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 07:01:19 +00:00
Bug 932092 - Data format for UI telemetry collection. r=mfinkle
This commit is contained in:
parent
055bf4fa39
commit
0daecb5fe0
@ -20,6 +20,7 @@ Cu.import("resource://gre/modules/PermissionPromptHelper.jsm");
|
||||
Cu.import("resource://gre/modules/ContactService.jsm");
|
||||
Cu.import("resource://gre/modules/NotificationDB.jsm");
|
||||
Cu.import("resource://gre/modules/SpatialNavigation.jsm");
|
||||
Cu.import("resource://gre/modules/UITelemetry.jsm");
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
Cu.import("resource://gre/modules/accessibility/AccessFu.jsm");
|
||||
@ -336,6 +337,7 @@ var BrowserApp = {
|
||||
DesktopUserAgent.init();
|
||||
Distribution.init();
|
||||
Tabs.init();
|
||||
UITelemetry.init();
|
||||
#ifdef ACCESSIBILITY
|
||||
AccessFu.attach(window);
|
||||
#endif
|
||||
|
103
toolkit/components/telemetry/UITelemetry.jsm
Normal file
103
toolkit/components/telemetry/UITelemetry.jsm
Normal file
@ -0,0 +1,103 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const Cu = Components.utils;
|
||||
|
||||
this.EXPORTED_SYMBOLS = [
|
||||
"UITelemetry"
|
||||
];
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
/**
|
||||
* UITelemetry is a helper JSM used to record UI specific telemetry events.
|
||||
*/
|
||||
this.UITelemetry = {
|
||||
|
||||
measurements: [],
|
||||
|
||||
init: function init() {
|
||||
Services.obs.addObserver(this, "UITelemetry:Event", false);
|
||||
Services.obs.addObserver(this, "UITelemetry:Session", false);
|
||||
},
|
||||
|
||||
observe: function observe(aMessage, aTopic, aData) {
|
||||
switch(aTopic) {
|
||||
case "UITelemetry:Event":
|
||||
let args = JSON.parse(aData);
|
||||
this.addEvent(args.action, args.method, args.extras, args.timestamp);
|
||||
break;
|
||||
case "UITelemetry:Session":
|
||||
args = JSON.parse(aData);
|
||||
let sessionName = args.name;
|
||||
let timestamp = args.timestamp;
|
||||
if (args.state == "start") {
|
||||
this.startSession(sessionName, timestamp);
|
||||
} else if (args.state == "stop") {
|
||||
this.stopSession(sessionName, timestamp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a single event described by an action, and the calling method. Optional
|
||||
* paramaters are extras and timestamp. The timestamp will be set here if it is
|
||||
* not passed in by the caller.
|
||||
*/
|
||||
addEvent: function addEvent(aAction, aMethod, aExtras, aTimestamp) {
|
||||
let timestamp = aTimestamp || Date.now();
|
||||
let aEvent = {
|
||||
type: "event",
|
||||
action: aAction,
|
||||
method: aMethod,
|
||||
timestamp: timestamp
|
||||
};
|
||||
|
||||
if (aExtras) aEvent.extras = aExtras;
|
||||
this._logEvent(aEvent);
|
||||
},
|
||||
|
||||
activeSessions: {},
|
||||
|
||||
/**
|
||||
* Begins tracking a session by storing a timestamp for session start.
|
||||
*/
|
||||
startSession: function startSession(aName, aTimestamp) {
|
||||
let timestamp = aTimestamp || Date.now();
|
||||
if (this.activeSessions[aName]) {
|
||||
// Do not overwrite a previous event start if it already exsts.
|
||||
return;
|
||||
}
|
||||
this.activeSessions[aName] = timestamp;
|
||||
},
|
||||
|
||||
/**
|
||||
* Tracks the end of a session with a timestamp.
|
||||
*/
|
||||
stopSession: function stopSession(aName, aTimestamp) {
|
||||
let timestamp = aTimestamp || Date.now();
|
||||
let sessionStart = this.activeSessions[aName];
|
||||
|
||||
if (!sessionStart) {
|
||||
Services.console.logStringMessage("UITelemetry error: no session [" + aName + "] to stop!");
|
||||
return;
|
||||
}
|
||||
|
||||
let aEvent = {
|
||||
type: "session",
|
||||
name: aName,
|
||||
start: sessionStart,
|
||||
end: timestamp
|
||||
};
|
||||
|
||||
this._logEvent(aEvent);
|
||||
},
|
||||
|
||||
_logEvent: function sendEvent(aEvent) {
|
||||
this.measurements.push(aEvent);
|
||||
}
|
||||
};
|
@ -35,6 +35,7 @@ EXTRA_JS_MODULES += [
|
||||
'TelemetryFile.jsm',
|
||||
'TelemetryStopwatch.jsm',
|
||||
'ThirdPartyCookieProbe.jsm',
|
||||
'UITelemetry.jsm',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user