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