Bug 1137222 - Submit subsession-specific value for simpleMeasurements.activeTicks. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-03-24 10:48:00 +01:00
Родитель 4dcce4682a
Коммит 484fcbf3eb
2 изменённых файлов: 71 добавлений и 4 удалений

Просмотреть файл

@ -727,6 +727,7 @@ this.TelemetrySession = Object.freeze({
Impl._previousSubsessionId = null;
Impl._subsessionCounter = 0;
Impl._profileSubsessionCounter = 0;
Impl._subsessionStartActiveTicks = 0;
this.uninstall();
return this.setup();
},
@ -804,6 +805,8 @@ let Impl = {
_profileSubsessionCounter: 0,
// Date of the last session split
_subsessionStartDate: null,
// The active ticks counted when the subsession starts
_subsessionStartActiveTicks: 0,
// A task performing delayed initialization of the chrome process
_delayedInitTask: null,
// The deferred promise resolved when the initialization task completes.
@ -816,10 +819,12 @@ let Impl = {
/**
* Gets a series of simple measurements (counters). At the moment, this
* only returns startup data from nsIAppStartup.getStartupInfo().
* @param {Boolean} isSubsession True if this is a subsession, false otherwise.
* @param {Boolean} clearSubsession True if a new subsession is being started, false otherwise.
*
* @return simple measurements as a dictionary.
*/
getSimpleMeasurements: function getSimpleMeasurements(forSavedSession) {
getSimpleMeasurements: function getSimpleMeasurements(forSavedSession, isSubsession, clearSubsession) {
this._log.trace("getSimpleMeasurements");
let si = Services.startup.getStartupInfo();
@ -909,7 +914,16 @@ let Impl = {
let sr = drs.getSessionRecorder();
if (sr) {
ret.activeTicks = sr.activeTicks;
let activeTicks = sr.activeTicks;
if (isSubsession) {
activeTicks = sr.activeTicks - this._subsessionStartActiveTicks;
}
if (clearSubsession) {
this._subsessionStartActiveTicks = activeTicks;
}
ret.activeTicks = activeTicks;
}
}
@ -1340,9 +1354,13 @@ let Impl = {
this._log.trace("getSessionPayload - reason: " + reason + ", clearSubsession: " + clearSubsession);
#if defined(MOZ_WIDGET_GONK) || defined(MOZ_WIDGET_ANDROID)
clearSubsession = false;
const isSubsession = false;
#else
const isSubsession = !this._isClassicReason(reason);
#endif
let measurements = this.getSimpleMeasurements(reason == REASON_SAVED_SESSION);
let measurements =
this.getSimpleMeasurements(reason == REASON_SAVED_SESSION, isSubsession, clearSubsession);
let info = !IS_CONTENT_PROCESS ? this.getMetadata(reason) : null;
let payload = this.assemblePayloadWithMeasurements(measurements, info, reason, clearSubsession);

Просмотреть файл

@ -664,7 +664,7 @@ add_task(function* test_saveLoadPing() {
}
});
add_task(function* test_checkSubsession() {
add_task(function* test_checkSubsessionHistograms() {
if (gIsAndroid) {
// We don't support subsessions yet on Android.
return;
@ -852,6 +852,55 @@ add_task(function* test_checkSubsession() {
Assert.equal(subsession.keyedHistograms[KEYED_ID]["b"].sum, 1);
});
add_task(function* test_checkSubsessionData() {
if (gIsAndroid || !SESSION_RECORDER_EXPECTED) {
// We don't support subsessions yet on Android. Also bail out if we
// can't use the session recorder.
return;
}
// Keep track of the active ticks count if the session recorder is available.
let sessionRecorder = gDatareportingService.getSessionRecorder();
let activeTicksAtSubsessionStart = sessionRecorder.activeTicks;
let expectedActiveTicks = activeTicksAtSubsessionStart;
incrementActiveTicks = () => {
sessionRecorder.incrementActiveTicks();
++expectedActiveTicks;
}
yield TelemetrySession.reset();
// Both classic and subsession payload data should be the same on the first subsession.
incrementActiveTicks();
let classic = TelemetrySession.getPayload();
let subsession = TelemetrySession.getPayload("environment-change");
Assert.equal(classic.simpleMeasurements.activeTicks, expectedActiveTicks,
"Classic pings must count active ticks since the beginning of the session.");
Assert.equal(subsession.simpleMeasurements.activeTicks, expectedActiveTicks,
"Subsessions must count active ticks as classic pings on the first subsession.");
// Start a new subsession and check that the active ticks are correctly reported.
incrementActiveTicks();
activeTicksAtSubsessionStart = sessionRecorder.activeTicks;
classic = TelemetrySession.getPayload();
subsession = TelemetrySession.getPayload("environment-change", true);
Assert.equal(classic.simpleMeasurements.activeTicks, expectedActiveTicks,
"Classic pings must count active ticks since the beginning of the session.");
Assert.equal(subsession.simpleMeasurements.activeTicks, expectedActiveTicks,
"Pings must not loose the tick count when starting a new subsession.");
// Get a new subsession payload without clearing the subsession.
incrementActiveTicks();
classic = TelemetrySession.getPayload();
subsession = TelemetrySession.getPayload("environment-change");
Assert.equal(classic.simpleMeasurements.activeTicks, expectedActiveTicks,
"Classic pings must count active ticks since the beginning of the session.");
Assert.equal(subsession.simpleMeasurements.activeTicks,
expectedActiveTicks - activeTicksAtSubsessionStart,
"Subsessions must count active ticks since the last new subsession.");
});
add_task(function* test_dailyCollection() {
if (gIsAndroid) {
// We don't do daily collections yet on Android.