OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/trace_controller.h" | 5 #include "content/browser/trace_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "content/browser/trace_message_filter.h" | 11 #include "content/browser/trace_message_filter.h" |
12 #include "content/browser/trace_subscriber_stdio.h" | 12 #include "content/browser/trace_subscriber_stdio.h" |
13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
14 #include "content/public/browser/browser_message_filter.h" | 14 #include "content/public/browser/browser_message_filter.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 | 16 |
17 using base::debug::TraceLog; | 17 using base::debug::TraceLog; |
18 using content::BrowserMessageFilter; | 18 using content::BrowserMessageFilter; |
19 using content::BrowserThread; | 19 using content::BrowserThread; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class AutoStopTraceSubscriberStdio : public content::TraceSubscriberStdio { | 23 class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio { |
24 public: | 24 public: |
25 AutoStopTraceSubscriberStdio(const FilePath& file_path) | 25 AutoStopTraceSubscriberStdio(const FilePath& file_path) |
26 : TraceSubscriberStdio(file_path) {} | 26 : TraceSubscriberStdio(file_path) {} |
27 | 27 |
28 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { | 28 static void EndStartupTrace(TraceSubscriberStdio* subscriber) { |
29 if (!TraceController::GetInstance()->EndTracingAsync(subscriber)) | 29 if (!TraceController::GetInstance()->EndTracingAsync(subscriber)) |
30 delete subscriber; | 30 delete subscriber; |
31 // else, the tracing will end asynchronously in OnEndTracingComplete(). | 31 // else, the tracing will end asynchronously in OnEndTracingComplete(). |
32 } | 32 } |
33 | 33 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (trace_file == FilePath().AppendASCII("none")) | 79 if (trace_file == FilePath().AppendASCII("none")) |
80 return; | 80 return; |
81 | 81 |
82 if (trace_file.empty()) { | 82 if (trace_file.empty()) { |
83 // Default to saving the startup trace into the current dir. | 83 // Default to saving the startup trace into the current dir. |
84 trace_file = FilePath().AppendASCII("chrometrace.log"); | 84 trace_file = FilePath().AppendASCII("chrometrace.log"); |
85 } | 85 } |
86 scoped_ptr<AutoStopTraceSubscriberStdio> subscriber( | 86 scoped_ptr<AutoStopTraceSubscriberStdio> subscriber( |
87 new AutoStopTraceSubscriberStdio(trace_file)); | 87 new AutoStopTraceSubscriberStdio(trace_file)); |
88 DCHECK(can_begin_tracing(subscriber.get())); | 88 DCHECK(can_begin_tracing(subscriber.get())); |
| 89 if (!subscriber->IsValid()) { |
| 90 TraceLog::GetInstance()->SetDisabled(); |
| 91 return; |
| 92 } |
89 | 93 |
90 std::string delay_str = command_line.GetSwitchValueASCII( | 94 std::string delay_str = command_line.GetSwitchValueASCII( |
91 switches::kTraceStartupDuration); | 95 switches::kTraceStartupDuration); |
92 int delay_secs = 5; | 96 int delay_secs = 5; |
93 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 97 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
94 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 98 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
95 << "=" << delay_str << " defaulting to 5 (secs)"; | 99 << "=" << delay_str << " defaulting to 5 (secs)"; |
96 delay_secs = 5; | 100 delay_secs = 5; |
97 } | 101 } |
98 | 102 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 // this code only executes if there were child processes. | 307 // this code only executes if there were child processes. |
304 std::vector<std::string> categories; | 308 std::vector<std::string> categories; |
305 TraceLog::GetInstance()->GetKnownCategories(&categories); | 309 TraceLog::GetInstance()->GetKnownCategories(&categories); |
306 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 310 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
307 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), | 311 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), |
308 categories)); | 312 categories)); |
309 } | 313 } |
310 } | 314 } |
311 | 315 |
312 void TraceController::OnTraceDataCollected( | 316 void TraceController::OnTraceDataCollected( |
313 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 317 const scoped_refptr<TraceLog::RefCountedString>& events_str_ptr) { |
314 // OnTraceDataCollected may be called from any browser thread, either by the | 318 // OnTraceDataCollected may be called from any browser thread, either by the |
315 // local event trace system or from child processes via TraceMessageFilter. | 319 // local event trace system or from child processes via TraceMessageFilter. |
316 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 320 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
317 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 321 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
318 base::Bind(&TraceController::OnTraceDataCollected, | 322 base::Bind(&TraceController::OnTraceDataCollected, |
319 base::Unretained(this), events_str_ptr)); | 323 base::Unretained(this), events_str_ptr)); |
320 return; | 324 return; |
321 } | 325 } |
322 | 326 |
323 // Drop trace events if we are just getting categories. | 327 // Drop trace events if we are just getting categories. |
324 if (subscriber_ && !is_get_categories_) | 328 if (subscriber_ && !is_get_categories_) |
325 subscriber_->OnTraceDataCollected(events_str_ptr); | 329 subscriber_->OnTraceDataCollected(events_str_ptr->data); |
326 } | 330 } |
327 | 331 |
328 void TraceController::OnTraceBufferFull() { | 332 void TraceController::OnTraceBufferFull() { |
329 // OnTraceBufferFull may be called from any browser thread, either by the | 333 // OnTraceBufferFull may be called from any browser thread, either by the |
330 // local event trace system or from child processes via TraceMessageFilter. | 334 // local event trace system or from child processes via TraceMessageFilter. |
331 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 335 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
332 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 336 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
333 base::Bind(&TraceController::OnTraceBufferFull, | 337 base::Bind(&TraceController::OnTraceBufferFull, |
334 base::Unretained(this))); | 338 base::Unretained(this))); |
335 return; | 339 return; |
(...skipping 26 matching lines...) Expand all Loading... |
362 if (pending_bpf_ack_count_ == 1) { | 366 if (pending_bpf_ack_count_ == 1) { |
363 // The last ack represents local trace, so we need to ack it now. Note that | 367 // The last ack represents local trace, so we need to ack it now. Note that |
364 // this code only executes if there were child processes. | 368 // this code only executes if there were child processes. |
365 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 369 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
366 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 370 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
367 base::Bind(&TraceController::OnTraceBufferPercentFullReply, | 371 base::Bind(&TraceController::OnTraceBufferPercentFullReply, |
368 base::Unretained(this), bpf)); | 372 base::Unretained(this), bpf)); |
369 } | 373 } |
370 } | 374 } |
371 | 375 |
OLD | NEW |