| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/tracing/public/cpp/provider.h" | 5 #include "services/tracing/public/cpp/provider.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "base/trace_event/trace_config.h" | 18 #include "base/trace_event/trace_config.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 #include "services/shell/public/cpp/connection.h" | 20 #include "services/shell/public/cpp/connection.h" |
| 20 #include "services/shell/public/cpp/connector.h" | 21 #include "services/shell/public/cpp/connector.h" |
| 21 #include "services/tracing/public/cpp/switches.h" | 22 #include "services/tracing/public/cpp/switches.h" |
| 22 | 23 |
| 23 namespace tracing { | 24 namespace tracing { |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 base::trace_event::TraceLog::GetInstance()->Flush( | 101 base::trace_event::TraceLog::GetInstance()->Flush( |
| 101 base::Bind(&Provider::SendChunk, base::Unretained(this))); | 102 base::Bind(&Provider::SendChunk, base::Unretained(this))); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 void Provider::ForceEnableTracing() { | 106 void Provider::ForceEnableTracing() { |
| 106 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 107 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 107 base::trace_event::TraceConfig("*", base::trace_event::RECORD_UNTIL_FULL), | 108 base::trace_event::TraceConfig("*", base::trace_event::RECORD_UNTIL_FULL), |
| 108 base::trace_event::TraceLog::RECORDING_MODE); | 109 base::trace_event::TraceLog::RECORDING_MODE); |
| 109 tracing_forced_ = true; | 110 tracing_forced_ = true; |
| 110 base::MessageLoop::current()->task_runner()->PostTask( | 111 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 111 FROM_HERE, | 112 FROM_HERE, |
| 112 base::Bind(&Provider::DelayedStop, weak_factory_.GetWeakPtr())); | 113 base::Bind(&Provider::DelayedStop, weak_factory_.GetWeakPtr())); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void Provider::DelayedStop() { | 116 void Provider::DelayedStop() { |
| 116 // We use this indirection to account for cases where the Initialize method | 117 // We use this indirection to account for cases where the Initialize method |
| 117 // takes more than one second to finish; thus we start the countdown only when | 118 // takes more than one second to finish; thus we start the countdown only when |
| 118 // the current thread is unblocked. | 119 // the current thread is unblocked. |
| 119 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 120 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 120 FROM_HERE, | 121 FROM_HERE, |
| 121 base::Bind(&Provider::StopIfForced, weak_factory_.GetWeakPtr()), | 122 base::Bind(&Provider::StopIfForced, weak_factory_.GetWeakPtr()), |
| 122 base::TimeDelta::FromSeconds(1)); | 123 base::TimeDelta::FromSeconds(1)); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void Provider::StopIfForced() { | 126 void Provider::StopIfForced() { |
| 126 if (!tracing_forced_) { | 127 if (!tracing_forced_) { |
| 127 return; | 128 return; |
| 128 } | 129 } |
| 129 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 130 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 // events. Empty string is not a valid chunk to record so skip in this case. | 141 // events. Empty string is not a valid chunk to record so skip in this case. |
| 141 if (!events_str->data().empty()) { | 142 if (!events_str->data().empty()) { |
| 142 recorder_->Record(mojo::String(events_str->data())); | 143 recorder_->Record(mojo::String(events_str->data())); |
| 143 } | 144 } |
| 144 if (!has_more_events) { | 145 if (!has_more_events) { |
| 145 recorder_.reset(); | 146 recorder_.reset(); |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 } // namespace tracing | 150 } // namespace tracing |
| OLD | NEW |