| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 TraceLog::Options trace_options = (options & RECORD_CONTINUOUSLY) ? | 167 TraceLog::Options trace_options = (options & RECORD_CONTINUOUSLY) ? |
| 168 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; | 168 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; |
| 169 if (options & ENABLE_SAMPLING) { | 169 if (options & ENABLE_SAMPLING) { |
| 170 trace_options = static_cast<TraceLog::Options>( | 170 trace_options = static_cast<TraceLog::Options>( |
| 171 trace_options | TraceLog::ENABLE_SAMPLING); | 171 trace_options | TraceLog::ENABLE_SAMPLING); |
| 172 } | 172 } |
| 173 // TODO(haraken): How to handle ENABLE_SYSTRACE? | 173 // TODO(haraken): How to handle ENABLE_SYSTRACE? |
| 174 | 174 |
| 175 TraceLog::GetInstance()->SetEnabled( | 175 TraceLog::GetInstance()->SetEnabled( |
| 176 base::debug::CategoryFilter(category_filter), trace_options); | 176 base::debug::CategoryFilter(category_filter), |
| 177 base::debug::TraceLog::RECORDING_MODE, |
| 178 trace_options); |
| 177 is_recording_ = true; | 179 is_recording_ = true; |
| 178 | 180 |
| 179 // Notify all child processes. | 181 // Notify all child processes. |
| 180 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 182 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 181 it != trace_message_filters_.end(); ++it) { | 183 it != trace_message_filters_.end(); ++it) { |
| 182 it->get()->SendBeginTracing(category_filter, trace_options); | 184 it->get()->SendBeginTracing(category_filter, trace_options); |
| 183 } | 185 } |
| 184 | 186 |
| 185 if (!callback.is_null()) | 187 if (!callback.is_null()) |
| 186 callback.Run(); | 188 callback.Run(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (!can_enable_monitoring()) | 242 if (!can_enable_monitoring()) |
| 241 return false; | 243 return false; |
| 242 is_monitoring_ = true; | 244 is_monitoring_ = true; |
| 243 | 245 |
| 244 #if defined(OS_ANDROID) | 246 #if defined(OS_ANDROID) |
| 245 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 247 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 246 #endif | 248 #endif |
| 247 | 249 |
| 248 int monitoring_tracing_options = 0; | 250 int monitoring_tracing_options = 0; |
| 249 if (options & ENABLE_SAMPLING) | 251 if (options & ENABLE_SAMPLING) |
| 250 monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING; | 252 monitoring_tracing_options |= base::debug::TraceLog::ENABLE_SAMPLING; |
| 251 | 253 |
| 252 TraceLog::GetInstance()->SetEnabled( | 254 TraceLog::GetInstance()->SetEnabled( |
| 253 base::debug::CategoryFilter(category_filter), | 255 base::debug::CategoryFilter(category_filter), |
| 256 base::debug::TraceLog::MONITORING_MODE, |
| 254 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 257 static_cast<TraceLog::Options>(monitoring_tracing_options)); |
| 255 | 258 |
| 256 // Notify all child processes. | 259 // Notify all child processes. |
| 257 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 260 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 258 it != trace_message_filters_.end(); ++it) { | 261 it != trace_message_filters_.end(); ++it) { |
| 259 it->get()->SendEnableMonitoring(category_filter, | 262 it->get()->SendEnableMonitoring(category_filter, |
| 260 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 263 static_cast<TraceLog::Options>(monitoring_tracing_options)); |
| 261 } | 264 } |
| 262 | 265 |
| 263 if (!callback.is_null()) | 266 if (!callback.is_null()) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 base::Unretained(this), | 416 base::Unretained(this), |
| 414 make_scoped_refptr(trace_message_filter))); | 417 make_scoped_refptr(trace_message_filter))); |
| 415 return; | 418 return; |
| 416 } | 419 } |
| 417 | 420 |
| 418 trace_message_filters_.insert(trace_message_filter); | 421 trace_message_filters_.insert(trace_message_filter); |
| 419 if (can_cancel_watch_event()) { | 422 if (can_cancel_watch_event()) { |
| 420 trace_message_filter->SendSetWatchEvent(watch_category_name_, | 423 trace_message_filter->SendSetWatchEvent(watch_category_name_, |
| 421 watch_event_name_); | 424 watch_event_name_); |
| 422 } | 425 } |
| 423 if (can_disable_recording()) { | 426 if (can_disable_recording() || can_disable_monitoring()) { |
| 424 trace_message_filter->SendBeginTracing( | 427 trace_message_filter->SendBeginTracing( |
| 425 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), | 428 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), |
| 426 TraceLog::GetInstance()->trace_options()); | 429 TraceLog::GetInstance()->trace_options()); |
| 427 } | 430 } |
| 428 } | 431 } |
| 429 | 432 |
| 430 void TracingControllerImpl::RemoveTraceMessageFilter( | 433 void TracingControllerImpl::RemoveTraceMessageFilter( |
| 431 TraceMessageFilter* trace_message_filter) { | 434 TraceMessageFilter* trace_message_filter) { |
| 432 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 435 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 433 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... |
| 635 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 638 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
| 636 base::Unretained(this))); | 639 base::Unretained(this))); |
| 637 return; | 640 return; |
| 638 } | 641 } |
| 639 | 642 |
| 640 if (!watch_event_callback_.is_null()) | 643 if (!watch_event_callback_.is_null()) |
| 641 watch_event_callback_.Run(); | 644 watch_event_callback_.Run(); |
| 642 } | 645 } |
| 643 | 646 |
| 644 } // namespace content | 647 } // namespace content |
| OLD | NEW |