| 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_ || !events_str_ptr->data().size()) | 83 if (!file_) |
| 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), | 176 base::debug::CategoryFilter(category_filter), trace_options); |
| 177 base::debug::TraceLog::RECORDING_MODE, | |
| 178 trace_options); | |
| 179 is_recording_ = true; | 177 is_recording_ = true; |
| 180 | 178 |
| 181 // Notify all child processes. | 179 // Notify all child processes. |
| 182 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 180 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 183 it != trace_message_filters_.end(); ++it) { | 181 it != trace_message_filters_.end(); ++it) { |
| 184 it->get()->SendBeginTracing(category_filter, trace_options); | 182 it->get()->SendBeginTracing(category_filter, trace_options); |
| 185 } | 183 } |
| 186 | 184 |
| 187 if (!callback.is_null()) | 185 if (!callback.is_null()) |
| 188 callback.Run(); | 186 callback.Run(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (!can_enable_monitoring()) | 240 if (!can_enable_monitoring()) |
| 243 return false; | 241 return false; |
| 244 is_monitoring_ = true; | 242 is_monitoring_ = true; |
| 245 | 243 |
| 246 #if defined(OS_ANDROID) | 244 #if defined(OS_ANDROID) |
| 247 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 245 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
| 248 #endif | 246 #endif |
| 249 | 247 |
| 250 int monitoring_tracing_options = 0; | 248 int monitoring_tracing_options = 0; |
| 251 if (options & ENABLE_SAMPLING) | 249 if (options & ENABLE_SAMPLING) |
| 252 monitoring_tracing_options |= base::debug::TraceLog::ENABLE_SAMPLING; | 250 monitoring_tracing_options |= base::debug::TraceLog::MONITOR_SAMPLING; |
| 253 | 251 |
| 254 TraceLog::GetInstance()->SetEnabled( | 252 TraceLog::GetInstance()->SetEnabled( |
| 255 base::debug::CategoryFilter(category_filter), | 253 base::debug::CategoryFilter(category_filter), |
| 256 base::debug::TraceLog::MONITORING_MODE, | |
| 257 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 254 static_cast<TraceLog::Options>(monitoring_tracing_options)); |
| 258 | 255 |
| 259 // Notify all child processes. | 256 // Notify all child processes. |
| 260 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); | 257 for (TraceMessageFilterMap::iterator it = trace_message_filters_.begin(); |
| 261 it != trace_message_filters_.end(); ++it) { | 258 it != trace_message_filters_.end(); ++it) { |
| 262 it->get()->SendEnableMonitoring(category_filter, | 259 it->get()->SendEnableMonitoring(category_filter, |
| 263 static_cast<TraceLog::Options>(monitoring_tracing_options)); | 260 static_cast<TraceLog::Options>(monitoring_tracing_options)); |
| 264 } | 261 } |
| 265 | 262 |
| 266 if (!callback.is_null()) | 263 if (!callback.is_null()) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 trace_message_filters_.insert(trace_message_filter); | 418 trace_message_filters_.insert(trace_message_filter); |
| 422 if (can_cancel_watch_event()) { | 419 if (can_cancel_watch_event()) { |
| 423 trace_message_filter->SendSetWatchEvent(watch_category_name_, | 420 trace_message_filter->SendSetWatchEvent(watch_category_name_, |
| 424 watch_event_name_); | 421 watch_event_name_); |
| 425 } | 422 } |
| 426 if (can_disable_recording()) { | 423 if (can_disable_recording()) { |
| 427 trace_message_filter->SendBeginTracing( | 424 trace_message_filter->SendBeginTracing( |
| 428 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), | 425 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), |
| 429 TraceLog::GetInstance()->trace_options()); | 426 TraceLog::GetInstance()->trace_options()); |
| 430 } | 427 } |
| 431 if (can_disable_monitoring()) { | |
| 432 trace_message_filter->SendEnableMonitoring( | |
| 433 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(), | |
| 434 TraceLog::GetInstance()->trace_options()); | |
| 435 } | |
| 436 } | 428 } |
| 437 | 429 |
| 438 void TracingControllerImpl::RemoveTraceMessageFilter( | 430 void TracingControllerImpl::RemoveTraceMessageFilter( |
| 439 TraceMessageFilter* trace_message_filter) { | 431 TraceMessageFilter* trace_message_filter) { |
| 440 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 432 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 441 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 433 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 442 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, | 434 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, |
| 443 base::Unretained(this), | 435 base::Unretained(this), |
| 444 make_scoped_refptr(trace_message_filter))); | 436 make_scoped_refptr(trace_message_filter))); |
| 445 return; | 437 return; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 635 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
| 644 base::Unretained(this))); | 636 base::Unretained(this))); |
| 645 return; | 637 return; |
| 646 } | 638 } |
| 647 | 639 |
| 648 if (!watch_event_callback_.is_null()) | 640 if (!watch_event_callback_.is_null()) |
| 649 watch_event_callback_.Run(); | 641 watch_event_callback_.Run(); |
| 650 } | 642 } |
| 651 | 643 |
| 652 } // namespace content | 644 } // namespace content |
| OLD | NEW |