2013-03-28 15:13:24 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
const { Cu } = require("chrome");
|
|
|
|
module.exports = [];
|
2013-03-28 15:13:24 -07:00
|
|
|
|
2013-05-09 07:15:22 -07:00
|
|
|
Cu.import("resource://gre/modules/devtools/gcli.jsm");
|
2013-03-28 15:13:24 -07:00
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
loader.lazyGetter(this, "gDevTools",
|
|
|
|
() => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools);
|
2013-03-28 15:13:24 -07:00
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
var promise = require("sdk/core/promise");
|
2013-03-28 15:13:24 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler' command. Doesn't do anything.
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler",
|
|
|
|
description: gcli.lookup("profilerDesc"),
|
|
|
|
manual: gcli.lookup("profilerManual")
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler open' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler open",
|
|
|
|
description: gcli.lookup("profilerOpenDesc"),
|
|
|
|
params: [],
|
|
|
|
|
|
|
|
exec: function (args, context) {
|
|
|
|
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
|
|
|
|
.then(function () null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler close' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler close",
|
|
|
|
description: gcli.lookup("profilerCloseDesc"),
|
|
|
|
params: [],
|
|
|
|
|
|
|
|
exec: function (args, context) {
|
2013-06-19 10:07:04 -07:00
|
|
|
if (!getPanel(context, "jsprofiler"))
|
|
|
|
return;
|
|
|
|
|
2013-03-28 15:13:24 -07:00
|
|
|
return gDevTools.closeToolbox(context.environment.target)
|
|
|
|
.then(function () null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler start' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler start",
|
|
|
|
description: gcli.lookup("profilerStartDesc"),
|
|
|
|
returnType: "string",
|
2013-06-27 17:31:52 -07:00
|
|
|
params: [],
|
2013-03-28 15:13:24 -07:00
|
|
|
|
|
|
|
exec: function (args, context) {
|
|
|
|
function start() {
|
|
|
|
let panel = getPanel(context, "jsprofiler");
|
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
if (panel.recordingProfile)
|
|
|
|
throw gcli.lookup("profilerAlreadyStarted2");
|
2013-06-18 14:42:36 -07:00
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
panel.toggleRecording();
|
2013-07-11 16:27:56 -07:00
|
|
|
return gcli.lookup("profilerStarted2");
|
2013-03-28 15:13:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
|
|
|
|
.then(start);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler stop' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler stop",
|
|
|
|
description: gcli.lookup("profilerStopDesc"),
|
|
|
|
returnType: "string",
|
2013-06-27 17:31:52 -07:00
|
|
|
params: [],
|
2013-03-28 15:13:24 -07:00
|
|
|
|
|
|
|
exec: function (args, context) {
|
|
|
|
function stop() {
|
|
|
|
let panel = getPanel(context, "jsprofiler");
|
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
if (!panel.recordingProfile)
|
|
|
|
throw gcli.lookup("profilerNotStarted3");
|
2013-06-18 14:42:36 -07:00
|
|
|
|
2013-06-27 17:31:52 -07:00
|
|
|
panel.toggleRecording();
|
2013-03-28 15:13:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return gDevTools.showToolbox(context.environment.target, "jsprofiler")
|
|
|
|
.then(stop);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler list' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler list",
|
|
|
|
description: gcli.lookup("profilerListDesc"),
|
|
|
|
returnType: "dom",
|
|
|
|
params: [],
|
|
|
|
|
|
|
|
exec: function (args, context) {
|
|
|
|
let panel = getPanel(context, "jsprofiler");
|
|
|
|
|
|
|
|
if (!panel) {
|
|
|
|
throw gcli.lookup("profilerNotReady");
|
|
|
|
}
|
|
|
|
|
|
|
|
let doc = panel.document;
|
|
|
|
let div = createXHTMLElement(doc, "div");
|
|
|
|
let ol = createXHTMLElement(doc, "ol");
|
|
|
|
|
|
|
|
for ([ uid, profile] of panel.profiles) {
|
|
|
|
let li = createXHTMLElement(doc, "li");
|
|
|
|
li.textContent = profile.name;
|
|
|
|
if (profile.isStarted) {
|
|
|
|
li.textContent += " *";
|
|
|
|
}
|
|
|
|
ol.appendChild(li);
|
|
|
|
}
|
|
|
|
|
|
|
|
div.appendChild(ol);
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'profiler show' command
|
|
|
|
*/
|
|
|
|
gcli.addCommand({
|
|
|
|
name: "profiler show",
|
|
|
|
description: gcli.lookup("profilerShowDesc"),
|
|
|
|
|
|
|
|
params: [
|
|
|
|
{
|
|
|
|
name: "name",
|
2013-06-20 10:48:25 -07:00
|
|
|
type: "string",
|
|
|
|
manual: gcli.lookup("profilerShowManual")
|
2013-03-28 15:13:24 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
exec: function (args, context) {
|
|
|
|
let panel = getPanel(context, "jsprofiler");
|
|
|
|
|
|
|
|
if (!panel) {
|
|
|
|
throw gcli.lookup("profilerNotReady");
|
|
|
|
}
|
|
|
|
|
|
|
|
let profile = panel.getProfileByName(args.name);
|
|
|
|
if (!profile) {
|
|
|
|
throw gcli.lookup("profilerNotFound");
|
|
|
|
}
|
|
|
|
|
2013-06-18 14:42:36 -07:00
|
|
|
panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile);
|
2013-03-28 15:13:24 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function getPanel(context, id) {
|
|
|
|
if (context == null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
let toolbox = gDevTools.getToolbox(context.environment.target);
|
|
|
|
return toolbox == null ? undefined : toolbox.getPanel(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createXHTMLElement(document, tagname) {
|
|
|
|
return document.createElementNS("http://www.w3.org/1999/xhtml", tagname);
|
2013-07-11 00:12:20 -07:00
|
|
|
}
|