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 "mojo/common/trace_controller_impl.h" | 5 #include "mojo/common/trace_controller_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/trace_event/trace_config.h" |
8 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
9 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
10 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
11 | 12 |
12 namespace mojo { | 13 namespace mojo { |
13 | 14 |
14 TraceControllerImpl::TraceControllerImpl( | 15 TraceControllerImpl::TraceControllerImpl( |
15 InterfaceRequest<tracing::TraceController> request) | 16 InterfaceRequest<tracing::TraceController> request) |
16 : tracing_already_started_(false), binding_(this, request.Pass()) { | 17 : tracing_already_started_(false), binding_(this, request.Pass()) { |
17 } | 18 } |
18 | 19 |
19 TraceControllerImpl::~TraceControllerImpl() { | 20 TraceControllerImpl::~TraceControllerImpl() { |
20 } | 21 } |
21 | 22 |
22 void TraceControllerImpl::StartTracing( | 23 void TraceControllerImpl::StartTracing( |
23 const String& categories, | 24 const String& categories, |
24 tracing::TraceDataCollectorPtr collector) { | 25 tracing::TraceDataCollectorPtr collector) { |
25 DCHECK(!collector_.get()); | 26 DCHECK(!collector_.get()); |
26 collector_ = collector.Pass(); | 27 collector_ = collector.Pass(); |
27 if (!tracing_already_started_) { | 28 if (!tracing_already_started_) { |
28 std::string categories_str = categories.To<std::string>(); | 29 std::string categories_str = categories.To<std::string>(); |
29 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 30 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
30 base::trace_event::CategoryFilter(categories_str), | 31 base::trace_event::TraceConfig(categories_str, |
31 base::trace_event::TraceLog::RECORDING_MODE, | 32 base::trace_event::RECORD_UNTIL_FULL), |
32 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); | 33 base::trace_event::TraceLog::RECORDING_MODE); |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 void TraceControllerImpl::StopTracing() { | 37 void TraceControllerImpl::StopTracing() { |
37 DCHECK(collector_); | 38 DCHECK(collector_); |
38 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 39 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
39 | 40 |
40 base::trace_event::TraceLog::GetInstance()->Flush( | 41 base::trace_event::TraceLog::GetInstance()->Flush( |
41 base::Bind(&TraceControllerImpl::SendChunk, base::Unretained(this))); | 42 base::Bind(&TraceControllerImpl::SendChunk, base::Unretained(this))); |
42 } | 43 } |
43 | 44 |
44 void TraceControllerImpl::SendChunk( | 45 void TraceControllerImpl::SendChunk( |
45 const scoped_refptr<base::RefCountedString>& events_str, | 46 const scoped_refptr<base::RefCountedString>& events_str, |
46 bool has_more_events) { | 47 bool has_more_events) { |
47 DCHECK(collector_); | 48 DCHECK(collector_); |
48 collector_->DataCollected(mojo::String(events_str->data())); | 49 collector_->DataCollected(mojo::String(events_str->data())); |
49 if (!has_more_events) { | 50 if (!has_more_events) { |
50 collector_.reset(); | 51 collector_.reset(); |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 } // namespace mojo | 55 } // namespace mojo |
OLD | NEW |