Bug 1201543 - Move CensusTreeNode to toolkit/devtools/heapsnapshot/*. r=fitzgen

--HG--
rename : browser/devtools/memory/modules/census.js => toolkit/devtools/heapsnapshot/census-tree-node.js
rename : browser/devtools/memory/test/unit/test_census-01.js => toolkit/devtools/heapsnapshot/tests/unit/test_census-tree-node-01.js
rename : browser/devtools/memory/test/unit/test_census-02.js => toolkit/devtools/heapsnapshot/tests/unit/test_census-tree-node-02.js
rename : browser/devtools/memory/test/unit/test_census-03.js => toolkit/devtools/heapsnapshot/tests/unit/test_census-tree-node-03.js
This commit is contained in:
Jordan Santell 2015-09-04 10:04:02 -07:00
Родитель 84631939a9
Коммит 980a030265
11 изменённых файлов: 11 добавлений и 156 удалений

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

@ -5,9 +5,7 @@
EXTRA_JS_MODULES.devtools.memory += [
'modules/census-view.js',
'modules/census.js',
'panel.js',
]
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
MOCHITEST_CHROME_MANIFESTS += ['test/mochitest/chrome.ini']

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

@ -19,7 +19,7 @@ Bug 1067491 - Test taking a census over the RDP.
<script src="head.js" type="application/javascript;version=1.8"></script>
<script>
window.onload = function() {
var { CensusTreeNode } = require("devtools/memory/census");
var { CensusTreeNode } = require("devtools/toolkit/heapsnapshot/census-tree-node");
var { INDENTATION, CensusView } = require("devtools/memory/census-view");
SimpleTest.waitForExplicitFinish();
const countBreakdown = { by: "count", count: true, bytes: true };

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

@ -1,143 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
const CC = Components.Constructor;
const { require } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const { addDebuggerToGlobal } = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
const { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
const { CensusTreeNode } = require("devtools/memory/census");
const Services = require("Services");
// Always log packets when running tests. runxpcshelltests.py will throw
// the output away anyway, unless you give it the --verbose flag.
Services.prefs.setBoolPref("devtools.debugger.log", true);
const SYSTEM_PRINCIPAL = Cc["@mozilla.org/systemprincipal;1"]
.createInstance(Ci.nsIPrincipal);
function dumpn(msg) {
dump("HEAPSNAPSHOT-TEST: " + msg + "\n");
}
function addTestingFunctionsToGlobal(global) {
global.eval(
`
const testingFunctions = Components.utils.getJSTestingFunctions();
for (let k in testingFunctions) {
this[k] = testingFunctions[k];
}
`
);
if (!global.print) {
global.print = do_print;
}
if (!global.newGlobal) {
global.newGlobal = newGlobal;
}
if (!global.Debugger) {
addDebuggerToGlobal(global);
}
}
addTestingFunctionsToGlobal(this);
/**
* Create a new global, with all the JS shell testing functions. Similar to the
* newGlobal function exposed to JS shells, and useful for porting JS shell
* tests to xpcshell tests.
*/
function newGlobal() {
const global = new Cu.Sandbox(SYSTEM_PRINCIPAL, { freshZone: true });
addTestingFunctionsToGlobal(global);
return global;
}
function assertThrowsValue(f, val, msg) {
var fullmsg;
try {
f();
} catch (exc) {
if ((exc === val) === (val === val) && (val !== 0 || 1 / exc === 1 / val))
return;
fullmsg = "Assertion failed: expected exception " + val + ", got " + exc;
}
if (fullmsg === undefined)
fullmsg = "Assertion failed: expected exception " + val + ", no exception thrown";
if (msg !== undefined)
fullmsg += " - " + msg;
throw new Error(fullmsg);
}
/**
* Returns the full path of the file with the specified name in a
* platform-independent and URL-like form.
*/
function getFilePath(aName, aAllowMissing=false, aUsePlatformPathSeparator=false)
{
let file = do_get_file(aName, aAllowMissing);
let path = Services.io.newFileURI(file).spec;
let filePrePath = "file://";
if ("nsILocalFileWin" in Ci &&
file instanceof Ci.nsILocalFileWin) {
filePrePath += "/";
}
path = path.slice(filePrePath.length);
if (aUsePlatformPathSeparator && path.match(/^\w:/)) {
path = path.replace(/\//g, "\\");
}
return path;
}
/**
* Save a heap snapshot to the file with the given name in the current
* directory, read it back as a HeapSnapshot instance, and then take a census of
* the heap snapshot's serialized heap graph with the provided census options.
*
* @param {Object|undefined} censusOptions
* Options that should be passed through to the takeCensus method. See
* js/src/doc/Debugger/Debugger.Memory.md for details.
*
* @param {Debugger|null} dbg
* If a Debugger object is given, only serialize the subgraph covered by
* the Debugger's debuggees. If null, serialize the whole heap graph.
*
* @param {String} fileName
* The file name to save the heap snapshot's core dump file to, within
* the current directory.
*
* @returns Census
*/
function saveHeapSnapshotAndTakeCensus(dbg=null, censusOptions=undefined,
// Add the Math.random() so that parallel
// tests are less likely to mess with
// each other.
fileName="core-dump-" + (Math.random()) + ".tmp") {
const filePath = getFilePath(fileName, true, true);
ok(filePath, "Should get a file path to save the core dump to.");
const snapshotOptions = dbg ? { debugger: dbg } : { runtime: true };
ChromeUtils.saveHeapSnapshot(filePath, snapshotOptions);
ok(true, "Should have saved a heap snapshot to " + filePath);
const snapshot = ChromeUtils.readHeapSnapshot(filePath);
ok(snapshot, "Should have read a heap snapshot back from " + filePath);
ok(snapshot instanceof HeapSnapshot, "snapshot should be an instance of HeapSnapshot");
equal(typeof snapshot.takeCensus, "function", "snapshot should have a takeCensus method");
return snapshot.takeCensus(censusOptions);
}
function compareCensusViewData (breakdown, report, expected, assertion) {
let data = new CensusTreeNode(breakdown, report);
equal(JSON.stringify(data), JSON.stringify(expected), assertion);
}

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

@ -1,10 +0,0 @@
[DEFAULT]
tags = devtools
head = head.js
tail =
firefox-appdir = browser
skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_census-01.js]
[test_census-02.js]
[test_census-03.js]

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

