Bug 916076 - Tests for OS.File telemetry. r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2014-01-22 12:21:44 -05:00
Родитель 0775559efd
Коммит 1ffb2fdeb5
4 изменённых файлов: 156 добавлений и 88 удалений

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

@ -160,7 +160,6 @@ let test = maketest("Main", function main(test) {
yield test_iter();
yield test_exists();
yield test_debug_test();
yield test_duration();
info("Test is over");
SimpleTest.finish();
});
@ -616,90 +615,3 @@ let test_debug_test = maketest("debug_test", function debug_test(test) {
});
/**
* Test optional duration reporting that can be used for telemetry.
*/
let test_duration = maketest("duration", function duration(test) {
return Task.spawn(function() {
Services.prefs.setBoolPref("toolkit.osfile.log", true);
// Options structure passed to a OS.File copy method.
let copyOptions = {
// This field should be overridden with the actual duration
// measurement.
outExecutionDuration: null
};
let currentDir = yield OS.File.getCurrentDirectory();
let pathSource = OS.Path.join(currentDir, EXISTING_FILE);
let copyFile = pathSource + ".bak";
let testOptions = function testOptions(options, name) {
test.info("Checking outExecutionDuration for operation: " + name);
test.info(name + ": Gathered method duration time: " +
options.outExecutionDuration + "ms");
// Making sure that duration was updated.
test.ok(typeof options.outExecutionDuration === "number",
name + ": Operation duration is a number");
test.ok(options.outExecutionDuration >= 0,
name + ": Operation duration time is non-negative.");
};
// Testing duration of OS.File.copy.
yield OS.File.copy(pathSource, copyFile, copyOptions);
testOptions(copyOptions, "OS.File.copy");
yield OS.File.remove(copyFile);
// Trying an operation where options are cloned.
let pathDest = OS.Path.join(OS.Constants.Path.tmpDir,
"osfile async test read writeAtomic.tmp");
let tmpPath = pathDest + ".tmp";
let readOptions = {
outExecutionDuration: null
};
let contents = yield OS.File.read(pathSource, undefined, readOptions);
testOptions(readOptions, "OS.File.read");
// Options structure passed to a OS.File writeAtomic method.
let writeAtomicOptions = {
// This field should be first initialized with the actual
// duration measurement then progressively incremented.
outExecutionDuration: null,
tmpPath: tmpPath
};
yield OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
testOptions(writeAtomicOptions, "OS.File.writeAtomic");
yield OS.File.remove(pathDest);
test.info("Ensuring that we can use outExecutionDuration to accumulate durations");
let ARBITRARY_BASE_DURATION = 5;
copyOptions = {
// This field should now be incremented with the actual duration
// measurement.
outExecutionDuration: ARBITRARY_BASE_DURATION
};
let backupDuration = ARBITRARY_BASE_DURATION;
// Testing duration of OS.File.copy.
yield OS.File.copy(pathSource, copyFile, copyOptions);
test.ok(copyOptions.outExecutionDuration >= backupDuration, "duration has increased 1");
backupDuration = copyOptions.outExecutionDuration;
yield OS.File.remove(copyFile, copyOptions);
test.ok(copyOptions.outExecutionDuration >= backupDuration, "duration has increased 2");
// Trying an operation where options are cloned.
// Options structure passed to a OS.File writeAtomic method.
writeAtomicOptions = {
// This field should be overridden with the actual duration
// measurement.
outExecutionDuration: copyOptions.outExecutionDuration,
tmpPath: tmpPath
};
backupDuration = writeAtomicOptions.outExecutionDuration;
yield OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
test.ok(copyOptions.outExecutionDuration >= backupDuration, "duration has increased 3");
OS.File.remove(pathDest);
// Testing an operation that doesn't take arguments at all
let file = yield OS.File.open(pathSource);
yield file.stat();
yield file.close();
});
});

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

