| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/tracing_impl.h" | 5 #include "mojo/common/tracing_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "mojo/common/trace_controller_impl.h" |
| 8 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 | 13 |
| 13 // static | 14 TracingImpl::TracingImpl() { |
| 14 void TracingImpl::Create(ApplicationImpl* app) { | |
| 15 new TracingImpl(app); | |
| 16 } | |
| 17 | |
| 18 // static | |
| 19 void TracingImpl::Create(tracing::TraceDataCollectorPtr ptr) { | |
| 20 new TracingImpl(ptr.Pass()); | |
| 21 } | |
| 22 | |
| 23 TracingImpl::TracingImpl(ApplicationImpl* app) : binding_(this) { | |
| 24 ApplicationConnection* connection = app->ConnectToApplication("mojo:tracing"); | |
| 25 tracing::TraceDataCollectorPtr trace_data_collector_ptr; | |
| 26 connection->ConnectToService(&trace_data_collector_ptr); | |
| 27 binding_.Bind(trace_data_collector_ptr.PassMessagePipe()); | |
| 28 } | |
| 29 | |
| 30 TracingImpl::TracingImpl(tracing::TraceDataCollectorPtr ptr) | |
| 31 : binding_(this, ptr.PassMessagePipe()) { | |
| 32 } | 15 } |
| 33 | 16 |
| 34 TracingImpl::~TracingImpl() { | 17 TracingImpl::~TracingImpl() { |
| 35 } | 18 } |
| 36 | 19 |
| 37 void TracingImpl::StartTracing(const String& categories) { | 20 void TracingImpl::Initialize(ApplicationImpl* app) { |
| 38 std::string categories_str = categories.To<std::string>(); | 21 ApplicationConnection* connection = app->ConnectToApplication("mojo:tracing"); |
| 39 base::debug::TraceLog::GetInstance()->SetEnabled( | 22 connection->AddService(this); |
| 40 base::debug::CategoryFilter(categories_str), | |
| 41 base::debug::TraceLog::RECORDING_MODE, | |
| 42 base::debug::TraceOptions(base::debug::RECORD_UNTIL_FULL)); | |
| 43 } | 23 } |
| 44 | 24 |
| 45 void TracingImpl::StopTracing() { | 25 void TracingImpl::Create(ApplicationConnection* connection, |
| 46 base::debug::TraceLog::GetInstance()->SetDisabled(); | 26 InterfaceRequest<tracing::TraceController> request) { |
| 47 | 27 auto impl = new TraceControllerImpl; |
| 48 base::debug::TraceLog::GetInstance()->Flush( | 28 impl->Bind(request.Pass()); |
| 49 base::Bind(&TracingImpl::SendChunk, base::Unretained(this))); | |
| 50 } | |
| 51 | |
| 52 void TracingImpl::SendChunk( | |
| 53 const scoped_refptr<base::RefCountedString>& events_str, | |
| 54 bool has_more_events) { | |
| 55 binding_.client()->DataCollected(mojo::String(events_str->data())); | |
| 56 if (!has_more_events) { | |
| 57 binding_.client()->EndTracing(); | |
| 58 } | |
| 59 } | 29 } |
| 60 | 30 |
| 61 } // namespace mojo | 31 } // namespace mojo |
| OLD | NEW |