browser/devtools/profiler/commands.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const gcli = require('gcli/index');
michael@0 8
michael@0 9 loader.lazyGetter(this, "gDevTools",
michael@0 10 () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools);
michael@0 11
michael@0 12
michael@0 13 module.exports.items = [
michael@0 14 {
michael@0 15 name: "profiler",
michael@0 16 description: gcli.lookup("profilerDesc"),
michael@0 17 manual: gcli.lookup("profilerManual")
michael@0 18 },
michael@0 19 {
michael@0 20 name: "profiler open",
michael@0 21 description: gcli.lookup("profilerOpenDesc"),
michael@0 22 exec: function (args, context) {
michael@0 23 return gDevTools.showToolbox(context.environment.target, "jsprofiler")
michael@0 24 .then(function () null);
michael@0 25 }
michael@0 26 },
michael@0 27 {
michael@0 28 name: "profiler close",
michael@0 29 description: gcli.lookup("profilerCloseDesc"),
michael@0 30 exec: function (args, context) {
michael@0 31 let toolbox = gDevTools.getToolbox(context.environment.target);
michael@0 32 let panel = (toolbox == null) ? null : toolbox.getPanel(id);
michael@0 33 if (panel == null)
michael@0 34 return;
michael@0 35
michael@0 36 return gDevTools.closeToolbox(context.environment.target)
michael@0 37 .then(function () null);
michael@0 38 }
michael@0 39 },
michael@0 40 {
michael@0 41 name: "profiler start",
michael@0 42 description: gcli.lookup("profilerStartDesc"),
michael@0 43 returnType: "string",
michael@0 44 exec: function (args, context) {
michael@0 45 let target = context.environment.target
michael@0 46 return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => {
michael@0 47 let panel = toolbox.getCurrentPanel();
michael@0 48
michael@0 49 if (panel.recordingProfile)
michael@0 50 throw gcli.lookup("profilerAlreadyStarted2");
michael@0 51
michael@0 52 panel.toggleRecording();
michael@0 53 return gcli.lookup("profilerStarted2");
michael@0 54 });
michael@0 55 }
michael@0 56 },
michael@0 57 {
michael@0 58 name: "profiler stop",
michael@0 59 description: gcli.lookup("profilerStopDesc"),
michael@0 60 returnType: "string",
michael@0 61 exec: function (args, context) {
michael@0 62 let target = context.environment.target
michael@0 63 return gDevTools.showToolbox(target, "jsprofiler").then(toolbox => {
michael@0 64 let panel = toolbox.getCurrentPanel();
michael@0 65
michael@0 66 if (!panel.recordingProfile)
michael@0 67 throw gcli.lookup("profilerNotStarted3");
michael@0 68
michael@0 69 panel.toggleRecording();
michael@0 70 return gcli.lookup("profilerStopped");
michael@0 71 });
michael@0 72 }
michael@0 73 },
michael@0 74 {
michael@0 75 name: "profiler list",
michael@0 76 description: gcli.lookup("profilerListDesc"),
michael@0 77 returnType: "profileList",
michael@0 78 exec: function (args, context) {
michael@0 79 let toolbox = gDevTools.getToolbox(context.environment.target);
michael@0 80 let panel = (toolbox == null) ? null : toolbox.getPanel("jsprofiler");
michael@0 81
michael@0 82 if (panel == null) {
michael@0 83 throw gcli.lookup("profilerNotReady");
michael@0 84 }
michael@0 85
michael@0 86 let profileList = [];
michael@0 87 for ([ uid, profile ] of panel.profiles) {
michael@0 88 profileList.push({ name: profile.name, started: profile.isStarted });
michael@0 89 }
michael@0 90 return profileList;
michael@0 91 }
michael@0 92 },
michael@0 93 {
michael@0 94 item: "converter",
michael@0 95 from: "profileList",
michael@0 96 to: "view",
michael@0 97 exec: function(profileList, context) {
michael@0 98 return {
michael@0 99 html: "<div>" +
michael@0 100 " <ol>" +
michael@0 101 " <li forEach='profile of ${profiles}'>${profile.name}</li>" +
michael@0 102 " ${profile.name} ${profile.started ? '*' : ''}" +
michael@0 103 " </li>" +
michael@0 104 " </ol>" +
michael@0 105 "</div>",
michael@0 106 data: { profiles: profileList.profiles },
michael@0 107 options: { allowEval: true }
michael@0 108 };
michael@0 109 },
michael@0 110 },
michael@0 111 {
michael@0 112 name: "profiler show",
michael@0 113 description: gcli.lookup("profilerShowDesc"),
michael@0 114 params: [
michael@0 115 {
michael@0 116 name: "name",
michael@0 117 type: "string",
michael@0 118 manual: gcli.lookup("profilerShowManual")
michael@0 119 }
michael@0 120 ],
michael@0 121
michael@0 122 exec: function (args, context) {
michael@0 123 let toolbox = gDevTools.getToolbox(context.environment.target);
michael@0 124 let panel = (toolbox == null) ? null : toolbox.getPanel(id);
michael@0 125
michael@0 126 if (!panel) {
michael@0 127 throw gcli.lookup("profilerNotReady");
michael@0 128 }
michael@0 129
michael@0 130 let profile = panel.getProfileByName(args.name);
michael@0 131 if (!profile) {
michael@0 132 throw gcli.lookup("profilerNotFound");
michael@0 133 }
michael@0 134
michael@0 135 panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile);
michael@0 136 }
michael@0 137 }];

mercurial