| 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> |
| 11 | 11 |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/trace_event/trace_config.h" | 18 #include "base/trace_event/trace_config.h" |
| 18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 19 | 20 |
| 20 namespace shell { | 21 namespace shell { |
| 21 | 22 |
| 22 Tracer::Tracer() | 23 Tracer::Tracer() |
| 23 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) {} | 24 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) {} |
| 24 | 25 |
| 25 Tracer::~Tracer() { | 26 Tracer::~Tracer() { |
| 26 StopAndFlushToFile(); | 27 StopAndFlushToFile(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void Tracer::Start(const std::string& categories, | 30 void Tracer::Start(const std::string& categories, |
| 30 const std::string& duration_seconds_str, | 31 const std::string& duration_seconds_str, |
| 31 const std::string& filename) { | 32 const std::string& filename) { |
| 32 tracing_ = true; | 33 tracing_ = true; |
| 33 trace_filename_ = filename; | 34 trace_filename_ = filename; |
| 34 categories_ = categories; | 35 categories_ = categories; |
| 35 base::trace_event::TraceConfig config(categories, | 36 base::trace_event::TraceConfig config(categories, |
| 36 base::trace_event::RECORD_UNTIL_FULL); | 37 base::trace_event::RECORD_UNTIL_FULL); |
| 37 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 38 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 38 config, base::trace_event::TraceLog::RECORDING_MODE); | 39 config, base::trace_event::TraceLog::RECORDING_MODE); |
| 39 | 40 |
| 40 int trace_duration_secs = 5; | 41 int trace_duration_secs = 5; |
| 41 if (!duration_seconds_str.empty()) { | 42 if (!duration_seconds_str.empty()) { |
| 42 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs)) | 43 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs)) |
| 43 << "Could not parse --trace-startup-duration value " | 44 << "Could not parse --trace-startup-duration value " |
| 44 << duration_seconds_str; | 45 << duration_seconds_str; |
| 45 } | 46 } |
| 46 base::MessageLoop::current()->task_runner()->PostDelayedTask( | 47 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 47 FROM_HERE, | 48 FROM_HERE, |
| 48 base::Bind(&Tracer::StopAndFlushToFile, base::Unretained(this)), | 49 base::Bind(&Tracer::StopAndFlushToFile, base::Unretained(this)), |
| 49 base::TimeDelta::FromSeconds(trace_duration_secs)); | 50 base::TimeDelta::FromSeconds(trace_duration_secs)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void Tracer::StartCollectingFromTracingService( | 53 void Tracer::StartCollectingFromTracingService( |
| 53 tracing::mojom::CollectorPtr coordinator) { | 54 tracing::mojom::CollectorPtr coordinator) { |
| 54 coordinator_ = std::move(coordinator); | 55 coordinator_ = std::move(coordinator); |
| 55 mojo::DataPipe data_pipe; | 56 mojo::DataPipe data_pipe; |
| 56 coordinator_->Start(std::move(data_pipe.producer_handle), categories_); | 57 coordinator_->Start(std::move(data_pipe.producer_handle), categories_); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 WriteFooterAndClose(); | 156 WriteFooterAndClose(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void Tracer::WriteCommaIfNeeded() { | 159 void Tracer::WriteCommaIfNeeded() { |
| 159 if (first_chunk_written_) | 160 if (first_chunk_written_) |
| 160 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); | 161 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); |
| 161 first_chunk_written_ = true; | 162 first_chunk_written_ = true; |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace shell | 165 } // namespace shell |
| OLD | NEW |