Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 2067793004: [memory-infra] Add support for queueing memory dump requests in the browser process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 void TracingControllerImpl::RequestGlobalMemoryDump( 913 void TracingControllerImpl::RequestGlobalMemoryDump(
914 const base::trace_event::MemoryDumpRequestArgs& args, 914 const base::trace_event::MemoryDumpRequestArgs& args,
915 const base::trace_event::MemoryDumpCallback& callback) { 915 const base::trace_event::MemoryDumpCallback& callback) {
916 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 916 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
917 BrowserThread::PostTask( 917 BrowserThread::PostTask(
918 BrowserThread::UI, FROM_HERE, 918 BrowserThread::UI, FROM_HERE,
919 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump, 919 base::Bind(&TracingControllerImpl::RequestGlobalMemoryDump,
920 base::Unretained(this), args, callback)); 920 base::Unretained(this), args, callback));
921 return; 921 return;
922 } 922 }
923 // Abort if another dump is already in progress. 923
924 // Enqueue request if another dump is already in progress.
924 if (pending_memory_dump_guid_) { 925 if (pending_memory_dump_guid_) {
Primiano Tucci (use gerrit) 2016/06/16 08:37:23 I think here I'd just if (!queued_memory_dump_requ
petrcermak 2016/06/16 12:08:29 Done.
925 VLOG(1) << base::trace_event::MemoryDumpManager::kLogPrefix 926 enqueued_memory_dump_requests_.emplace(args, callback);
ssid 2016/06/15 17:20:51 For the case of only periodic dumps, if a heavy du
Primiano Tucci (use gerrit) 2016/06/16 08:37:23 So, I agree with ssid that this can cause some sto
petrcermak 2016/06/16 12:08:31 I think that the following would be the best appro
ssid 2016/06/16 23:12:03 If there is a sequence of events like this when a
petrcermak 2016/06/17 08:36:44 I'm fine with that, BUT that would require re-arch
ssid 2016/06/17 18:43:45 Ah I see, then I am fine with this, if that is goi
926 << " (" << args.dump_guid << ") aborted because another dump ("
927 << pending_memory_dump_guid_ << ") is in progress";
928 if (!callback.is_null())
929 callback.Run(args.dump_guid, false /* success */);
930 return; 927 return;
931 } 928 }
932 929
930 PerformGlobalMemoryDump(args, callback);
931 }
932
933 void TracingControllerImpl::PerformGlobalMemoryDump(
934 const base::trace_event::MemoryDumpRequestArgs& args,
Primiano Tucci (use gerrit) 2016/06/16 08:37:23 Does this require any arg? Aren't this the front()
petrcermak 2016/06/16 12:08:29 They were not, but I changed it, so done.
935 const base::trace_event::MemoryDumpCallback& callback) {
936 DCHECK_CURRENTLY_ON(BrowserThread::UI);
937
933 // Count myself (local trace) in pending_memory_dump_ack_count_, acked by 938 // Count myself (local trace) in pending_memory_dump_ack_count_, acked by
934 // OnBrowserProcessMemoryDumpDone(). 939 // OnBrowserProcessMemoryDumpDone().
935 pending_memory_dump_ack_count_ = trace_message_filters_.size() + 1; 940 pending_memory_dump_ack_count_ = trace_message_filters_.size() + 1;
936 pending_memory_dump_filters_.clear(); 941 pending_memory_dump_filters_.clear();
937 pending_memory_dump_guid_ = args.dump_guid; 942 pending_memory_dump_guid_ = args.dump_guid;
938 pending_memory_dump_callback_ = callback; 943 pending_memory_dump_callback_ = callback;
939 failed_memory_dump_count_ = 0; 944 failed_memory_dump_count_ = 0;
940 945
941 MemoryDumpManagerDelegate::CreateProcessDump( 946 MemoryDumpManagerDelegate::CreateProcessDump(
942 args, base::Bind(&TracingControllerImpl::OnBrowserProcessMemoryDumpDone, 947 args, base::Bind(&TracingControllerImpl::OnBrowserProcessMemoryDumpDone,
943 base::Unretained(this))); 948 base::Unretained(this)));
944 949
945 // If there are no child processes we are just done. 950 // If there are no child processes we are just done.
946 if (pending_memory_dump_ack_count_ == 1) 951 if (pending_memory_dump_ack_count_ == 1)
947 return; 952 return;
948 953
949 pending_memory_dump_filters_ = trace_message_filters_; 954 pending_memory_dump_filters_ = trace_message_filters_;
950 955
951 for (const scoped_refptr<TraceMessageFilter>& tmf : trace_message_filters_) 956 for (const scoped_refptr<TraceMessageFilter>& tmf : trace_message_filters_)
952 tmf->SendProcessMemoryDumpRequest(args); 957 tmf->SendProcessMemoryDumpRequest(args);
953 } 958 }
954 959
960 TracingControllerImpl::GlobalMemoryDumpRequest::GlobalMemoryDumpRequest(
961 const base::trace_event::MemoryDumpRequestArgs& args,
962 const base::trace_event::MemoryDumpCallback& callback)
963 : args(args), callback(callback) {}
964
965 TracingControllerImpl::GlobalMemoryDumpRequest::~GlobalMemoryDumpRequest() {}
966
955 uint64_t TracingControllerImpl::GetTracingProcessId() const { 967 uint64_t TracingControllerImpl::GetTracingProcessId() const {
956 return ChildProcessHost::kBrowserTracingProcessId; 968 return ChildProcessHost::kBrowserTracingProcessId;
957 } 969 }
958 970
959 void TracingControllerImpl::AddTraceMessageFilterObserver( 971 void TracingControllerImpl::AddTraceMessageFilterObserver(
960 TraceMessageFilterObserver* observer) { 972 TraceMessageFilterObserver* observer) {
961 DCHECK_CURRENTLY_ON(BrowserThread::UI); 973 DCHECK_CURRENTLY_ON(BrowserThread::UI);
962 trace_message_filter_observers_.AddObserver(observer); 974 trace_message_filter_observers_.AddObserver(observer);
963 975
964 for (auto& filter : trace_message_filters_) 976 for (auto& filter : trace_message_filters_)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 return; 1038 return;
1027 1039
1028 DCHECK_NE(0u, pending_memory_dump_guid_); 1040 DCHECK_NE(0u, pending_memory_dump_guid_);
1029 const bool global_success = failed_memory_dump_count_ == 0; 1041 const bool global_success = failed_memory_dump_count_ == 0;
1030 if (!pending_memory_dump_callback_.is_null()) { 1042 if (!pending_memory_dump_callback_.is_null()) {
1031 pending_memory_dump_callback_.Run(pending_memory_dump_guid_, 1043 pending_memory_dump_callback_.Run(pending_memory_dump_guid_,
1032 global_success); 1044 global_success);
1033 pending_memory_dump_callback_.Reset(); 1045 pending_memory_dump_callback_.Reset();
1034 } 1046 }
1035 pending_memory_dump_guid_ = 0; 1047 pending_memory_dump_guid_ = 0;
1048
1049 // Immediately perform another dump if it's been enqueued.
1050 if (!enqueued_memory_dump_requests_.empty()) {
petrcermak 2016/06/15 16:19:11 Maybe it would be better to post a task instead?
Primiano Tucci (use gerrit) 2016/06/16 08:37:23 Yeah that will avoid thinking about weird re-entra
petrcermak 2016/06/16 12:08:31 Done.
1051 const auto args = enqueued_memory_dump_requests_.front().args;
1052 const auto callback = enqueued_memory_dump_requests_.front().callback;
1053 enqueued_memory_dump_requests_.pop();
1054 PerformGlobalMemoryDump(args, callback);
1055 }
1036 } 1056 }
1037 1057
1038 } // namespace content 1058 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698