1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Provides communication interface to remote v8 profiler.
*/
goog.provide('devtools.ProfilerAgent');
/**
* @constructor
*/
devtools.ProfilerAgent = function() {
RemoteProfilerAgent.didGetActiveProfilerModules =
goog.bind(this.didGetActiveProfilerModules_, this);
RemoteProfilerAgent.didGetLogLines =
goog.bind(this.didGetLogLines_, this);
/**
* Active profiler modules flags.
* @type {number}
*/
this.activeProfilerModules_ =
devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_NONE;
/**
* Interval for polling profiler state.
* @type {number}
*/
this.getActiveProfilerModulesInterval_ = null;
/**
* Profiler log position.
* @type {number}
*/
this.logPosition_ = 0;
/**
* Whether log contents retrieval must be forced next time.
* @type {boolean}
*/
this.forceGetLogLines_ = false;
/**
* Profiler processor instance.
* @type {devtools.profiler.Processor}
*/
this.profilerProcessor_ = new devtools.profiler.Processor();
};
/**
* A copy of enum from include/v8.h
* @enum {number}
*/
devtools.ProfilerAgent.ProfilerModules = {
PROFILER_MODULE_NONE: 0,
PROFILER_MODULE_CPU: 1,
PROFILER_MODULE_HEAP_STATS: 1 << 1,
PROFILER_MODULE_JS_CONSTRUCTORS: 1 << 2,
PROFILER_MODULE_HEAP_SNAPSHOT: 1 << 16
};
/**
* Sets up callbacks that deal with profiles processing.
*/
devtools.ProfilerAgent.prototype.setupProfilerProcessorCallbacks = function() {
// A temporary icon indicating that the profile is being processed.
var processingIcon = new WebInspector.SidebarTreeElement(
'profile-sidebar-tree-item',
WebInspector.UIString('Processing...'),
'', null, false);
var profilesSidebar = WebInspector.panels.profiles.getProfileType(
WebInspector.CPUProfileType.TypeId).treeElement;
this.profilerProcessor_.setCallbacks(
function onProfileProcessingStarted() {
// Set visually empty string. Subtitle hiding is done via styles
// manipulation which doesn't play well with dynamic append / removal.
processingIcon.subtitle = ' ';
profilesSidebar.appendChild(processingIcon);
},
function onProfileProcessingStatus(ticksCount) {
processingIcon.subtitle =
WebInspector.UIString('%d ticks processed', ticksCount);
},
function onProfileProcessingFinished(profile) {
profilesSidebar.removeChild(processingIcon);
profile.typeId = WebInspector.CPUProfileType.TypeId;
InspectorBackend.addFullProfile(profile);
WebInspector.addProfileHeader(profile);
// If no profile is currently shown, show the new one.
var profilesPanel = WebInspector.panels.profiles;
if (!profilesPanel.visibleView) {
profilesPanel.showProfile(profile);
}
}
);
};
/**
* Initializes profiling state.
*/
devtools.ProfilerAgent.prototype.initializeProfiling = function() {
this.setupProfilerProcessorCallbacks();
this.forceGetLogLines_ = true;
this.getActiveProfilerModulesInterval_ = setInterval(
function() { RemoteProfilerAgent.getActiveProfilerModules(); }, 1000);
};
/**
* Starts profiling.
* @param {number} modules List of modules to enable.
*/
devtools.ProfilerAgent.prototype.startProfiling = function(modules) {
var cmd = new devtools.DebugCommand('profile', {
'modules': modules,
'command': 'resume'});
devtools.DebuggerAgent.sendCommand_(cmd);
RemoteToolsAgent.executeVoidJavaScript();
if (modules &
devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_HEAP_SNAPSHOT) {
var pos = this.logPosition_;
// Active modules will not change, instead, a snapshot will be logged.
setTimeout(function() { RemoteProfilerAgent.getLogLines(pos); }, 500);
}
};
/**
* Stops profiling.
*/
devtools.ProfilerAgent.prototype.stopProfiling = function(modules) {
var cmd = new devtools.DebugCommand('profile', {
'modules': modules,
'command': 'pause'});
devtools.DebuggerAgent.sendCommand_(cmd);
RemoteToolsAgent.executeVoidJavaScript();
};
/**
* Handles current profiler status.
* @param {number} modules List of active (started) modules.
*/
devtools.ProfilerAgent.prototype.didGetActiveProfilerModules_ = function(
modules) {
var profModules = devtools.ProfilerAgent.ProfilerModules;
var profModuleNone = profModules.PROFILER_MODULE_NONE;
if (this.forceGetLogLines_ ||
(modules != profModuleNone &&
this.activeProfilerModules_ == profModuleNone)) {
this.forceGetLogLines_ = false;
// Start to query log data.
RemoteProfilerAgent.getLogLines(this.logPosition_);
}
this.activeProfilerModules_ = modules;
// Update buttons.
WebInspector.setRecordingProfile(modules & profModules.PROFILER_MODULE_CPU);
};
/**
* Handles a portion of a profiler log retrieved by getLogLines call.
* @param {number} pos Current position in log.
* @param {string} log A portion of profiler log.
*/
devtools.ProfilerAgent.prototype.didGetLogLines_ = function(pos, log) {
this.logPosition_ = pos;
if (log.length > 0) {
this.profilerProcessor_.processLogChunk(log);
} else if (this.activeProfilerModules_ ==
devtools.ProfilerAgent.ProfilerModules.PROFILER_MODULE_NONE) {
// No new data and profiling is stopped---suspend log reading.
return;
}
setTimeout(function() { RemoteProfilerAgent.getLogLines(pos); }, 500);
};
|