@ -32,6 +32,7 @@ DEFINES['GOOGLE_PROTOBUF_NO_RTTI'] = True
FINAL_LIBRARY = 'xul'
EXTRA_JS_MODULES.devtools.heapsnapshot += [
'census-tree-node.js',
'HeapAnalysesClient.js',
'HeapAnalysesWorker.js',
]

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

@ -20,6 +20,7 @@ const DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
const HeapAnalysesClient =
require("devtools/toolkit/heapsnapshot/HeapAnalysesClient");
const Services = require("Services");
const { CensusTreeNode } = require("devtools/toolkit/heapsnapshot/census-tree-node");
// Always log packets when running tests. runxpcshelltests.py will throw
// the output away anyway, unless you give it the --verbose flag.
@ -153,3 +154,8 @@ function saveHeapSnapshotAndTakeCensus(dbg=null, censusOptions=undefined,
equal(typeof snapshot.takeCensus, "function", "snapshot should have a takeCensus method");
return snapshot.takeCensus(censusOptions);
}
function compareCensusViewData (breakdown, report, expected, assertion) {
let data = new CensusTreeNode(breakdown, report);
equal(JSON.stringify(data), JSON.stringify(expected), assertion);
}

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

@ -9,6 +9,9 @@ support-files =
heap-snapshot-worker.js
Match.jsm
[test_census-tree-node-01.js]
[test_census-tree-node-02.js]
[test_census-tree-node-03.js]
[test_HeapAnalyses_readHeapSnapshot_01.js]
[test_HeapAnalyses_takeCensus_01.js]
[test_HeapAnalyses_takeCensus_02.js]