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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial