| 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/shell/standalone/tracer.h" | 5 #include "services/shell/standalone/tracer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 << "Could not parse --trace-startup-duration value " | 43 << "Could not parse --trace-startup-duration value " |
| 44 << duration_seconds_str; | 44 << duration_seconds_str; |
| 45 } | 45 } |
| 46 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 46 base::MessageLoop::current()->task_runner()->PostDelayedTask( |
| 47 FROM_HERE, | 47 FROM_HERE, |
| 48 base::Bind(&Tracer::StopAndFlushToFile, base::Unretained(this)), | 48 base::Bind(&Tracer::StopAndFlushToFile, base::Unretained(this)), |
| 49 base::TimeDelta::FromSeconds(trace_duration_secs)); | 49 base::TimeDelta::FromSeconds(trace_duration_secs)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Tracer::StartCollectingFromTracingService( | 52 void Tracer::StartCollectingFromTracingService( |
| 53 tracing::TraceCollectorPtr coordinator) { | 53 tracing::mojom::CollectorPtr coordinator) { |
| 54 coordinator_ = std::move(coordinator); | 54 coordinator_ = std::move(coordinator); |
| 55 mojo::DataPipe data_pipe; | 55 mojo::DataPipe data_pipe; |
| 56 coordinator_->Start(std::move(data_pipe.producer_handle), categories_); | 56 coordinator_->Start(std::move(data_pipe.producer_handle), categories_); |
| 57 drainer_.reset(new mojo::common::DataPipeDrainer( | 57 drainer_.reset(new mojo::common::DataPipeDrainer( |
| 58 this, std::move(data_pipe.consumer_handle))); | 58 this, std::move(data_pipe.consumer_handle))); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void Tracer::StopAndFlushToFile() { | 61 void Tracer::StopAndFlushToFile() { |
| 62 if (tracing_) | 62 if (tracing_) |
| 63 StopTracingAndFlushToDisk(); | 63 StopTracingAndFlushToDisk(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Tracer::ConnectToProvider( | 66 void Tracer::ConnectToProvider(tracing::mojom::ProviderRequest request) { |
| 67 mojo::InterfaceRequest<tracing::TraceProvider> request) { | 67 provider_.Bind(std::move(request)); |
| 68 trace_provider_impl_.Bind(std::move(request)); | |
| 69 } | 68 } |
| 70 | 69 |
| 71 void Tracer::StopTracingAndFlushToDisk() { | 70 void Tracer::StopTracingAndFlushToDisk() { |
| 72 tracing_ = false; | 71 tracing_ = false; |
| 73 trace_file_ = fopen(trace_filename_.c_str(), "w+"); | 72 trace_file_ = fopen(trace_filename_.c_str(), "w+"); |
| 74 PCHECK(trace_file_); | 73 PCHECK(trace_file_); |
| 75 static const char kStart[] = "{\"traceEvents\":["; | 74 static const char kStart[] = "{\"traceEvents\":["; |
| 76 PCHECK(fwrite(kStart, 1, strlen(kStart), trace_file_) == strlen(kStart)); | 75 PCHECK(fwrite(kStart, 1, strlen(kStart), trace_file_) == strlen(kStart)); |
| 77 | 76 |
| 78 // At this point we might be connected to the tracing service, in which case | 77 // At this point we might be connected to the tracing service, in which case |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 WriteFooterAndClose(); | 155 WriteFooterAndClose(); |
| 157 } | 156 } |
| 158 | 157 |
| 159 void Tracer::WriteCommaIfNeeded() { | 158 void Tracer::WriteCommaIfNeeded() { |
| 160 if (first_chunk_written_) | 159 if (first_chunk_written_) |
| 161 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); | 160 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); |
| 162 first_chunk_written_ = true; | 161 first_chunk_written_ = true; |
| 163 } | 162 } |
| 164 | 163 |
| 165 } // namespace shell | 164 } // namespace shell |
| OLD | NEW |