michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const gcli = require('gcli/index'); michael@0: michael@0: loader.lazyGetter(this, "gDevTools", michael@0: () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools); michael@0: michael@0: michael@0: module.exports.items = [ michael@0: { michael@0: name: "profiler", michael@0: description: gcli.lookup("profilerDesc"), michael@0: manual: gcli.lookup("profilerManual") michael@0: }, michael@0: { michael@0: name: "profiler open", michael@0: description: gcli.lookup("profilerOpenDesc"), michael@0: exec: function (args, context) { michael@0: return gDevTools.showToolbox(context.environment.target, "jsprofiler") michael@0: .then(function () null); michael@0: } michael@0: }, michael@0: { michael@0: name: "profiler close", michael@0: description: gcli.lookup("profilerCloseDesc"), michael@0: exec: function (args, context) { michael@0: let toolbox = gDevTools.getToolbox(context.environment.target); michael@0: let panel = (toolbox == null) ? null : toolbox.getPanel(id); michael@0: if (panel == null) michael@0: return; michael@0: michael@0: return gDevTools.closeToolbox(context.environment.target) michael@0: .then(function () null); michael@0: } michael@0: }, michael@0: { michael@0: name: "profiler start", michael@0: description: gcli.lookup("profilerStartDesc"), michael@0: returnType: "string", michael@0: exec: function (args, context) { michael@0: let target = context.environment.target michael@0: return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => { michael@0: let panel = toolbox.getCurrentPanel(); michael@0: michael@0: if (panel.recordingProfile) michael@0: throw gcli.lookup("profilerAlreadyStarted2"); michael@0: michael@0: panel.toggleRecording(); michael@0: return gcli.lookup("profilerStarted2"); michael@0: }); michael@0: } michael@0: }, michael@0: { michael@0: name: "profiler stop", michael@0: description: gcli.lookup("profilerStopDesc"), michael@0: returnType: "string", michael@0: exec: function (args, context) { michael@0: let target = context.environment.target michael@0: return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => { michael@0: let panel = toolbox.getCurrentPanel(); michael@0: michael@0: if (!panel.recordingProfile) michael@0: throw gcli.lookup("profilerNotStarted3"); michael@0: michael@0: panel.toggleRecording(); michael@0: return gcli.lookup("profilerStopped"); michael@0: }); michael@0: } michael@0: }, michael@0: { michael@0: name: "profiler list", michael@0: description: gcli.lookup("profilerListDesc"), michael@0: returnType: "profileList", michael@0: exec: function (args, context) { michael@0: let toolbox = gDevTools.getToolbox(context.environment.target); michael@0: let panel = (toolbox == null) ? null : toolbox.getPanel("jsprofiler"); michael@0: michael@0: if (panel == null) { michael@0: throw gcli.lookup("profilerNotReady"); michael@0: } michael@0: michael@0: let profileList = []; michael@0: for ([ uid, profile ] of panel.profiles) { michael@0: profileList.push({ name: profile.name, started: profile.isStarted }); michael@0: } michael@0: return profileList; michael@0: } michael@0: }, michael@0: { michael@0: item: "converter", michael@0: from: "profileList", michael@0: to: "view", michael@0: exec: function(profileList, context) { michael@0: return { michael@0: html: "
" + michael@0: "
    " + michael@0: "
  1. ${profile.name}
  2. " + michael@0: " ${profile.name} ${profile.started ? '*' : ''}" + michael@0: " " + michael@0: "
" + michael@0: "
", michael@0: data: { profiles: profileList.profiles }, michael@0: options: { allowEval: true } michael@0: }; michael@0: }, michael@0: }, michael@0: { michael@0: name: "profiler show", michael@0: description: gcli.lookup("profilerShowDesc"), michael@0: params: [ michael@0: { michael@0: name: "name", michael@0: type: "string", michael@0: manual: gcli.lookup("profilerShowManual") michael@0: } michael@0: ], michael@0: michael@0: exec: function (args, context) { michael@0: let toolbox = gDevTools.getToolbox(context.environment.target); michael@0: let panel = (toolbox == null) ? null : toolbox.getPanel(id); michael@0: michael@0: if (!panel) { michael@0: throw gcli.lookup("profilerNotReady"); michael@0: } michael@0: michael@0: let profile = panel.getProfileByName(args.name); michael@0: if (!profile) { michael@0: throw gcli.lookup("profilerNotFound"); michael@0: } michael@0: michael@0: panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile); michael@0: } michael@0: }];