| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include "content/browser/tracing/tracing_controller_impl.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/cpu.h" | 7 #include "base/cpu.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 approximate_event_count_ = 0; | 405 approximate_event_count_ = 0; |
| 406 | 406 |
| 407 base::trace_event::TraceLogStatus status = | 407 base::trace_event::TraceLogStatus status = |
| 408 TraceLog::GetInstance()->GetStatus(); | 408 TraceLog::GetInstance()->GetStatus(); |
| 409 // Call OnTraceLogStatusReply unconditionally for the browser process. | 409 // Call OnTraceLogStatusReply unconditionally for the browser process. |
| 410 // This will result in immediate execution of the callback if there are no | 410 // This will result in immediate execution of the callback if there are no |
| 411 // child processes. | 411 // child processes. |
| 412 BrowserThread::PostTask( | 412 BrowserThread::PostTask( |
| 413 BrowserThread::UI, FROM_HERE, | 413 BrowserThread::UI, FROM_HERE, |
| 414 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 414 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 415 base::Unretained(this), scoped_refptr<TraceMessageFilter>(), | 415 base::Unretained(this), nullptr, status)); |
| 416 status)); | |
| 417 | 416 |
| 418 // Notify all child processes. | 417 // Notify all child processes. |
| 419 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 418 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
| 420 it != trace_message_filters_.end(); ++it) { | 419 it != trace_message_filters_.end(); ++it) { |
| 421 it->get()->SendGetTraceLogStatus(); | 420 it->get()->SendGetTraceLogStatus(); |
| 422 } | 421 } |
| 423 return true; | 422 return true; |
| 424 } | 423 } |
| 425 | 424 |
| 426 bool TracingControllerImpl::SetWatchEvent( | 425 bool TracingControllerImpl::SetWatchEvent( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return true; | 462 return true; |
| 464 } | 463 } |
| 465 | 464 |
| 466 bool TracingControllerImpl::IsTracing() const { | 465 bool TracingControllerImpl::IsTracing() const { |
| 467 return is_tracing_; | 466 return is_tracing_; |
| 468 } | 467 } |
| 469 | 468 |
| 470 void TracingControllerImpl::AddTraceMessageFilter( | 469 void TracingControllerImpl::AddTraceMessageFilter( |
| 471 TraceMessageFilter* trace_message_filter) { | 470 TraceMessageFilter* trace_message_filter) { |
| 472 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 471 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 473 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 472 BrowserThread::PostTask( |
| 473 BrowserThread::UI, FROM_HERE, |
| 474 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, | 474 base::Bind(&TracingControllerImpl::AddTraceMessageFilter, |
| 475 base::Unretained(this), | 475 base::Unretained(this), |
| 476 make_scoped_refptr(trace_message_filter))); | 476 base::RetainedRef(trace_message_filter))); |
| 477 return; | 477 return; |
| 478 } | 478 } |
| 479 | 479 |
| 480 #if defined(OS_LINUX) | 480 #if defined(OS_LINUX) |
| 481 // On Linux the browser process dumps process metrics for child process due to | 481 // On Linux the browser process dumps process metrics for child process due to |
| 482 // sandbox. | 482 // sandbox. |
| 483 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( | 483 tracing::ProcessMetricsMemoryDumpProvider::RegisterForProcess( |
| 484 trace_message_filter->peer_pid()); | 484 trace_message_filter->peer_pid()); |
| 485 #endif | 485 #endif |
| 486 | 486 |
| 487 trace_message_filters_.insert(trace_message_filter); | 487 trace_message_filters_.insert(trace_message_filter); |
| 488 if (can_cancel_watch_event()) { | 488 if (can_cancel_watch_event()) { |
| 489 trace_message_filter->SendSetWatchEvent(watch_category_name_, | 489 trace_message_filter->SendSetWatchEvent(watch_category_name_, |
| 490 watch_event_name_); | 490 watch_event_name_); |
| 491 } | 491 } |
| 492 if (can_stop_tracing()) { | 492 if (can_stop_tracing()) { |
| 493 trace_message_filter->SendBeginTracing( | 493 trace_message_filter->SendBeginTracing( |
| 494 TraceLog::GetInstance()->GetCurrentTraceConfig()); | 494 TraceLog::GetInstance()->GetCurrentTraceConfig()); |
| 495 } | 495 } |
| 496 | 496 |
| 497 FOR_EACH_OBSERVER(TraceMessageFilterObserver, trace_message_filter_observers_, | 497 FOR_EACH_OBSERVER(TraceMessageFilterObserver, trace_message_filter_observers_, |
| 498 OnTraceMessageFilterAdded(trace_message_filter)); | 498 OnTraceMessageFilterAdded(trace_message_filter)); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void TracingControllerImpl::RemoveTraceMessageFilter( | 501 void TracingControllerImpl::RemoveTraceMessageFilter( |
| 502 TraceMessageFilter* trace_message_filter) { | 502 TraceMessageFilter* trace_message_filter) { |
| 503 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 503 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 504 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 504 BrowserThread::PostTask( |
| 505 BrowserThread::UI, FROM_HERE, |
| 505 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, | 506 base::Bind(&TracingControllerImpl::RemoveTraceMessageFilter, |
| 506 base::Unretained(this), | 507 base::Unretained(this), |
| 507 make_scoped_refptr(trace_message_filter))); | 508 base::RetainedRef(trace_message_filter))); |
| 508 return; | 509 return; |
| 509 } | 510 } |
| 510 | 511 |
| 511 #if defined(OS_LINUX) | 512 #if defined(OS_LINUX) |
| 512 tracing::ProcessMetricsMemoryDumpProvider::UnregisterForProcess( | 513 tracing::ProcessMetricsMemoryDumpProvider::UnregisterForProcess( |
| 513 trace_message_filter->peer_pid()); | 514 trace_message_filter->peer_pid()); |
| 514 #endif | 515 #endif |
| 515 | 516 |
| 516 // If a filter is removed while a response from that filter is pending then | 517 // If a filter is removed while a response from that filter is pending then |
| 517 // simulate the response. Otherwise the response count will be wrong and the | 518 // simulate the response. Otherwise the response count will be wrong and the |
| 518 // completion callback will never be executed. | 519 // completion callback will never be executed. |
| 519 if (pending_stop_tracing_ack_count_ > 0) { | 520 if (pending_stop_tracing_ack_count_ > 0) { |
| 520 TraceMessageFilterSet::const_iterator it = | 521 TraceMessageFilterSet::const_iterator it = |
| 521 pending_stop_tracing_filters_.find(trace_message_filter); | 522 pending_stop_tracing_filters_.find(trace_message_filter); |
| 522 if (it != pending_stop_tracing_filters_.end()) { | 523 if (it != pending_stop_tracing_filters_.end()) { |
| 523 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 524 BrowserThread::PostTask( |
| 525 BrowserThread::UI, FROM_HERE, |
| 524 base::Bind(&TracingControllerImpl::OnStopTracingAcked, | 526 base::Bind(&TracingControllerImpl::OnStopTracingAcked, |
| 525 base::Unretained(this), | 527 base::Unretained(this), |
| 526 make_scoped_refptr(trace_message_filter), | 528 base::RetainedRef(trace_message_filter), |
| 527 std::vector<std::string>())); | 529 std::vector<std::string>())); |
| 528 } | 530 } |
| 529 } | 531 } |
| 530 if (pending_trace_log_status_ack_count_ > 0) { | 532 if (pending_trace_log_status_ack_count_ > 0) { |
| 531 TraceMessageFilterSet::const_iterator it = | 533 TraceMessageFilterSet::const_iterator it = |
| 532 pending_trace_log_status_filters_.find(trace_message_filter); | 534 pending_trace_log_status_filters_.find(trace_message_filter); |
| 533 if (it != pending_trace_log_status_filters_.end()) { | 535 if (it != pending_trace_log_status_filters_.end()) { |
| 534 BrowserThread::PostTask( | 536 BrowserThread::PostTask( |
| 535 BrowserThread::UI, FROM_HERE, | 537 BrowserThread::UI, FROM_HERE, |
| 536 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 538 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 537 base::Unretained(this), | 539 base::Unretained(this), |
| 538 make_scoped_refptr(trace_message_filter), | 540 base::RetainedRef(trace_message_filter), |
| 539 base::trace_event::TraceLogStatus())); | 541 base::trace_event::TraceLogStatus())); |
| 540 } | 542 } |
| 541 } | 543 } |
| 542 if (pending_memory_dump_ack_count_ > 0) { | 544 if (pending_memory_dump_ack_count_ > 0) { |
| 543 TraceMessageFilterSet::const_iterator it = | 545 TraceMessageFilterSet::const_iterator it = |
| 544 pending_memory_dump_filters_.find(trace_message_filter); | 546 pending_memory_dump_filters_.find(trace_message_filter); |
| 545 if (it != pending_memory_dump_filters_.end()) { | 547 if (it != pending_memory_dump_filters_.end()) { |
| 546 BrowserThread::PostTask( | 548 BrowserThread::PostTask( |
| 547 BrowserThread::UI, FROM_HERE, | 549 BrowserThread::UI, FROM_HERE, |
| 548 base::Bind(&TracingControllerImpl::OnProcessMemoryDumpResponse, | 550 base::Bind(&TracingControllerImpl::OnProcessMemoryDumpResponse, |
| 549 base::Unretained(this), | 551 base::Unretained(this), |
| 550 make_scoped_refptr(trace_message_filter), | 552 base::RetainedRef(trace_message_filter), |
| 551 pending_memory_dump_guid_, false /* success */)); | 553 pending_memory_dump_guid_, false /* success */)); |
| 552 } | 554 } |
| 553 } | 555 } |
| 554 trace_message_filters_.erase(trace_message_filter); | 556 trace_message_filters_.erase(trace_message_filter); |
| 555 } | 557 } |
| 556 | 558 |
| 557 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { | 559 void TracingControllerImpl::AddTracingAgent(const std::string& agent_name) { |
| 558 #if defined(OS_CHROMEOS) | 560 #if defined(OS_CHROMEOS) |
| 559 auto debug_daemon = | 561 auto debug_daemon = |
| 560 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 562 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 if (--pending_start_tracing_ack_count_ == 0) { | 600 if (--pending_start_tracing_ack_count_ == 0) { |
| 599 start_tracing_timer_.Stop(); | 601 start_tracing_timer_.Stop(); |
| 600 OnAllTracingAgentsStarted(); | 602 OnAllTracingAgentsStarted(); |
| 601 } | 603 } |
| 602 } | 604 } |
| 603 | 605 |
| 604 void TracingControllerImpl::OnStopTracingAcked( | 606 void TracingControllerImpl::OnStopTracingAcked( |
| 605 TraceMessageFilter* trace_message_filter, | 607 TraceMessageFilter* trace_message_filter, |
| 606 const std::vector<std::string>& known_category_groups) { | 608 const std::vector<std::string>& known_category_groups) { |
| 607 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 609 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 608 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 610 BrowserThread::PostTask( |
| 609 base::Bind(&TracingControllerImpl::OnStopTracingAcked, | 611 BrowserThread::UI, FROM_HERE, |
| 610 base::Unretained(this), | 612 base::Bind( |
| 611 make_scoped_refptr(trace_message_filter), | 613 &TracingControllerImpl::OnStopTracingAcked, base::Unretained(this), |
| 612 known_category_groups)); | 614 base::RetainedRef(trace_message_filter), known_category_groups)); |
| 613 return; | 615 return; |
| 614 } | 616 } |
| 615 | 617 |
| 616 // Merge known_category_groups with known_category_groups_ | 618 // Merge known_category_groups with known_category_groups_ |
| 617 known_category_groups_.insert(known_category_groups.begin(), | 619 known_category_groups_.insert(known_category_groups.begin(), |
| 618 known_category_groups.end()); | 620 known_category_groups.end()); |
| 619 | 621 |
| 620 if (pending_stop_tracing_ack_count_ == 0) | 622 if (pending_stop_tracing_ack_count_ == 0) |
| 621 return; | 623 return; |
| 622 | 624 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } | 715 } |
| 714 | 716 |
| 715 void TracingControllerImpl::OnTraceLogStatusReply( | 717 void TracingControllerImpl::OnTraceLogStatusReply( |
| 716 TraceMessageFilter* trace_message_filter, | 718 TraceMessageFilter* trace_message_filter, |
| 717 const base::trace_event::TraceLogStatus& status) { | 719 const base::trace_event::TraceLogStatus& status) { |
| 718 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 720 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 719 BrowserThread::PostTask( | 721 BrowserThread::PostTask( |
| 720 BrowserThread::UI, FROM_HERE, | 722 BrowserThread::UI, FROM_HERE, |
| 721 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, | 723 base::Bind(&TracingControllerImpl::OnTraceLogStatusReply, |
| 722 base::Unretained(this), | 724 base::Unretained(this), |
| 723 make_scoped_refptr(trace_message_filter), status)); | 725 base::RetainedRef(trace_message_filter), status)); |
| 724 return; | 726 return; |
| 725 } | 727 } |
| 726 | 728 |
| 727 if (pending_trace_log_status_ack_count_ == 0) | 729 if (pending_trace_log_status_ack_count_ == 0) |
| 728 return; | 730 return; |
| 729 | 731 |
| 730 if (trace_message_filter && | 732 if (trace_message_filter && |
| 731 !pending_trace_log_status_filters_.erase(trace_message_filter)) { | 733 !pending_trace_log_status_filters_.erase(trace_message_filter)) { |
| 732 // The response from the specified message filter has already been received. | 734 // The response from the specified message filter has already been received. |
| 733 return; | 735 return; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 | 956 |
| 955 void TracingControllerImpl::OnProcessMemoryDumpResponse( | 957 void TracingControllerImpl::OnProcessMemoryDumpResponse( |
| 956 TraceMessageFilter* trace_message_filter, | 958 TraceMessageFilter* trace_message_filter, |
| 957 uint64_t dump_guid, | 959 uint64_t dump_guid, |
| 958 bool success) { | 960 bool success) { |
| 959 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 961 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 960 BrowserThread::PostTask( | 962 BrowserThread::PostTask( |
| 961 BrowserThread::UI, FROM_HERE, | 963 BrowserThread::UI, FROM_HERE, |
| 962 base::Bind(&TracingControllerImpl::OnProcessMemoryDumpResponse, | 964 base::Bind(&TracingControllerImpl::OnProcessMemoryDumpResponse, |
| 963 base::Unretained(this), | 965 base::Unretained(this), |
| 964 make_scoped_refptr(trace_message_filter), dump_guid, | 966 base::RetainedRef(trace_message_filter), dump_guid, |
| 965 success)); | 967 success)); |
| 966 return; | 968 return; |
| 967 } | 969 } |
| 968 | 970 |
| 969 TraceMessageFilterSet::iterator it = | 971 TraceMessageFilterSet::iterator it = |
| 970 pending_memory_dump_filters_.find(trace_message_filter); | 972 pending_memory_dump_filters_.find(trace_message_filter); |
| 971 | 973 |
| 972 if (pending_memory_dump_guid_ != dump_guid || | 974 if (pending_memory_dump_guid_ != dump_guid || |
| 973 it == pending_memory_dump_filters_.end()) { | 975 it == pending_memory_dump_filters_.end()) { |
| 974 DLOG(WARNING) << "Received unexpected memory dump response: " << dump_guid; | 976 DLOG(WARNING) << "Received unexpected memory dump response: " << dump_guid; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1005 const bool global_success = failed_memory_dump_count_ == 0; | 1007 const bool global_success = failed_memory_dump_count_ == 0; |
| 1006 if (!pending_memory_dump_callback_.is_null()) { | 1008 if (!pending_memory_dump_callback_.is_null()) { |
| 1007 pending_memory_dump_callback_.Run(pending_memory_dump_guid_, | 1009 pending_memory_dump_callback_.Run(pending_memory_dump_guid_, |
| 1008 global_success); | 1010 global_success); |
| 1009 pending_memory_dump_callback_.Reset(); | 1011 pending_memory_dump_callback_.Reset(); |
| 1010 } | 1012 } |
| 1011 pending_memory_dump_guid_ = 0; | 1013 pending_memory_dump_guid_ = 0; |
| 1012 } | 1014 } |
| 1013 | 1015 |
| 1014 } // namespace content | 1016 } // namespace content |
| OLD | NEW |