toolkit/components/osfile/tests/xpcshell/test_telemetry.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 "use strict";
michael@0 2
michael@0 3 let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
michael@0 4 let {Services} = Components.utils.import("resource://gre/modules/Services.jsm", {});
michael@0 5
michael@0 6 // Ensure that we have a profile but that the OS.File worker is not launched
michael@0 7 add_task(function* init() {
michael@0 8 do_get_profile();
michael@0 9 yield File.resetWorker();
michael@0 10 });
michael@0 11
michael@0 12 function getCount(histogram) {
michael@0 13 if (histogram == null) {
michael@0 14 return 0;
michael@0 15 }
michael@0 16
michael@0 17 let total = 0;
michael@0 18 for (let i of histogram.counts) {
michael@0 19 total += i;
michael@0 20 }
michael@0 21 return total;
michael@0 22 }
michael@0 23
michael@0 24 // Ensure that launching the OS.File worker adds data to the relevant
michael@0 25 // histograms
michael@0 26 add_task(function* test_startup() {
michael@0 27 let LAUNCH = "OSFILE_WORKER_LAUNCH_MS";
michael@0 28 let READY = "OSFILE_WORKER_READY_MS";
michael@0 29
michael@0 30 let before = Services.telemetry.histogramSnapshots;
michael@0 31
michael@0 32 // Launch the OS.File worker
michael@0 33 yield File.getCurrentDirectory();
michael@0 34
michael@0 35 let after = Services.telemetry.histogramSnapshots;
michael@0 36
michael@0 37
michael@0 38 do_print("Ensuring that we have recorded measures for histograms");
michael@0 39 do_check_eq(getCount(after[LAUNCH]), getCount(before[LAUNCH]) + 1);
michael@0 40 do_check_eq(getCount(after[READY]), getCount(before[READY]) + 1);
michael@0 41
michael@0 42 do_print("Ensuring that launh <= ready");
michael@0 43 do_check_true(after[LAUNCH].sum <= after[READY].sum);
michael@0 44 });
michael@0 45
michael@0 46 // Ensure that calling writeAtomic adds data to the relevant histograms
michael@0 47 add_task(function* test_writeAtomic() {
michael@0 48 let LABEL = "OSFILE_WRITEATOMIC_JANK_MS";
michael@0 49
michael@0 50 let before = Services.telemetry.histogramSnapshots;
michael@0 51
michael@0 52 // Perform a write.
michael@0 53 let path = Path.join(Constants.Path.profileDir, "test_osfile_telemetry.tmp");
michael@0 54 yield File.writeAtomic(path, LABEL, { tmpPath: path + ".tmp" } );
michael@0 55
michael@0 56 let after = Services.telemetry.histogramSnapshots;
michael@0 57
michael@0 58 do_check_eq(getCount(after[LABEL]), getCount(before[LABEL]) + 1);
michael@0 59 });
michael@0 60
michael@0 61 function run_test() {
michael@0 62 run_next_test();
michael@0 63 }

mercurial