|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const gcli = require('gcli/index'); |
|
8 |
|
9 loader.lazyGetter(this, "gDevTools", |
|
10 () => Cu.import("resource:///modules/devtools/gDevTools.jsm", {}).gDevTools); |
|
11 |
|
12 |
|
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; |
|
35 |
|
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(); |
|
48 |
|
49 if (panel.recordingProfile) |
|
50 throw gcli.lookup("profilerAlreadyStarted2"); |
|
51 |
|
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(); |
|
65 |
|
66 if (!panel.recordingProfile) |
|
67 throw gcli.lookup("profilerNotStarted3"); |
|
68 |
|
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"); |
|
81 |
|
82 if (panel == null) { |
|
83 throw gcli.lookup("profilerNotReady"); |
|
84 } |
|
85 |
|
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 ], |
|
121 |
|
122 exec: function (args, context) { |
|
123 let toolbox = gDevTools.getToolbox(context.environment.target); |
|
124 let panel = (toolbox == null) ? null : toolbox.getPanel(id); |
|
125 |
|
126 if (!panel) { |
|
127 throw gcli.lookup("profilerNotReady"); |
|
128 } |
|
129 |
|
130 let profile = panel.getProfileByName(args.name); |
|
131 if (!profile) { |
|
132 throw gcli.lookup("profilerNotFound"); |
|
133 } |
|
134 |
|
135 panel.sidebar.selectedItem = panel.sidebar.getItemByProfile(profile); |
|
136 } |
|
137 }]; |