OLD | NEW |
1 // Copyright (c) 2011 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 TraceSubscriberStdio { | 23 class AutoStopTraceSubscriberStdio : public content::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 } | |
93 | 89 |
94 std::string delay_str = command_line.GetSwitchValueASCII( | 90 std::string delay_str = command_line.GetSwitchValueASCII( |
95 switches::kTraceStartupDuration); | 91 switches::kTraceStartupDuration); |
96 int delay_secs = 5; | 92 int delay_secs = 5; |
97 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { | 93 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { |
98 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration | 94 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration |
99 << "=" << delay_str << " defaulting to 5 (secs)"; | 95 << "=" << delay_str << " defaulting to 5 (secs)"; |
100 delay_secs = 5; | 96 delay_secs = 5; |
101 } | 97 } |
102 | 98 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // this code only executes if there were child processes. | 303 // this code only executes if there were child processes. |
308 std::vector<std::string> categories; | 304 std::vector<std::string> categories; |
309 TraceLog::GetInstance()->GetKnownCategories(&categories); | 305 TraceLog::GetInstance()->GetKnownCategories(&categories); |
310 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 306 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
311 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), | 307 base::Bind(&TraceController::OnEndTracingAck, base::Unretained(this), |
312 categories)); | 308 categories)); |
313 } | 309 } |
314 } | 310 } |
315 | 311 |
316 void TraceController::OnTraceDataCollected( | 312 void TraceController::OnTraceDataCollected( |
317 const scoped_refptr<TraceLog::RefCountedString>& events_str_ptr) { | 313 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
318 // OnTraceDataCollected may be called from any browser thread, either by the | 314 // OnTraceDataCollected may be called from any browser thread, either by the |
319 // local event trace system or from child processes via TraceMessageFilter. | 315 // local event trace system or from child processes via TraceMessageFilter. |
320 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 316 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
321 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 317 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
322 base::Bind(&TraceController::OnTraceDataCollected, | 318 base::Bind(&TraceController::OnTraceDataCollected, |
323 base::Unretained(this), events_str_ptr)); | 319 base::Unretained(this), events_str_ptr)); |
324 return; | 320 return; |
325 } | 321 } |
326 | 322 |
327 // Drop trace events if we are just getting categories. | 323 // Drop trace events if we are just getting categories. |
328 if (subscriber_ && !is_get_categories_) | 324 if (subscriber_ && !is_get_categories_) |
329 subscriber_->OnTraceDataCollected(events_str_ptr->data); | 325 subscriber_->OnTraceDataCollected(events_str_ptr); |
330 } | 326 } |
331 | 327 |
332 void TraceController::OnTraceBufferFull() { | 328 void TraceController::OnTraceBufferFull() { |
333 // OnTraceBufferFull may be called from any browser thread, either by the | 329 // OnTraceBufferFull may be called from any browser thread, either by the |
334 // local event trace system or from child processes via TraceMessageFilter. | 330 // local event trace system or from child processes via TraceMessageFilter. |
335 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 331 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
336 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 332 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
337 base::Bind(&TraceController::OnTraceBufferFull, | 333 base::Bind(&TraceController::OnTraceBufferFull, |
338 base::Unretained(this))); | 334 base::Unretained(this))); |
339 return; | 335 return; |
(...skipping 26 matching lines...) Expand all Loading... |
366 if (pending_bpf_ack_count_ == 1) { | 362 if (pending_bpf_ack_count_ == 1) { |
367 // The last ack represents local trace, so we need to ack it now. Note that | 363 // The last ack represents local trace, so we need to ack it now. Note that |
368 // this code only executes if there were child processes. | 364 // this code only executes if there were child processes. |
369 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); | 365 float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); |
370 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 366 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
371 base::Bind(&TraceController::OnTraceBufferPercentFullReply, | 367 base::Bind(&TraceController::OnTraceBufferPercentFullReply, |
372 base::Unretained(this), bpf)); | 368 base::Unretained(this), bpf)); |
373 } | 369 } |
374 } | 370 } |
375 | 371 |
OLD | NEW |