1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/profiler/commands.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,137 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const gcli = require('gcli/index'); 1.11 + 1.12 +loader.lazyGetter(this, "gDevTools", 1.13 + () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools); 1.14 + 1.15 + 1.16 +module.exports.items = [ 1.17 +{ 1.18 + name: "profiler", 1.19 + description: gcli.lookup("profilerDesc"), 1.20 + manual: gcli.lookup("profilerManual") 1.21 +}, 1.22 +{ 1.23 + name: "profiler open", 1.24 + description: gcli.lookup("profilerOpenDesc"), 1.25 + exec: function (args, context) { 1.26 + return gDevTools.showToolbox(context.environment.target, "jsprofiler") 1.27 + .then(function () null); 1.28 + } 1.29 +}, 1.30 +{ 1.31 + name: "profiler close", 1.32 + description: gcli.lookup("profilerCloseDesc"), 1.33 + exec: function (args, context) { 1.34 + let toolbox = gDevTools.getToolbox(context.environment.target); 1.35 + let panel = (toolbox == null) ? null : toolbox.getPanel(id); 1.36 + if (panel == null) 1.37 + return; 1.38 + 1.39 + return gDevTools.closeToolbox(context.environment.target) 1.40 + .then(function () null); 1.41 + } 1.42 +}, 1.43 +{ 1.44 + name: "profiler start", 1.45 + description: gcli.lookup("profilerStartDesc"), 1.46 + returnType: "string", 1.47 + exec: function (args, context) { 1.48 + let target = context.environment.target 1.49 + return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => { 1.50 + let panel = toolbox.getCurrentPanel(); 1.51 + 1.52 + if (panel.recordingProfile) 1.53 + throw gcli.lookup("profilerAlreadyStarted2"); 1.54 + 1.55 + panel.toggleRecording(); 1.56 + return gcli.lookup("profilerStarted2"); 1.57 + }); 1.58 + } 1.59 +}, 1.60 +{ 1.61 + name: "profiler stop", 1.62 + description: gcli.lookup("profilerStopDesc"), 1.63 + returnType: "string", 1.64 + exec: function (args, context) { 1.65 + let target = context.environment.target 1.66 + return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => { 1.67 + let panel = toolbox.getCurrentPanel(); 1.68 + 1.69 + if (!panel.recordingProfile) 1.70 + throw gcli.lookup("profilerNotStarted3"); 1.71 + 1.72 + panel.toggleRecording(); 1.73 + return gcli.lookup("profilerStopped"); 1.74 + }); 1.75 + } 1.76 +}, 1.77 +{ 1.78 + name: "profiler list", 1.79 + description: gcli.lookup("profilerListDesc"), 1.80 + returnType: "profileList", 1.81 + exec: function (args, context) { 1.82 + let toolbox = gDevTools.getToolbox(context.environment.target); 1.83 + let panel = (toolbox == null) ? null : toolbox.getPanel("jsprofiler"); 1.84 + 1.85 + if (panel == null) { 1.86 + throw gcli.lookup("profilerNotReady"); 1.87 + } 1.88 + 1.89 + let profileList = []; 1.90 + for ([ uid, profile ] of panel.profiles) { 1.91 + profileList.push({ name: profile.name, started: profile.isStarted }); 1.92 + } 1.93 + return profileList; 1.94 + } 1.95 +}, 1.96 +{ 1.97 + item: "converter", 1.98 + from: "profileList", 1.99 + to: "view", 1.100 + exec: function(profileList, context) { 1.101 + return { 1.102 + html: "<div>" + 1.103 + " <ol>" + 1.104 + " <li forEach='profile of ${profiles}'>${profile.name}</li>" + 1.105 + " ${profile.name} ${profile.started ? '*' : ''}" + 1.106 + " </li>" + 1.107 + " </ol>" + 1.108 + "</div>", 1.109 + data: { profiles: profileList.profiles }, 1.110 + options: { allowEval: true } 1.111 + }; 1.112 + }, 1.113 +}, 1.114 +{ 1.115 + name: "profiler show", 1.116 + description: gcli.lookup("profilerShowDesc"), 1.117 + params: [ 1.118 + { 1.119 + name: "name", 1.120 + type: "string", 1.121 + manual: gcli.lookup("profilerShowManual") 1.122 + } 1.123 + ], 1.124 + 1.125 + exec: function (args, context) { 1.126 + let toolbox = gDevTools.getToolbox(context.environment.target); 1.127 + let panel = (toolbox == null) ? null : toolbox.getPanel(id); 1.128 + 1.129 + if (!panel) { 1.130 + throw gcli.lookup("profilerNotReady"); 1.131 + } 1.132 + 1.133 + let profile = panel.getProfileByName(args.name); 1.134 + if (!profile) { 1.135 + throw gcli.lookup("profilerNotFound"); 1.136 + } 1.137 + 1.138 + panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile); 1.139 + } 1.140 +}];