diff options
author | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 07:34:22 +0000 |
---|---|---|
committer | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 07:34:22 +0000 |
commit | ad8b63738c201266cf8d0301a8db6c7894969423 (patch) | |
tree | 617f7a142828d12174a0fd7fcfbcfd67f8de6183 /webkit/glue/devtools | |
parent | b07f2909abb3f48f25a0e96f2a41b55199023375 (diff) | |
download | chromium_src-ad8b63738c201266cf8d0301a8db6c7894969423.zip chromium_src-ad8b63738c201266cf8d0301a8db6c7894969423.tar.gz chromium_src-ad8b63738c201266cf8d0301a8db6c7894969423.tar.bz2 |
DevTools Profiler: better handling of DevTools' reset and initial load.
Rationale: as V8 can't be reset for the process, it means that profiling logs are permanent from the viewpoint of a DevTools instance. Thus, we don't need to reset Profiles panel UI as opposed to WebKit.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/119175
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools')
-rw-r--r-- | webkit/glue/devtools/debugger_agent.h | 8 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_impl.cc | 11 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_impl.h | 3 | ||||
-rw-r--r-- | webkit/glue/devtools/js/debugger_agent.js | 76 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 18 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools_host_stub.js | 13 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inject_dispatch.js | 5 | ||||
-rw-r--r-- | webkit/glue/devtools/js/profiler_processor.js | 46 |
8 files changed, 111 insertions, 69 deletions
diff --git a/webkit/glue/devtools/debugger_agent.h b/webkit/glue/devtools/debugger_agent.h index 8205491..087bf6c 100644 --- a/webkit/glue/devtools/debugger_agent.h +++ b/webkit/glue/devtools/debugger_agent.h @@ -26,8 +26,8 @@ /* Requests current profiler status. */ \ METHOD0(IsProfilingStarted) \ \ - /* Retrieves a portion of profiler log. */ \ - METHOD1(GetLogLines, int /* position */) + /* Retrieves next portion of profiler log. */ \ + METHOD0(GetNextLogLines) DEFINE_RPC_CLASS(DebuggerAgent, DEBUGGER_AGENT_STRUCT) @@ -41,8 +41,8 @@ DEFINE_RPC_CLASS(DebuggerAgent, DEBUGGER_AGENT_STRUCT) /* Response to IsProfilingStarted. */ \ METHOD1(DidIsProfilingStarted, bool /* is_started */) \ \ - /* Response to GetLogLines. */ \ - METHOD2(DidGetLogLines, std::string /* log */, int /* new_position */) + /* Response to GetNextLogLines. */ \ + METHOD1(DidGetNextLogLines, std::string /* log */) DEFINE_RPC_CLASS(DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc index d672881..dd40b002 100644 --- a/webkit/glue/devtools/debugger_agent_impl.cc +++ b/webkit/glue/devtools/debugger_agent_impl.cc @@ -43,7 +43,8 @@ DebuggerAgentImpl::DebuggerAgentImpl( WebDevToolsAgentImpl* webdevtools_agent) : web_view_impl_(web_view_impl), delegate_(delegate), - webdevtools_agent_(webdevtools_agent) { + webdevtools_agent_(webdevtools_agent), + profiler_log_position_(0) { DebuggerAgentManager::DebugAttach(this); } @@ -75,11 +76,13 @@ void DebuggerAgentImpl::IsProfilingStarted() { delegate_->DidIsProfilingStarted(!v8::V8::IsProfilerPaused()); } -void DebuggerAgentImpl::GetLogLines(int position) { +void DebuggerAgentImpl::GetNextLogLines() { static char buffer[65536]; - int read_size = v8::V8::GetLogLines(position, buffer, sizeof(buffer) - 1); + int read_size = v8::V8::GetLogLines( + profiler_log_position_, buffer, sizeof(buffer) - 1); + profiler_log_position_ += read_size; buffer[read_size] = '\0'; - delegate_->DidGetLogLines(buffer, position + read_size); + delegate_->DidGetNextLogLines(buffer); } void DebuggerAgentImpl::DebuggerOutput(const std::string& command) { diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h index c61eb29..e2d6b6c 100644 --- a/webkit/glue/devtools/debugger_agent_impl.h +++ b/webkit/glue/devtools/debugger_agent_impl.h @@ -44,7 +44,7 @@ class DebuggerAgentImpl : public DebuggerAgent { virtual void IsProfilingStarted(); - virtual void GetLogLines(int position); + virtual void GetNextLogLines(); void DebuggerOutput(const std::string& out); @@ -67,6 +67,7 @@ class DebuggerAgentImpl : public DebuggerAgent { WebViewImpl* web_view_impl_; DebuggerAgentDelegate* delegate_; WebDevToolsAgentImpl* webdevtools_agent_; + int profiler_log_position_; DISALLOW_COPY_AND_ASSIGN(DebuggerAgentImpl); }; diff --git a/webkit/glue/devtools/js/debugger_agent.js b/webkit/glue/devtools/js/debugger_agent.js index 59ce5d6..6eec36e 100644 --- a/webkit/glue/devtools/js/debugger_agent.js +++ b/webkit/glue/devtools/js/debugger_agent.js @@ -19,8 +19,8 @@ devtools.DebuggerAgent = function() { goog.bind(this.didGetContextId_, this); RemoteDebuggerAgent.DidIsProfilingStarted = goog.bind(this.didIsProfilingStarted_, this); - RemoteDebuggerAgent.DidGetLogLines = - goog.bind(this.didGetLogLines_, this); + RemoteDebuggerAgent.DidGetNextLogLines = + goog.bind(this.didGetNextLogLines_, this); /** * Id of the inspected page global context. It is used for filtering scripts. @@ -75,17 +75,10 @@ devtools.DebuggerAgent = function() { this.isProfilingStarted_ = false; /** - * The position in log file to read from. - * @type {number} - */ - this.lastProfileLogPosition_ = 0; - - /** * Profiler processor instance. * @type {devtools.profiler.Processor} */ - this.profilerProcessor_ = new devtools.profiler.Processor( - goog.bind(WebInspector.addProfile, WebInspector)); + this.profilerProcessor_ = new devtools.profiler.Processor(); }; @@ -99,6 +92,10 @@ devtools.DebuggerAgent.prototype.reset = function() { this.requestNumberToBreakpointInfo_ = {}; this.currentCallFrame_ = null; this.requestSeqToCallback_ = {}; + + // Profiler isn't reset because it contains no data that is + // specific for a particular V8 instance. All such data is + // managed by an agent on the Render's side. }; @@ -345,6 +342,36 @@ devtools.DebuggerAgent.prototype.resolveChildren = function(object, callback) { /** + * Sets up callbacks that deal with profiles processing. + */ +devtools.DebuggerAgent.prototype.setupProfilerProcessorCallbacks = function() { + // A temporary icon indicating that the profile is being processed. + var processingIcon = new WebInspector.SidebarTreeElement( + "profile-sidebar-tree-item", "Processing...", "", null, false); + var profilesSidebar = WebInspector.panels.profiles.sidebarTree; + + this.profilerProcessor_.setCallbacks( + function onProfileProcessingStarted() { + profilesSidebar.appendChild(processingIcon); + }, + function onProfileProcessingFinished(profile) { + profilesSidebar.removeChild(processingIcon); + WebInspector.addProfile(profile); + } + ); +}; + + +/** + * Initializes profiling state. + */ +devtools.DebuggerAgent.prototype.initializeProfiling = function() { + this.setupProfilerProcessorCallbacks(); + RemoteDebuggerAgent.IsProfilingStarted(); +}; + + +/** * Starts (resumes) profiling. */ devtools.DebuggerAgent.prototype.startProfiling = function() { @@ -610,24 +637,7 @@ devtools.DebuggerAgent.prototype.didIsProfilingStarted_ = function( is_started) { if (is_started && !this.isProfilingStarted_) { // Start to query log data. - RemoteDebuggerAgent.GetLogLines(this.lastProfileLogPosition_); - } else if (!is_started && this.isProfilingStarted_ && - this.profilerProcessor_.isProcessingProfile()) { - // Display a temporary icon / message indicating that the profile - // is being processed. - var processingIcon = new WebInspector.SidebarTreeElement( - "profile-sidebar-tree-item", "Processing...", "", null, false); - var profilesSidebar = WebInspector.panels.profiles.sidebarTree; - profilesSidebar.appendChild(processingIcon); - var profilerProcessor = this.profilerProcessor_; - // Set a callback for adding a profile that removes the temporary element - // and restores plain "addProfile" callback. - profilerProcessor.setNewProfileCallback(function (profile) { - profilesSidebar.removeChild(processingIcon); - WebInspector.addProfile(profile); - profilerProcessor.setNewProfileCallback( - goog.bind(WebInspector.addProfile, WebInspector)); - }); + RemoteDebuggerAgent.GetNextLogLines(); } this.isProfilingStarted_ = is_started; // Update button. @@ -640,21 +650,17 @@ devtools.DebuggerAgent.prototype.didIsProfilingStarted_ = function( /** - * Handles a portion of a profiler log retrieved by GetLogLines call. + * Handles a portion of a profiler log retrieved by GetNextLogLines call. * @param {string} log A portion of profiler log. - * @param {number} newPosition The position in log file to read from - * next time. */ -devtools.DebuggerAgent.prototype.didGetLogLines_ = function( - log, newPosition) { +devtools.DebuggerAgent.prototype.didGetNextLogLines_ = function(log) { if (log.length > 0) { this.profilerProcessor_.processLogChunk(log); - this.lastProfileLogPosition_ = newPosition; } else if (!this.isProfilingStarted_) { // No new data and profiling is stopped---suspend log reading. return; } - setTimeout(function() { RemoteDebuggerAgent.GetLogLines(newPosition); }, 500); + setTimeout(function() { RemoteDebuggerAgent.GetNextLogLines(); }, 500); }; diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 5ed05c2..a1e7bf5 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -114,7 +114,16 @@ devtools.ToolsAgent.prototype.updateFocusedNode_ = function(nodeId) { devtools.ToolsAgent.prototype.frameNavigate_ = function(url, topLevel) { if (topLevel) { this.reset(); + // Do not reset Profiles panel. + var profiles = null; + if ('profiles' in WebInspector.panels) { + profiles = WebInspector.panels['profiles']; + delete WebInspector.panels['profiles']; + } WebInspector.reset(); + if (profiles != null) { + WebInspector.panels['profiles'] = profiles; + } } }; @@ -885,6 +894,15 @@ WebInspector.Console.prototype._evalInInspectedWindow = function(expression) { })(); +(function InterceptProfilesPanelEvents() { + var oldShow = WebInspector.ProfilesPanel.prototype.show; + WebInspector.ProfilesPanel.prototype.show = function() { + devtools.tools.getDebuggerAgent().initializeProfiling(); + oldShow.call(this); + }; +})(); + + /** * @override * TODO(pfeldman): Add l10n. diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js index 4538e83..5948abe 100644 --- a/webkit/glue/devtools/js/devtools_host_stub.js +++ b/webkit/glue/devtools/js/devtools_host_stub.js @@ -12,6 +12,7 @@ */ RemoteDebuggerAgentStub = function() { this.isProfiling_ = false; + this.profileLogPos_ = 0; }; RemoteDebuggerAgentStub.prototype.DebugBreak = function() { @@ -36,16 +37,16 @@ RemoteDebuggerAgentStub.prototype.IsProfilingStarted = function() { }, 100); }; -RemoteDebuggerAgentStub.prototype.GetLogLines = function(pos) { - if (pos < RemoteDebuggerAgentStub.ProfilerLogBuffer.length) { +RemoteDebuggerAgentStub.prototype.GetNextLogLines = function() { + if (this.profileLogPos_ < RemoteDebuggerAgentStub.ProfilerLogBuffer.length) { + this.profileLogPos_ += RemoteDebuggerAgentStub.ProfilerLogBuffer.length; setTimeout(function() { - RemoteDebuggerAgent.DidGetLogLines( - RemoteDebuggerAgentStub.ProfilerLogBuffer, - pos + RemoteDebuggerAgentStub.ProfilerLogBuffer.length); + RemoteDebuggerAgent.DidGetNextLogLines( + RemoteDebuggerAgentStub.ProfilerLogBuffer); }, 100); } else { - setTimeout(function() { RemoteDebuggerAgent.DidGetLogLines('', pos); }, 100); + setTimeout(function() { RemoteDebuggerAgent.DidGetNextLogLines(''); }, 100); } }; diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js index aa402f0..c50b123 100644 --- a/webkit/glue/devtools/js/inject_dispatch.js +++ b/webkit/glue/devtools/js/inject_dispatch.js @@ -40,7 +40,10 @@ function devtools$$dispatch(functionName, node, json_args) { */ var dispatch = function(method, var_args) { // Handle all messages with non-primitieve arguments here. - if (method == 'inspectedWindowCleared') { + if (method == 'inspectedWindowCleared' || + // TODO(pfeldman): move this code from injected dispatch + // to the client dispatch. + method == 'reset') { return; } var args = Array.prototype.slice.call(arguments); diff --git a/webkit/glue/devtools/js/profiler_processor.js b/webkit/glue/devtools/js/profiler_processor.js index 9f06acb3..3c4778e 100644 --- a/webkit/glue/devtools/js/profiler_processor.js +++ b/webkit/glue/devtools/js/profiler_processor.js @@ -142,18 +142,19 @@ devtools.profiler.JsProfile.prototype.skipThisFunction = function(name) { * that receives a new processed profile. * @constructor */ -devtools.profiler.Processor = function(newProfileCallback) { +devtools.profiler.Processor = function() { /** - * Callback that adds a new profile to view. - * @type {function(devtools.profiler.ProfileView)} + * Callback that is called when a new profile is encountered in the log. + * @type {function()} */ - this.newProfileCallback_ = newProfileCallback; + this.startedProfileProcessing_ = null; /** - * Profiles array. - * @type {Array<devtools.profiler.JsProfile>} + * Callback that is called when a profile has been processed and is ready + * to be shown. + * @type {function(devtools.profiler.ProfileView)} */ - this.profiles_ = []; + this.finishedProfileProcessing_ = null; /** * The current profile. @@ -176,6 +177,20 @@ devtools.profiler.Processor = function(newProfileCallback) { /** + * Sets profile processing callbacks. + * + * @param {function()} started Started processing callback. + * @param {function(devtools.profiler.ProfileView)} finished Finished + * processing callback. + */ +devtools.profiler.Processor.prototype.setCallbacks = function( + started, finished) { + this.startedProfileProcessing_ = started; + this.finishedProfileProcessing_ = finished; +}; + + +/** * An address for the fake "(program)" entry. WebKit's visualisation * has assumptions on how the top of the call tree should look like, * and we need to add a fake entry as the topmost function. This @@ -213,15 +228,6 @@ devtools.profiler.Processor.RecordsDispatch_ = { /** - * Returns whether a profile is currently processed. - * @return {boolean} - */ -devtools.profiler.Processor.prototype.isProcessingProfile = function() { - return this.currentProfile_ != null; -}; - - -/** * Sets new profile callback. * @param {function(devtools.profiler.ProfileView)} callback Callback function. */ @@ -310,16 +316,20 @@ devtools.profiler.Processor.prototype.processProfiler_ = function( case 'resume': if (this.currentProfile_ == null) { this.currentProfile_ = new devtools.profiler.JsProfile(); - this.profiles_.push(this.currentProfile_); // see the comment for devtools.profiler.Processor.PROGRAM_ENTRY this.currentProfile_.addCode( 'Function', '(program)', devtools.profiler.Processor.PROGRAM_ENTRY, 1); + if (this.startedProfileProcessing_) { + this.startedProfileProcessing_(); + } } break; case 'pause': if (this.currentProfile_ != null) { - this.newProfileCallback_(this.createProfileForView()); + if (this.finishedProfileProcessing_) { + this.finishedProfileProcessing_(this.createProfileForView()); + } this.currentProfile_ = null; } break; |