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