Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: shell/tracer.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/window_manager/focus_controller.h ('k') | skia/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_event.h" 15 #include "base/trace_event/trace_event.h"
15 16
16 namespace shell { 17 namespace shell {
17 18
18 Tracer::Tracer() 19 Tracer::Tracer()
19 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) { 20 : tracing_(false), first_chunk_written_(false), trace_file_(nullptr) {
20 } 21 }
21 22
22 Tracer::~Tracer() { 23 Tracer::~Tracer() {
23 } 24 }
24 25
25 void Tracer::Start(const std::string& categories, 26 void Tracer::Start(const std::string& categories,
26 const std::string& duration_seconds_str, 27 const std::string& duration_seconds_str,
27 const std::string& filename) { 28 const std::string& filename) {
28 trace_duration_secs_ = 5; 29 trace_duration_secs_ = 5;
29 if (!duration_seconds_str.empty()) { 30 if (!duration_seconds_str.empty()) {
30 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs_)) 31 CHECK(base::StringToInt(duration_seconds_str, &trace_duration_secs_))
31 << "Could not parse --trace-startup-duration value " 32 << "Could not parse --trace-startup-duration value "
32 << duration_seconds_str; 33 << duration_seconds_str;
33 } 34 }
34 tracing_ = true; 35 tracing_ = true;
35 trace_filename_ = filename; 36 trace_filename_ = filename;
36 categories_ = categories; 37 categories_ = categories;
37 base::trace_event::CategoryFilter category_filter(categories); 38 base::trace_event::TraceConfig config(categories,
39 base::trace_event::RECORD_UNTIL_FULL);
38 base::trace_event::TraceLog::GetInstance()->SetEnabled( 40 base::trace_event::TraceLog::GetInstance()->SetEnabled(
39 category_filter, base::trace_event::TraceLog::RECORDING_MODE, 41 config, base::trace_event::TraceLog::RECORDING_MODE);
40 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL));
41 } 42 }
42 43
43 void Tracer::DidCreateMessageLoop() { 44 void Tracer::DidCreateMessageLoop() {
44 if (!tracing_) 45 if (!tracing_)
45 return; 46 return;
46 47
47 base::MessageLoop::current()->PostDelayedTask( 48 base::MessageLoop::current()->PostDelayedTask(
48 FROM_HERE, 49 FROM_HERE,
49 base::Bind(&shell::Tracer::StopAndFlushToFile, base::Unretained(this)), 50 base::Bind(&shell::Tracer::StopAndFlushToFile, base::Unretained(this)),
50 base::TimeDelta::FromSeconds(trace_duration_secs_)); 51 base::TimeDelta::FromSeconds(trace_duration_secs_));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 WriteFooterAndClose(); 157 WriteFooterAndClose();
157 } 158 }
158 159
159 void Tracer::WriteCommaIfNeeded() { 160 void Tracer::WriteCommaIfNeeded() {
160 if (first_chunk_written_) 161 if (first_chunk_written_)
161 PCHECK(fwrite(",", 1, 1, trace_file_) == 1); 162 PCHECK(fwrite(",", 1, 1, trace_file_) == 1);
162 first_chunk_written_ = true; 163 first_chunk_written_ = true;
163 } 164 }
164 165
165 } // namespace shell 166 } // namespace shell
OLDNEW
« no previous file with comments | « services/window_manager/focus_controller.h ('k') | skia/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698