| 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/services/tracing/tracing_app.h" | 5 #include "mojo/services/tracing/tracing_app.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/application/public/cpp/application_connection.h" | 9 #include "mojo/application/public/cpp/application_connection.h" |
| 10 #include "mojo/services/tracing/trace_data_sink.h" | 10 #include "mojo/services/tracing/trace_data_sink.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 DISALLOW_COPY_AND_ASSIGN(CollectorImpl); | 31 DISALLOW_COPY_AND_ASSIGN(CollectorImpl); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 TracingApp::TracingApp() {} | 34 TracingApp::TracingApp() {} |
| 35 | 35 |
| 36 TracingApp::~TracingApp() {} | 36 TracingApp::~TracingApp() {} |
| 37 | 37 |
| 38 bool TracingApp::ConfigureIncomingConnection( | 38 bool TracingApp::ConfigureIncomingConnection( |
| 39 mojo::ApplicationConnection* connection) { | 39 mojo::ApplicationConnection* connection) { |
| 40 connection->AddService<TraceCoordinator>(this); | 40 connection->AddService<TraceCoordinator>(this); |
| 41 connection->AddService<StartupPerformanceDataCollector>(this); |
| 41 | 42 |
| 42 // If someone connects to us they may want to use the TraceCoordinator | 43 // If someone connects to us they may want to use the TraceCoordinator |
| 43 // interface and/or they may want to expose themselves to be traced. Attempt | 44 // interface and/or they may want to expose themselves to be traced. Attempt |
| 44 // to connect to the TraceController interface to see if the application | 45 // to connect to the TraceController interface to see if the application |
| 45 // connecting to us wants to be traced. They can refuse the connection or | 46 // connecting to us wants to be traced. They can refuse the connection or |
| 46 // close the pipe if not. | 47 // close the pipe if not. |
| 47 TraceControllerPtr controller_ptr; | 48 TraceControllerPtr controller_ptr; |
| 48 connection->ConnectToService(&controller_ptr); | 49 connection->ConnectToService(&controller_ptr); |
| 49 controller_ptrs_.AddInterfacePtr(controller_ptr.Pass()); | 50 if (controller_ptr) |
| 51 controller_ptrs_.AddInterfacePtr(controller_ptr.Pass()); |
| 50 return true; | 52 return true; |
| 51 } | 53 } |
| 52 | 54 |
| 53 void TracingApp::Create( | 55 void TracingApp::Create( |
| 54 mojo::ApplicationConnection* connection, | 56 mojo::ApplicationConnection* connection, |
| 55 mojo::InterfaceRequest<TraceCoordinator> request) { | 57 mojo::InterfaceRequest<TraceCoordinator> request) { |
| 56 coordinator_bindings_.AddBinding(this, request.Pass()); | 58 coordinator_bindings_.AddBinding(this, request.Pass()); |
| 57 } | 59 } |
| 58 | 60 |
| 61 void TracingApp::Create( |
| 62 mojo::ApplicationConnection* connection, |
| 63 mojo::InterfaceRequest<StartupPerformanceDataCollector> request) { |
| 64 startup_performance_data_collector_bindings_.AddBinding(this, request.Pass()); |
| 65 } |
| 66 |
| 59 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, | 67 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, |
| 60 const mojo::String& categories) { | 68 const mojo::String& categories) { |
| 61 sink_.reset(new TraceDataSink(stream.Pass())); | 69 sink_.reset(new TraceDataSink(stream.Pass())); |
| 62 controller_ptrs_.ForAllPtrs( | 70 controller_ptrs_.ForAllPtrs( |
| 63 [categories, this](TraceController* controller) { | 71 [categories, this](TraceController* controller) { |
| 64 TraceDataCollectorPtr ptr; | 72 TraceDataCollectorPtr ptr; |
| 65 collector_impls_.push_back( | 73 collector_impls_.push_back( |
| 66 new CollectorImpl(GetProxy(&ptr), sink_.get())); | 74 new CollectorImpl(GetProxy(&ptr), sink_.get())); |
| 67 controller->StartTracing(categories, ptr.Pass()); | 75 controller->StartTracing(categories, ptr.Pass()); |
| 68 }); | 76 }); |
| 69 } | 77 } |
| 70 | 78 |
| 71 void TracingApp::StopAndFlush() { | 79 void TracingApp::StopAndFlush() { |
| 72 controller_ptrs_.ForAllPtrs( | 80 controller_ptrs_.ForAllPtrs( |
| 73 [](TraceController* controller) { controller->StopTracing(); }); | 81 [](TraceController* controller) { controller->StopTracing(); }); |
| 74 | 82 |
| 75 // TODO: We really should keep track of how many connections we have here | 83 // TODO: We really should keep track of how many connections we have here |
| 76 // and flush + reset the sink after we receive a EndTracing or a detect a | 84 // and flush + reset the sink after we receive a EndTracing or a detect a |
| 77 // pipe closure on all pipes. | 85 // pipe closure on all pipes. |
| 78 base::MessageLoop::current()->PostDelayedTask( | 86 base::MessageLoop::current()->PostDelayedTask( |
| 79 FROM_HERE, | 87 FROM_HERE, |
| 80 base::Bind(&TracingApp::AllDataCollected, base::Unretained(this)), | 88 base::Bind(&TracingApp::AllDataCollected, base::Unretained(this)), |
| 81 base::TimeDelta::FromSeconds(1)); | 89 base::TimeDelta::FromSeconds(1)); |
| 82 } | 90 } |
| 83 | 91 |
| 92 void TracingApp::SetShellProcessCreationTime(int64 time) { |
| 93 if (startup_performance_times_.shell_process_creation_time == 0) |
| 94 startup_performance_times_.shell_process_creation_time = time; |
| 95 } |
| 96 |
| 97 void TracingApp::SetBrowserMessageLoopStartTime(int64 time) { |
| 98 if (startup_performance_times_.browser_message_loop_start_time == 0) |
| 99 startup_performance_times_.browser_message_loop_start_time = time; |
| 100 } |
| 101 |
| 102 void TracingApp::SetBrowserWindowDisplayTime(int64 time) { |
| 103 if (startup_performance_times_.browser_window_display_time == 0) |
| 104 startup_performance_times_.browser_window_display_time = time; |
| 105 } |
| 106 |
| 107 void TracingApp::SetBrowserOpenTabsTime(int64 time) { |
| 108 if (startup_performance_times_.browser_open_tabs_time == 0) |
| 109 startup_performance_times_.browser_open_tabs_time = time; |
| 110 } |
| 111 |
| 112 void TracingApp::SetFirstWebContentsMainFrameLoadTime(int64 time) { |
| 113 if (startup_performance_times_.first_web_contents_main_frame_load_time == 0) |
| 114 startup_performance_times_.first_web_contents_main_frame_load_time = time; |
| 115 } |
| 116 |
| 117 void TracingApp::SetFirstVisuallyNonEmptyLayoutTime(int64 time) { |
| 118 if (startup_performance_times_.first_visually_non_empty_layout_time == 0) |
| 119 startup_performance_times_.first_visually_non_empty_layout_time = time; |
| 120 } |
| 121 |
| 122 void TracingApp::GetStartupPerformanceTimes( |
| 123 const GetStartupPerformanceTimesCallback& callback) { |
| 124 callback.Run(startup_performance_times_.Clone()); |
| 125 } |
| 126 |
| 84 void TracingApp::AllDataCollected() { | 127 void TracingApp::AllDataCollected() { |
| 85 collector_impls_.clear(); | 128 collector_impls_.clear(); |
| 86 sink_->Flush(); | 129 sink_->Flush(); |
| 87 } | 130 } |
| 88 | 131 |
| 89 } // namespace tracing | 132 } // namespace tracing |
| OLD | NEW |