Commit 99bc9288 authored by Oystein Eftevaag's avatar Oystein Eftevaag Committed by Commit Bot

Tracing: Migrated away from BrowserThread::FILE to TaskScheduler

Bug: 667892
Change-Id: I578c3b3386ee018b8a4ac2a097e56555a34c9f51
Reviewed-on: https://chromium-review.googlesource.com/611188Reviewed-by: default avatarSiddhartha S <ssid@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: oysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501498}
parent 2f459573
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/data_use_measurement/core/data_use_user_data.h" #include "components/data_use_measurement/core/data_use_user_data.h"
...@@ -104,6 +105,7 @@ void TraceCrashServiceUploader::OnURLFetchUploadProgress( ...@@ -104,6 +105,7 @@ void TraceCrashServiceUploader::OnURLFetchUploadProgress(
int64_t current, int64_t current,
int64_t total) { int64_t total) {
DCHECK(url_fetcher_.get()); DCHECK(url_fetcher_.get());
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
LOG(WARNING) << "Upload progress: " << current << " of " << total; LOG(WARNING) << "Upload progress: " << current << " of " << total;
...@@ -121,27 +123,24 @@ void TraceCrashServiceUploader::DoUpload( ...@@ -121,27 +123,24 @@ void TraceCrashServiceUploader::DoUpload(
const UploadProgressCallback& progress_callback, const UploadProgressCallback& progress_callback,
const UploadDoneCallback& done_callback) { const UploadDoneCallback& done_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::BrowserThread::PostTask(
content::BrowserThread::FILE, FROM_HERE, progress_callback_ = progress_callback;
base::Bind(&TraceCrashServiceUploader::DoUploadOnFileThread, done_callback_ = done_callback;
base::PostTaskWithTraits(
FROM_HERE, {base::TaskPriority::BACKGROUND},
base::Bind(&TraceCrashServiceUploader::DoCompressOnBackgroundThread,
base::Unretained(this), file_contents, upload_mode, base::Unretained(this), file_contents, upload_mode,
upload_url_, base::Passed(std::move(metadata)), upload_url_, base::Passed(std::move(metadata))));
progress_callback, done_callback));
} }
void TraceCrashServiceUploader::DoUploadOnFileThread( void TraceCrashServiceUploader::DoCompressOnBackgroundThread(
const std::string& file_contents, const std::string& file_contents,
UploadMode upload_mode, UploadMode upload_mode,
const std::string& upload_url, const std::string& upload_url,
std::unique_ptr<const base::DictionaryValue> metadata, std::unique_ptr<const base::DictionaryValue> metadata) {
const UploadProgressCallback& progress_callback,
const UploadDoneCallback& done_callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
DCHECK(!url_fetcher_.get()); DCHECK(!url_fetcher_.get());
progress_callback_ = progress_callback;
done_callback_ = done_callback;
if (upload_url.empty()) { if (upload_url.empty()) {
OnUploadError("Upload URL empty or invalid"); OnUploadError("Upload URL empty or invalid");
return; return;
......
...@@ -49,13 +49,12 @@ class TraceCrashServiceUploader : public content::TraceUploader, ...@@ -49,13 +49,12 @@ class TraceCrashServiceUploader : public content::TraceUploader,
const UploadDoneCallback& done_callback) override; const UploadDoneCallback& done_callback) override;
private: private:
void DoUploadOnFileThread( void DoCompressOnBackgroundThread(
const std::string& file_contents, const std::string& file_contents,
UploadMode upload_mode, UploadMode upload_mode,
const std::string& upload_url, const std::string& upload_url,
std::unique_ptr<const base::DictionaryValue> metadata, std::unique_ptr<const base::DictionaryValue> metadata);
const UploadProgressCallback& progress_callback,
const UploadDoneCallback& done_callback);
// Sets up a multipart body to be uploaded. The body is produced according // Sets up a multipart body to be uploaded. The body is produced according
// to RFC 2046. // to RFC 2046.
void SetupMultipart(const std::string& product, void SetupMultipart(const std::string& product,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/task_scheduler/post_task.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -134,7 +135,9 @@ TracingControllerImpl::TracingControllerImpl() ...@@ -134,7 +135,9 @@ TracingControllerImpl::TracingControllerImpl()
maximum_trace_buffer_usage_(0), maximum_trace_buffer_usage_(0),
approximate_event_count_(0), approximate_event_count_(0),
pending_clock_sync_ack_count_(0), pending_clock_sync_ack_count_(0),
enabled_tracing_modes_(0) { enabled_tracing_modes_(0),
background_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
{base::TaskPriority::BACKGROUND})) {
// Deliberately leaked, like this class. // Deliberately leaked, like this class.
base::FileTracing::SetProvider(new FileTracingProviderImpl); base::FileTracing::SetProvider(new FileTracingProviderImpl);
} }
...@@ -166,19 +169,15 @@ bool TracingControllerImpl::GetCategories( ...@@ -166,19 +169,15 @@ bool TracingControllerImpl::GetCategories(
return true; return true;
} }
void TracingControllerImpl::SetEnabledOnFileThread( void TracingControllerImpl::SetEnabledOnBackgroundThread(
const TraceConfig& trace_config, const TraceConfig& trace_config,
const base::Closure& callback) { const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_); TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
} }
void TracingControllerImpl::SetDisabledOnFileThread( void TracingControllerImpl::SetDisabledOnBackgroundThread(
const base::Closure& callback) { const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
DCHECK(enabled_tracing_modes_); DCHECK(enabled_tracing_modes_);
TraceLog::GetInstance()->SetDisabled(enabled_tracing_modes_); TraceLog::GetInstance()->SetDisabled(enabled_tracing_modes_);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
...@@ -338,9 +337,9 @@ void TracingControllerImpl::StopTracingAfterClockSync() { ...@@ -338,9 +337,9 @@ void TracingControllerImpl::StopTracingAfterClockSync() {
// interfering with the process. // interfering with the process.
base::Closure on_stop_tracing_done_callback = base::Bind( base::Closure on_stop_tracing_done_callback = base::Bind(
&TracingControllerImpl::OnStopTracingDone, base::Unretained(this)); &TracingControllerImpl::OnStopTracingDone, base::Unretained(this));
BrowserThread::PostTask( background_task_runner_->PostTask(
BrowserThread::FILE, FROM_HERE, FROM_HERE,
base::BindOnce(&TracingControllerImpl::SetDisabledOnFileThread, base::BindOnce(&TracingControllerImpl::SetDisabledOnBackgroundThread,
base::Unretained(this), on_stop_tracing_done_callback)); base::Unretained(this), on_stop_tracing_done_callback));
} }
...@@ -418,7 +417,7 @@ void TracingControllerImpl::AddTraceMessageFilter( ...@@ -418,7 +417,7 @@ void TracingControllerImpl::AddTraceMessageFilter(
void TracingControllerImpl::RemoveTraceMessageFilter( void TracingControllerImpl::RemoveTraceMessageFilter(
TraceMessageFilter* trace_message_filter) { TraceMessageFilter* trace_message_filter) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// If a filter is removed while a response from that filter is pending then // If a filter is removed while a response from that filter is pending then
// simulate the response. Otherwise the response count will be wrong and the // simulate the response. Otherwise the response count will be wrong and the
...@@ -457,7 +456,8 @@ void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { ...@@ -457,7 +456,8 @@ void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) {
if (agent_name == debug_daemon->GetTracingAgentName()) { if (agent_name == debug_daemon->GetTracingAgentName()) {
additional_tracing_agents_.push_back(debug_daemon); additional_tracing_agents_.push_back(debug_daemon);
debug_daemon->SetStopAgentTracingTaskRunner( debug_daemon->SetStopAgentTracingTaskRunner(
BrowserThread::GetBlockingPool()); base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND}));
return; return;
} }
...@@ -678,16 +678,10 @@ void TracingControllerImpl::StartAgentTracing( ...@@ -678,16 +678,10 @@ void TracingControllerImpl::StartAgentTracing(
base::Closure on_agent_started = base::Closure on_agent_started =
base::Bind(callback, kChromeTracingAgentName, true); base::Bind(callback, kChromeTracingAgentName, true);
if (!BrowserThread::PostTask( background_task_runner_->PostTask(
BrowserThread::FILE, FROM_HERE, FROM_HERE,
base::BindOnce(&TracingControllerImpl::SetEnabledOnFileThread, base::Bind(&TracingControllerImpl::SetEnabledOnBackgroundThread,
base::Unretained(this), trace_config, base::Unretained(this), trace_config, on_agent_started));
on_agent_started))) {
// BrowserThread::PostTask fails if the threads haven't been created yet,
// so it should be safe to just use TraceLog::SetEnabled directly.
TraceLog::GetInstance()->SetEnabled(trace_config, enabled_tracing_modes_);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_agent_started);
}
} }
void TracingControllerImpl::StopAgentTracing( void TracingControllerImpl::StopAgentTracing(
......
...@@ -143,10 +143,10 @@ class TracingControllerImpl ...@@ -143,10 +143,10 @@ class TracingControllerImpl
void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter, void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter,
const base::trace_event::TraceLogStatus& status); const base::trace_event::TraceLogStatus& status);
void SetEnabledOnFileThread( void SetEnabledOnBackgroundThread(
const base::trace_event::TraceConfig& trace_config, const base::trace_event::TraceConfig& trace_config,
const base::Closure& callback); const base::Closure& callback);
void SetDisabledOnFileThread(const base::Closure& callback); void SetDisabledOnBackgroundThread(const base::Closure& callback);
void OnAllTracingAgentsStarted(); void OnAllTracingAgentsStarted();
void StopTracingAfterClockSync(); void StopTracingAfterClockSync();
void OnStopTracingDone(); void OnStopTracingDone();
...@@ -198,6 +198,7 @@ class TracingControllerImpl ...@@ -198,6 +198,7 @@ class TracingControllerImpl
scoped_refptr<TraceDataSink> trace_data_sink_; scoped_refptr<TraceDataSink> trace_data_sink_;
scoped_refptr<TraceDataSink> monitoring_data_sink_; scoped_refptr<TraceDataSink> monitoring_data_sink_;
std::unique_ptr<base::DictionaryValue> metadata_; std::unique_ptr<base::DictionaryValue> metadata_;
const scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl);
}; };
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "base/task_scheduler/post_task.h"
#include "content/browser/tracing/tracing_controller_impl.h" #include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/zlib/zlib.h" #include "third_party/zlib/zlib.h"
...@@ -65,29 +66,30 @@ class FileTraceDataEndpoint : public TraceDataEndpoint { ...@@ -65,29 +66,30 @@ class FileTraceDataEndpoint : public TraceDataEndpoint {
file_(NULL) {} file_(NULL) {}
void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override { void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override {
BrowserThread::PostTask( background_task_runner_->PostTask(
BrowserThread::FILE, FROM_HERE, FROM_HERE,
base::BindOnce(&FileTraceDataEndpoint::ReceiveTraceChunkOnFileThread, base::Bind(&FileTraceDataEndpoint::ReceiveTraceChunkOnBlockingThread,
this, base::Passed(std::move(chunk)))); this, base::Passed(std::move(chunk))));
} }
void ReceiveTraceFinalContents( void ReceiveTraceFinalContents(
std::unique_ptr<const base::DictionaryValue>) override { std::unique_ptr<const base::DictionaryValue>) override {
BrowserThread::PostTask( background_task_runner_->PostTask(
BrowserThread::FILE, FROM_HERE, FROM_HERE,
base::BindOnce(&FileTraceDataEndpoint::CloseOnFileThread, this)); base::Bind(&FileTraceDataEndpoint::CloseOnBlockingThread, this));
} }
private: private:
~FileTraceDataEndpoint() override { DCHECK(file_ == NULL); } ~FileTraceDataEndpoint() override { DCHECK(file_ == NULL); }
void ReceiveTraceChunkOnFileThread(std::unique_ptr<std::string> chunk) { void ReceiveTraceChunkOnBlockingThread(std::unique_ptr<std::string> chunk) {
if (!OpenFileIfNeededOnFileThread()) if (!OpenFileIfNeededOnBlockingThread())
return; return;
ignore_result(fwrite(chunk->c_str(), chunk->size(), 1, file_)); ignore_result(fwrite(chunk->c_str(), chunk->size(), 1, file_));
} }
bool OpenFileIfNeededOnFileThread() { bool OpenFileIfNeededOnBlockingThread() {
base::ThreadRestrictions::AssertIOAllowed();
if (file_ != NULL) if (file_ != NULL)
return true; return true;
file_ = base::OpenFile(file_path_, "w"); file_ = base::OpenFile(file_path_, "w");
...@@ -98,11 +100,12 @@ class FileTraceDataEndpoint : public TraceDataEndpoint { ...@@ -98,11 +100,12 @@ class FileTraceDataEndpoint : public TraceDataEndpoint {
return true; return true;
} }
void CloseOnFileThread() { void CloseOnBlockingThread() {
if (OpenFileIfNeededOnFileThread()) { if (OpenFileIfNeededOnBlockingThread()) {
base::CloseFile(file_); base::CloseFile(file_);
file_ = NULL; file_ = NULL;
} }
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&FileTraceDataEndpoint::FinalizeOnUIThread, this)); base::BindOnce(&FileTraceDataEndpoint::FinalizeOnUIThread, this));
...@@ -113,6 +116,9 @@ class FileTraceDataEndpoint : public TraceDataEndpoint { ...@@ -113,6 +116,9 @@ class FileTraceDataEndpoint : public TraceDataEndpoint {
base::FilePath file_path_; base::FilePath file_path_;
base::Closure completion_callback_; base::Closure completion_callback_;
FILE* file_; FILE* file_;
const scoped_refptr<base::SequencedTaskRunner> background_task_runner_ =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND});
DISALLOW_COPY_AND_ASSIGN(FileTraceDataEndpoint); DISALLOW_COPY_AND_ASSIGN(FileTraceDataEndpoint);
}; };
......
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