diff --git a/browser/devtools/performance/modules/logic/recording-model.js b/browser/devtools/performance/modules/logic/recording-model.js index 5fd125b388e..3d829fca2cb 100644 --- a/browser/devtools/performance/modules/logic/recording-model.js +++ b/browser/devtools/performance/modules/logic/recording-model.js @@ -371,9 +371,8 @@ RecordingModel.prototype = { case "allocations": { if (!config.withAllocations) { break; } let [{ sites, timestamps, frames, counts }] = data; - let timeOffset = this._memoryStartTime * 1000; - let timeScale = 1000; - RecordingUtils.offsetAndScaleTimestamps(timestamps, timeOffset, timeScale); + let timeOffset = this._memoryStartTime; + RecordingUtils.offsetAndScaleTimestamps(timestamps, timeOffset); pushAll(this._allocations.sites, sites); pushAll(this._allocations.timestamps, timestamps); pushAll(this._allocations.frames, frames); diff --git a/browser/devtools/performance/modules/logic/recording-utils.js b/browser/devtools/performance/modules/logic/recording-utils.js index f74007ced37..5d033e5cc2e 100644 --- a/browser/devtools/performance/modules/logic/recording-utils.js +++ b/browser/devtools/performance/modules/logic/recording-utils.js @@ -106,7 +106,9 @@ function offsetMarkerTimes(markers, timeOffset) { function offsetAndScaleTimestamps(timestamps, timeOffset, timeScale) { for (let i = 0, len = timestamps.length; i < len; i++) { timestamps[i] -= timeOffset; - timestamps[i] /= timeScale; + if (timeScale) { + timestamps[i] /= timeScale; + } } } diff --git a/browser/devtools/performance/test/browser.ini b/browser/devtools/performance/test/browser.ini index 13e157fa8f2..119e62e3aea 100644 --- a/browser/devtools/performance/test/browser.ini +++ b/browser/devtools/performance/test/browser.ini @@ -2,6 +2,7 @@ tags = devtools subsuite = devtools support-files = + doc_allocs.html doc_force_cc.html doc_force_gc.html doc_innerHTML.html diff --git a/browser/devtools/performance/test/browser_perf-details-memory-calltree-render.js b/browser/devtools/performance/test/browser_perf-details-memory-calltree-render.js index be67422352c..db486aedbb7 100644 --- a/browser/devtools/performance/test/browser_perf-details-memory-calltree-render.js +++ b/browser/devtools/performance/test/browser_perf-details-memory-calltree-render.js @@ -5,14 +5,14 @@ * Tests that the memory call tree view renders content after recording. */ function* spawnTest() { - let { panel } = yield initPerformance(SIMPLE_URL); - let { EVENTS, DetailsView, MemoryCallTreeView } = panel.panelWin; + let { panel } = yield initPerformance(ALLOCS_URL); + let { EVENTS, $$, PerformanceController, DetailsView, MemoryCallTreeView } = panel.panelWin; // Enable memory to test. Services.prefs.setBoolPref(ALLOCATIONS_PREF, true); yield startRecording(panel); - yield busyWait(100); + yield waitUntil(() => PerformanceController.getCurrentRecording().getAllocations().timestamps.length); yield stopRecording(panel); let rendered = once(MemoryCallTreeView, EVENTS.MEMORY_CALL_TREE_RENDERED); @@ -22,6 +22,8 @@ function* spawnTest() { ok(true, "MemoryCallTreeView rendered after recording is stopped."); + ok($$("#memory-calltree-view .call-tree-item").length, "there are several allocations rendered."); + yield startRecording(panel); yield busyWait(100); diff --git a/browser/devtools/performance/test/doc_allocs.html b/browser/devtools/performance/test/doc_allocs.html new file mode 100644 index 00000000000..fced65094b2 --- /dev/null +++ b/browser/devtools/performance/test/doc_allocs.html @@ -0,0 +1,25 @@ + + + + + + + Performance test page + + + + + + + diff --git a/browser/devtools/performance/test/head.js b/browser/devtools/performance/test/head.js index 3bb0dcb0a2a..f46bb96cf1f 100644 --- a/browser/devtools/performance/test/head.js +++ b/browser/devtools/performance/test/head.js @@ -24,6 +24,7 @@ const FRAME_SCRIPT_UTILS_URL = "chrome://browser/content/devtools/frame-script-u const EXAMPLE_URL = "http://example.com/browser/browser/devtools/performance/test/"; const SIMPLE_URL = EXAMPLE_URL + "doc_simple-test.html"; const MARKERS_URL = EXAMPLE_URL + "doc_markers.html"; +const ALLOCS_URL = EXAMPLE_URL + "doc_allocs.html"; const MEMORY_SAMPLE_PROB_PREF = "devtools.performance.memory.sample-probability"; const MEMORY_MAX_LOG_LEN_PREF = "devtools.performance.memory.max-log-length"; diff --git a/toolkit/devtools/shared/memory.js b/toolkit/devtools/shared/memory.js index aa6ffb33a7c..e7039a1dc77 100644 --- a/toolkit/devtools/shared/memory.js +++ b/toolkit/devtools/shared/memory.js @@ -95,7 +95,7 @@ let Memory = exports.Memory = Class({ _clearDebuggees: function() { if (this._dbg) { - if (this.dbg.memory.trackingAllocationSites) { + if (this.isRecordingAllocations()) { this.dbg.memory.drainAllocationsLog(); } this._clearFrames(); @@ -104,7 +104,7 @@ let Memory = exports.Memory = Class({ }, _clearFrames: function() { - if (this.dbg.memory.trackingAllocationSites) { + if (this.isRecordingAllocations()) { this._frameCache.clearFrames(); } }, @@ -114,7 +114,7 @@ let Memory = exports.Memory = Class({ */ _onWindowReady: function({ isTopLevel }) { if (this.state == "attached") { - if (isTopLevel && this.dbg.memory.trackingAllocationSites) { + if (isTopLevel && this.isRecordingAllocations()) { this._clearDebuggees(); this._frameCache.initFrames(); } @@ -122,6 +122,14 @@ let Memory = exports.Memory = Class({ } }, + /** + * Returns a boolean indicating whether or not allocation + * sites are being tracked. + */ + isRecordingAllocations: function () { + return this.dbg.memory.trackingAllocationSites; + }, + /** * Take a census of the heap. See js/src/doc/Debugger/Debugger.Memory.md for * more information. @@ -146,8 +154,8 @@ let Memory = exports.Memory = Class({ * resetting the timer. */ startRecordingAllocations: expectState("attached", function(options = {}) { - if (this.dbg.memory.trackingAllocationSites) { - return Date.now(); + if (this.isRecordingAllocations()) { + return this._getCurrentTime(); } this._frameCache.initFrames(); @@ -171,13 +179,16 @@ let Memory = exports.Memory = Class({ } this.dbg.memory.trackingAllocationSites = true; - return Date.now(); + return this._getCurrentTime(); }, `starting recording allocations`), /** * Stop recording allocation sites. */ stopRecordingAllocations: expectState("attached", function() { + if (!this.isRecordingAllocations()) { + return this._getCurrentTime(); + } this.dbg.memory.trackingAllocationSites = false; this._clearFrames(); @@ -186,7 +197,7 @@ let Memory = exports.Memory = Class({ this._poller = null; } - return Date.now(); + return this._getCurrentTime(); }, `stopping recording allocations`), /** @@ -380,4 +391,12 @@ let Memory = exports.Memory = Class({ events.emit(this, "allocations", this.getAllocations()); this._poller.arm(); }, + + /** + * Accesses the docshell to return the current process time. + */ + _getCurrentTime: function () { + return (this.parent.isRootActor ? this.parent.docShell : this.parent.originalDocShell).now(); + }, + });