OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tracing/tracing_controller_impl.h" | 5 #include "content/browser/tracing/tracing_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 LOG(ERROR) << "Failed to open " << path_.value(); | 73 LOG(ERROR) << "Failed to open " << path_.value(); |
74 return; | 74 return; |
75 } | 75 } |
76 const char* preamble = "{\"traceEvents\": ["; | 76 const char* preamble = "{\"traceEvents\": ["; |
77 size_t written = fwrite(preamble, strlen(preamble), 1, file_); | 77 size_t written = fwrite(preamble, strlen(preamble), 1, file_); |
78 DCHECK(written == 1); | 78 DCHECK(written == 1); |
79 } | 79 } |
80 | 80 |
81 void TracingControllerImpl::ResultFile::WriteTask( | 81 void TracingControllerImpl::ResultFile::WriteTask( |
82 const scoped_refptr<base::RefCountedString>& events_str_ptr) { | 82 const scoped_refptr<base::RefCountedString>& events_str_ptr) { |
83 if (!file_) | 83 if (!file_ || !events_str_ptr->data().size()) |
84 return; | 84 return; |
85 | 85 |
86 // If there is already a result in the file, then put a commma | 86 // If there is already a result in the file, then put a commma |
87 // before the next batch of results. | 87 // before the next batch of results. |
88 if (has_at_least_one_result_) { | 88 if (has_at_least_one_result_) { |
89 size_t written = fwrite(",", 1, 1, file_); | 89 size_t written = fwrite(",", 1, 1, file_); |
90 DCHECK(written == 1); | 90 DCHECK(written == 1); |
91 } | 91 } |
92 has_at_least_one_result_ = true; | 92 has_at_least_one_result_ = true; |
93 size_t written = fwrite(events_str_ptr->data().c_str(), | 93 size_t written = fwrite(events_str_ptr->data().c_str(), |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 base::Unretained(this), | 416 base::Unretained(this), |
417 make_scoped_refptr(trace_message_filter))); | 417 make_scoped_refptr(trace_message_filter))); |
418 return; | 418 return; |
419 } | 419 } |
420 | 420 |
421 trace_message_filters_.insert(trace_message_filter); | 421 trace_message_filters_.insert(trace_message_filter); |
422 if (can_cancel_watch_event()) { | 422 if (can_cancel_watch_event()) { |
423 trace_message_filter->SendSetWatchEvent(watch_category_name_, | 423 trace_message_filter->SendSetWatchEvent(watch_category_name_, |
424 watch_event_name_); | 424 watch_event_name_); |
425 } | 425 } |
426 if (can_disable_recording()) { | 426 if (can_disable_recording() || can_disable_monitoring()) { |
427 trace_message_filter->SendBeginTracing( | 427 trace_message_filter->SendBeginTracing( |
428 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), | 428 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), |
429 TraceLog::GetInstance()->trace_options()); | 429 TraceLog::GetInstance()->trace_options()); |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 void TracingControllerImpl::RemoveTraceMessageFilter( | 433 void TracingControllerImpl::RemoveTraceMessageFilter( |
434 TraceMessageFilter* trace_message_filter) { | 434 TraceMessageFilter* trace_message_filter) { |
435 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 435 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
436 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 436 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
639 base::Unretained(this))); | 639 base::Unretained(this))); |
640 return; | 640 return; |
641 } | 641 } |
642 | 642 |
643 if (!watch_event_callback_.is_null()) | 643 if (!watch_event_callback_.is_null()) |
644 watch_event_callback_.Run(); | 644 watch_event_callback_.Run(); |
645 } | 645 } |
646 | 646 |
647 } // namespace content | 647 } // namespace content |
OLD | NEW |