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.

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

mercurial