| 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 "shell/tracer.h" | 5 #include "shell/tracer.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/trace_event/trace_config.h" | 14 #include "base/trace_event/trace_config.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 | 16 |
| 17 namespace shell { | 17 namespace shell { |
| 18 | 18 |
| 19 Tracer::Tracer() | 19 Tracer::Tracer() |
| 20 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) { | 20 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) {} |
| 21 } | |
| 22 | 21 |
| 23 Tracer::~Tracer() { | 22 Tracer::~Tracer() {} |
| 24 } | |
| 25 | 23 |
| 26 void Tracer::Start(const std::string& categories, | 24 void Tracer::Start(const std::string& categories, |
| 27 const std::string& duration_seconds_str, | 25 const std::string& duration_seconds_str, |
| 28 const std::string& filename) { | 26 const std::string& filename) { |
| 29 trace_duration_secs_ = 5; | 27 trace_duration_secs_ = 5; |
| 30 if (!duration_seconds_str.empty()) { | 28 if (!duration_seconds_str.empty()) { |
| 31 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs_)) | 29 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs_)) |
| 32 << "Could not parse --trace-startup-duration value " | 30 << "Could not parse --trace-startup-duration value " |
| 33 << duration_seconds_str; | 31 << duration_seconds_str; |
| 34 } | 32 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 60 this, data_pipe.consumer_handle.Pass())); | 58 this, data_pipe.consumer_handle.Pass())); |
| 61 } | 59 } |
| 62 | 60 |
| 63 void Tracer::StopAndFlushToFile() { | 61 void Tracer::StopAndFlushToFile() { |
| 64 if (tracing_) | 62 if (tracing_) |
| 65 StopTracingAndFlushToDisk(); | 63 StopTracingAndFlushToDisk(); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void Tracer::ConnectToProvider( | 66 void Tracer::ConnectToProvider( |
| 69 mojo::InterfaceRequest<tracing::TraceProvider> request) { | 67 mojo::InterfaceRequest<tracing::TraceProvider> request) { |
| 70 auto impl = new mojo::TraceProviderImpl(request.Pass()); | 68 trace_provider_impl_.Bind(request.Pass()); |
| 71 impl->set_tracing_already_started(tracing_); | |
| 72 } | 69 } |
| 73 | 70 |
| 74 void Tracer::StopTracingAndFlushToDisk() { | 71 void Tracer::StopTracingAndFlushToDisk() { |
| 75 tracing_ = false; | 72 tracing_ = false; |
| 76 trace_file_ = fopen(trace_filename_.c_str(), "w+"); | 73 trace_file_ = fopen(trace_filename_.c_str(), "w+"); |
| 77 PCHECK(trace_file_); | 74 PCHECK(trace_file_); |
| 78 static const char kStart[] = "{\"traceEvents\":["; | 75 static const char kStart[] = "{\"traceEvents\":["; |
| 79 PCHECK(fwrite(kStart, 1, strlen(kStart), trace_file_) == strlen(kStart)); | 76 PCHECK(fwrite(kStart, 1, strlen(kStart), trace_file_) == strlen(kStart)); |
| 80 | 77 |
| 81 // At this point we might be connected to the tracing service, in which case | 78 // At this point we might be connected to the tracing service, in which case |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 WriteFooterAndClose(); | 154 WriteFooterAndClose(); |
| 158 } | 155 } |
| 159 | 156 |
| 160 void Tracer::WriteCommaIfNeeded() { | 157 void Tracer::WriteCommaIfNeeded() { |
| 161 if (first_chunk_written_) | 158 if (first_chunk_written_) |
| 162 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); | 159 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); |
| 163 first_chunk_written_ = true; | 160 first_chunk_written_ = true; |
| 164 } | 161 } |
| 165 | 162 |
| 166 } // namespace shell | 163 } // namespace shell |
| OLD | NEW |