@ -0,0 +1,91 @@
let {OS} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
let {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
/**
* Test optional duration reporting that can be used for telemetry.
*/
add_task(function* duration() {
Services.prefs.setBoolPref("toolkit.osfile.log", true);
// Options structure passed to a OS.File copy method.
let copyOptions = {
// This field should be overridden with the actual duration
// measurement.
outExecutionDuration: null
};
let currentDir = yield OS.File.getCurrentDirectory();
let pathSource = OS.Path.join(currentDir, "test_duration.js");
let copyFile = pathSource + ".bak";
function testOptions(options, name) {
do_print("Checking outExecutionDuration for operation: " + name);
do_print(name + ": Gathered method duration time: " +
options.outExecutionDuration + "ms");
// Making sure that duration was updated.
do_check_eq(typeof options.outExecutionDuration, "number");
do_check_true(options.outExecutionDuration >= 0);
};
// Testing duration of OS.File.copy.
yield OS.File.copy(pathSource, copyFile, copyOptions);
testOptions(copyOptions, "OS.File.copy");
yield OS.File.remove(copyFile);
// Trying an operation where options are cloned.
let pathDest = OS.Path.join(OS.Constants.Path.tmpDir,
"osfile async test read writeAtomic.tmp");
let tmpPath = pathDest + ".tmp";
let readOptions = {
outExecutionDuration: null
};
let contents = yield OS.File.read(pathSource, undefined, readOptions);
testOptions(readOptions, "OS.File.read");
// Options structure passed to a OS.File writeAtomic method.
let writeAtomicOptions = {
// This field should be first initialized with the actual
// duration measurement then progressively incremented.
outExecutionDuration: null,
tmpPath: tmpPath
};
yield OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
testOptions(writeAtomicOptions, "OS.File.writeAtomic");
yield OS.File.remove(pathDest);
do_print("Ensuring that we can use outExecutionDuration to accumulate durations");
let ARBITRARY_BASE_DURATION = 5;
copyOptions = {
// This field should now be incremented with the actual duration
// measurement.
outExecutionDuration: ARBITRARY_BASE_DURATION
};
let backupDuration = ARBITRARY_BASE_DURATION;
// Testing duration of OS.File.copy.
yield OS.File.copy(pathSource, copyFile, copyOptions);
do_check_true(copyOptions.outExecutionDuration >= backupDuration);
backupDuration = copyOptions.outExecutionDuration;
yield OS.File.remove(copyFile, copyOptions);
do_check_true(copyOptions.outExecutionDuration >= backupDuration);
// Trying an operation where options are cloned.
// Options structure passed to a OS.File writeAtomic method.
writeAtomicOptions = {
// This field should be overridden with the actual duration
// measurement.
outExecutionDuration: copyOptions.outExecutionDuration,
tmpPath: tmpPath
};
backupDuration = writeAtomicOptions.outExecutionDuration;
yield OS.File.writeAtomic(pathDest, contents, writeAtomicOptions);
do_check_true(copyOptions.outExecutionDuration >= backupDuration);
OS.File.remove(pathDest);
// Testing an operation that doesn't take arguments at all
let file = yield OS.File.open(pathSource);
yield file.stat();
yield file.close();
});
function run_test() {
run_next_test();
}

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

@ -0,0 +1,63 @@
"use strict";
let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
let {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
// Ensure that we have a profile but that the OS.File worker is not launched
add_task(function* init() {
do_get_profile();
yield File.resetWorker();
});
function getCount(histogram) {
if (histogram == null) {
return 0;
}
let total = 0;
for (let i of histogram.counts) {
total += i;
}
return total;
}
// Ensure that launching the OS.File worker adds data to the relevant
// histograms
add_task(function* test_startup() {
let LAUNCH = "OSFILE_WORKER_LAUNCH_MS";
let READY = "OSFILE_WORKER_READY_MS";
let before = Services.telemetry.histogramSnapshots;
// Launch the OS.File worker
yield File.getCurrentDirectory();
let after = Services.telemetry.histogramSnapshots;
do_print("Ensuring that we have recorded measures for histograms");
do_check_eq(getCount(after[LAUNCH]), getCount(before[LAUNCH]) + 1);
do_check_eq(getCount(after[READY]), getCount(before[READY]) + 1);
do_print("Ensuring that launh <= ready");
do_check_true(after[LAUNCH].sum <= after[READY].sum);
});
// Ensure that calling writeAtomic adds data to the relevant histograms
add_task(function* test_writeAtomic() {
let LABEL = "OSFILE_WRITEATOMIC_JANK_MS";
let before = Services.telemetry.histogramSnapshots;
// Perform a write.
let path = Path.join(Constants.Path.profileDir, "test_osfile_telemetry.tmp");
yield File.writeAtomic(path, LABEL, { tmpPath: path + ".tmp" } );
let after = Services.telemetry.histogramSnapshots;
do_check_eq(getCount(after[LABEL]), getCount(before[LABEL]) + 1);
});
function run_test() {
run_next_test();
}

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

@ -23,4 +23,6 @@ tail =
[test_shutdown.js]
[test_unique.js]
[test_open.js]
[test_telemetry.js]
[test_duration.js]
[test_compression.js]