Commit edcd08b2 authored by elfogris@gmail.com's avatar elfogris@gmail.com

[ChromeDriver] Expose CPU Profiling DevTools API into chromeWebDriver

BUG=chromedriver:796

Review URL: https://codereview.chromium.org/275193003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271803 0039d316-1c4b-4281-b951-d872f2087c98
parent 196e53e8
......@@ -88,6 +88,7 @@ David Erceg <erceg.david@gmail.com>
David Futcher <david.mike.futcher@gmail.com>
Derek Halman <d.halman@gmail.com>
Devlin Cronin <rdevlin.cronin@gmail.com>
Diego Ferreiro Val <elfogris@gmail.com>
Dillon Sellars <dill.sellars@gmail.com>
Dominic Jodoin <dominic.jodoin@gmail.com>
Dominik Röttsches <dominik.rottsches@intel.com>
......
......@@ -131,3 +131,11 @@ Status StubWebView::SetFileInputFiles(
Status StubWebView::TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) {
return Status(kOk);
}
Status StubWebView::StartProfile() {
return Status(kOk);
}
Status StubWebView::EndProfile(scoped_ptr<base::Value>* profile_data) {
return Status(kOk);
}
......@@ -68,6 +68,8 @@ class StubWebView : public WebView {
const base::DictionaryValue& element,
const std::vector<base::FilePath>& files) OVERRIDE;
virtual Status TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) OVERRIDE;
virtual Status StartProfile() OVERRIDE;
virtual Status EndProfile(scoped_ptr<base::Value>* profile_data) OVERRIDE;
private:
std::string id_;
......
......@@ -154,6 +154,14 @@ class WebView {
// 1. A meta data element "snapshot" about how to parse data elements.
// 2. Data elements: "nodes", "edges", "strings".
virtual Status TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) = 0;
// Start recording Javascript CPU Profile.
virtual Status StartProfile() = 0;
// Stop recording Javascript CPU Profile and returns a graph of
// CPUProfile objects. The format for the captured profile is defined
// (by DevTools) in protocol.json.
virtual Status EndProfile(scoped_ptr<base::Value>* profile_data) = 0;
};
#endif // CHROME_TEST_CHROMEDRIVER_CHROME_WEB_VIEW_H_
......@@ -421,6 +421,67 @@ Status WebViewImpl::TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) {
return heap_snapshot_taker_->TakeSnapshot(snapshot);
}
Status WebViewImpl::InitProfileInternal() {
base::DictionaryValue params;
// TODO: Remove Debugger.enable after Chrome 36 stable is released.
Status status_debug = client_->SendCommand("Debugger.enable", params);
if (status_debug.IsError())
return status_debug;
Status status_profiler = client_->SendCommand("Profiler.enable", params);
if (status_profiler.IsError()) {
Status status_debugger = client_->SendCommand("Debugger.disable", params);
if (status_debugger.IsError())
return status_debugger;
return status_profiler;
}
return Status(kOk);
}
Status WebViewImpl::StopProfileInternal() {
base::DictionaryValue params;
Status status_debug = client_->SendCommand("Debugger.disable", params);
Status status_profiler = client_->SendCommand("Profiler.disable", params);
if (status_debug.IsError())
return status_debug;
else if (status_profiler.IsError())
return status_profiler;
return Status(kOk);
}
Status WebViewImpl::StartProfile() {
Status status_init = InitProfileInternal();
if (status_init.IsError())
return status_init;
base::DictionaryValue params;
return client_->SendCommand("Profiler.start", params);
}
Status WebViewImpl::EndProfile(scoped_ptr<base::Value>* profile_data) {
base::DictionaryValue params;
scoped_ptr<base::DictionaryValue> profile_result;
Status status = client_->SendCommandAndGetResult(
"Profiler.stop", params, &profile_result);
if (status.IsError()) {
Status disable_profile_status = StopProfileInternal();
return disable_profile_status;
}
*profile_data = profile_result.PassAs<base::Value>();
return status;
}
Status WebViewImpl::CallAsyncFunctionInternal(const std::string& frame,
const std::string& function,
const base::ListValue& args,
......
......@@ -89,6 +89,8 @@ class WebViewImpl : public WebView {
const base::DictionaryValue& element,
const std::vector<base::FilePath>& files) OVERRIDE;
virtual Status TakeHeapSnapshot(scoped_ptr<base::Value>* snapshot) OVERRIDE;
virtual Status StartProfile() OVERRIDE;
virtual Status EndProfile(scoped_ptr<base::Value>* profile_data) OVERRIDE;
private:
Status CallAsyncFunctionInternal(const std::string& frame,
......@@ -99,6 +101,10 @@ class WebViewImpl : public WebView {
scoped_ptr<base::Value>* result);
Status IsNotPendingNavigation(const std::string& frame_id,
bool* is_not_pending);
Status InitProfileInternal();
Status StopProfileInternal();
std::string id_;
const BrowserInfo* browser_info_;
scoped_ptr<DomTracker> dom_tracker_;
......
......@@ -257,6 +257,10 @@ Status ExecuteExecuteScript(
return Status(kUnknownError, "'script' must be a string");
if (script == ":takeHeapSnapshot") {
return web_view->TakeHeapSnapshot(value);
} else if (script == ":startProfile") {
return web_view->StartProfile();
} else if (script == ":endProfile") {
return web_view->EndProfile(value);
} else {
const base::ListValue* args;
if (!params.GetList("args", &args))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment