summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharaken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-06 18:54:39 +0000
committerharaken@chromium.org <haraken@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-06 18:54:39 +0000
commitb04cefb8a431d9605b6718fe0095f1809be2782d (patch)
tree5b3c4d577edaaabe3c01283e366fce508ea49c9e
parent73a54c2addd04e68993eca40071bbef15ce8370b (diff)
downloadchromium_src-b04cefb8a431d9605b6718fe0095f1809be2782d.zip
chromium_src-b04cefb8a431d9605b6718fe0095f1809be2782d.tar.gz
chromium_src-b04cefb8a431d9605b6718fe0095f1809be2782d.tar.bz2
Sampling profiling thread should be joined in a FILE thread
BUG=271439 Review URL: https://codereview.chromium.org/105893004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243129 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/base/tracing.cc26
-rw-r--r--content/browser/tracing/tracing_controller_impl.cc116
-rw-r--r--content/browser/tracing/tracing_controller_impl.h15
3 files changed, 129 insertions, 28 deletions
diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc
index 5aa07e7..87e6aaa 100644
--- a/chrome/test/base/tracing.cc
+++ b/chrome/test/base/tracing.cc
@@ -34,7 +34,6 @@ class InProcessTraceController {
return content::TracingController::GetInstance()->EnableRecording(
category_patterns, content::TracingController::DEFAULT_OPTIONS,
content::TracingController::EnableRecordingDoneCallback());
- return true;
}
bool BeginTracingWithWatch(const std::string& category_patterns,
@@ -44,11 +43,22 @@ class InProcessTraceController {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(num_occurrences > 0);
watch_notification_count_ = num_occurrences;
- return content::TracingController::GetInstance()->SetWatchEvent(
- category_name, event_name,
- base::Bind(&InProcessTraceController::OnWatchEventMatched,
- base::Unretained(this))) &&
- BeginTracing(category_patterns);
+ if (!content::TracingController::GetInstance()->SetWatchEvent(
+ category_name, event_name,
+ base::Bind(&InProcessTraceController::OnWatchEventMatched,
+ base::Unretained(this)))) {
+ return false;
+ }
+ if (!content::TracingController::GetInstance()->EnableRecording(
+ category_patterns, content::TracingController::DEFAULT_OPTIONS,
+ base::Bind(&InProcessTraceController::OnEnableTracingComplete,
+ base::Unretained(this)))) {
+ return false;
+ }
+
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ return true;
}
bool WaitForWatchEvent(base::TimeDelta timeout) {
@@ -93,6 +103,10 @@ class InProcessTraceController {
private:
friend struct DefaultSingletonTraits<InProcessTraceController>;
+ void OnEnableTracingComplete() {
+ message_loop_runner_->Quit();
+ }
+
void OnEndTracingComplete() {
message_loop_runner_->Quit();
}
diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc
index 20b7728..cc7ffd5 100644
--- a/content/browser/tracing/tracing_controller_impl.cc
+++ b/content/browser/tracing/tracing_controller_impl.cc
@@ -150,6 +150,26 @@ bool TracingControllerImpl::GetCategories(
return true;
}
+void TracingControllerImpl::SetEnabledOnFileThread(
+ const std::string& category_filter,
+ int trace_options,
+ const base::Closure& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ TraceLog::GetInstance()->SetEnabled(
+ base::debug::CategoryFilter(category_filter),
+ static_cast<TraceLog::Options>(trace_options));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
+}
+
+void TracingControllerImpl::SetDisabledOnFileThread(
+ const base::Closure& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ TraceLog::GetInstance()->SetDisabled();
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
+}
+
bool TracingControllerImpl::EnableRecording(
const std::string& category_filter,
TracingController::Options options,
@@ -158,33 +178,47 @@ bool TracingControllerImpl::EnableRecording(
if (!can_enable_recording())
return false;
+ is_recording_ = true;
#if defined(OS_ANDROID)
if (pending_get_categories_done_callback_.is_null())
TraceLog::GetInstance()->AddClockSyncMetadataEvent();
#endif
- TraceLog::Options trace_options = (options & RECORD_CONTINUOUSLY) ?
+ int trace_options = (options & RECORD_CONTINUOUSLY) ?
TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL;
if (options & ENABLE_SAMPLING) {
- trace_options = static_cast<TraceLog::Options>(
- trace_options | TraceLog::ENABLE_SAMPLING);
+ trace_options |= TraceLog::ENABLE_SAMPLING;
}
// TODO(haraken): How to handle ENABLE_SYSTRACE?
- TraceLog::GetInstance()->SetEnabled(
- base::debug::CategoryFilter(category_filter), trace_options);
- is_recording_ = true;
+ base::Closure on_enable_recording_done_callback =
+ base::Bind(&TracingControllerImpl::OnEnableRecordingDone,
+ base::Unretained(this),
+ category_filter, trace_options, callback);
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
+ base::Unretained(this),
+ category_filter, trace_options,
+ on_enable_recording_done_callback));
+ return true;
+}
+
+void TracingControllerImpl::OnEnableRecordingDone(
+ const std::string& category_filter,
+ int trace_options,
+ const EnableRecordingDoneCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Notify all child processes.
for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
it != trace_message_filters_.end(); ++it) {
- it->get()->SendBeginTracing(category_filter, trace_options);
+ it->get()->SendBeginTracing(category_filter,
+ static_cast<TraceLog::Options>(trace_options));
}
if (!callback.is_null())
callback.Run();
- return true;
}
bool TracingControllerImpl::DisableRecording(
@@ -195,11 +229,25 @@ bool TracingControllerImpl::DisableRecording(
if (!can_disable_recording())
return false;
- pending_disable_recording_done_callback_ = callback;
-
// Disable local trace early to avoid traces during end-tracing process from
// interfering with the process.
- TraceLog::GetInstance()->SetDisabled();
+ base::Closure on_disable_recording_done_callback =
+ base::Bind(&TracingControllerImpl::OnDisableRecordingDone,
+ base::Unretained(this),
+ result_file_path, callback);
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
+ base::Unretained(this),
+ on_disable_recording_done_callback));
+ return true;
+}
+
+void TracingControllerImpl::OnDisableRecordingDone(
+ const base::FilePath& result_file_path,
+ const TracingFileResultCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ pending_disable_recording_done_callback_ = callback;
#if defined(OS_ANDROID)
if (pending_get_categories_done_callback_.is_null())
@@ -229,7 +277,6 @@ bool TracingControllerImpl::DisableRecording(
it != trace_message_filters_.end(); ++it) {
it->get()->SendEndTracing();
}
- return true;
}
bool TracingControllerImpl::EnableMonitoring(
@@ -246,24 +293,37 @@ bool TracingControllerImpl::EnableMonitoring(
TraceLog::GetInstance()->AddClockSyncMetadataEvent();
#endif
- int monitoring_tracing_options = 0;
+ int trace_options = 0;
if (options & ENABLE_SAMPLING)
- monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING;
+ trace_options |= TraceLog::MONITOR_SAMPLING;
- TraceLog::GetInstance()->SetEnabled(
- base::debug::CategoryFilter(category_filter),
- static_cast<TraceLog::Options>(monitoring_tracing_options));
+ base::Closure on_enable_monitoring_done_callback =
+ base::Bind(&TracingControllerImpl::OnEnableMonitoringDone,
+ base::Unretained(this),
+ category_filter, trace_options, callback);
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
+ base::Unretained(this),
+ category_filter, trace_options,
+ on_enable_monitoring_done_callback));
+ return true;
+}
+
+void TracingControllerImpl::OnEnableMonitoringDone(
+ const std::string& category_filter,
+ int trace_options,
+ const EnableMonitoringDoneCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Notify all child processes.
for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
it != trace_message_filters_.end(); ++it) {
it->get()->SendEnableMonitoring(category_filter,
- static_cast<TraceLog::Options>(monitoring_tracing_options));
+ static_cast<TraceLog::Options>(trace_options));
}
if (!callback.is_null())
callback.Run();
- return true;
}
bool TracingControllerImpl::DisableMonitoring(
@@ -272,9 +332,22 @@ bool TracingControllerImpl::DisableMonitoring(
if (!can_disable_monitoring())
return false;
- is_monitoring_ = false;
- TraceLog::GetInstance()->SetDisabled();
+ base::Closure on_disable_monitoring_done_callback =
+ base::Bind(&TracingControllerImpl::OnDisableMonitoringDone,
+ base::Unretained(this), callback);
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&TracingControllerImpl::SetDisabledOnFileThread,
+ base::Unretained(this),
+ on_disable_monitoring_done_callback));
+ return true;
+}
+
+void TracingControllerImpl::OnDisableMonitoringDone(
+ const DisableMonitoringDoneCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ is_monitoring_ = false;
// Notify all child processes.
for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin();
@@ -284,7 +357,6 @@ bool TracingControllerImpl::DisableMonitoring(
if (!callback.is_null())
callback.Run();
- return true;
}
void TracingControllerImpl::GetMonitoringStatus(
diff --git a/content/browser/tracing/tracing_controller_impl.h b/content/browser/tracing/tracing_controller_impl.h
index 0f23b1bc..41fa4e8 100644
--- a/content/browser/tracing/tracing_controller_impl.h
+++ b/content/browser/tracing/tracing_controller_impl.h
@@ -121,7 +121,22 @@ class TracingControllerImpl : public TracingController {
void OnWatchEventMatched();
+ void SetEnabledOnFileThread(const std::string& category_filter,
+ int options,
+ const base::Closure& callback);
+ void SetDisabledOnFileThread(const base::Closure& callback);
+ void OnEnableRecordingDone(const std::string& category_filter,
+ int trace_options,
+ const EnableRecordingDoneCallback& callback);
+ void OnDisableRecordingDone(const base::FilePath& result_file_path,
+ const TracingFileResultCallback& callback);
+ void OnEnableMonitoringDone(const std::string& category_filter,
+ int trace_options,
+ const EnableMonitoringDoneCallback& callback);
+ void OnDisableMonitoringDone(const DisableMonitoringDoneCallback& callback);
+
TraceMessageFilterSet trace_message_filters_;
+
// Pending acks for DisableRecording.
int pending_disable_recording_ack_count_;
TraceMessageFilterSet pending_disable_recording_filters_;