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

Side by Side Diff: src/inspector/v8-debugger.cc

Issue 2826183002: [inspector] collect old async stack traces 20% faster (Closed)
Patch Set: rebased Created 3 years, 8 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
« no previous file with comments | « src/inspector/v8-debugger.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-debugger.h" 5 #include "src/inspector/v8-debugger.h"
6 6
7 #include "src/inspector/debugger-script.h" 7 #include "src/inspector/debugger-script.h"
8 #include "src/inspector/inspected-context.h" 8 #include "src/inspector/inspected-context.h"
9 #include "src/inspector/protocol/Protocol.h" 9 #include "src/inspector/protocol/Protocol.h"
10 #include "src/inspector/script-breakpoint.h" 10 #include "src/inspector/script-breakpoint.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 func->GetScriptColumnNumber()); 126 func->GetScriptColumnNumber());
127 } 127 }
128 v8::Local<v8::debug::Script> script; 128 v8::Local<v8::debug::Script> script;
129 if (!generatorObject->Script().ToLocal(&script)) 129 if (!generatorObject->Script().ToLocal(&script))
130 return v8::MaybeLocal<v8::Object>(); 130 return v8::MaybeLocal<v8::Object>();
131 v8::debug::Location suspendedLocation = generatorObject->SuspendedLocation(); 131 v8::debug::Location suspendedLocation = generatorObject->SuspendedLocation();
132 return buildLocation(context, script->Id(), suspendedLocation.GetLineNumber(), 132 return buildLocation(context, script->Id(), suspendedLocation.GetLineNumber(),
133 suspendedLocation.GetColumnNumber()); 133 suspendedLocation.GetColumnNumber());
134 } 134 }
135 135
136 template <typename Map>
137 void cleanupExpiredWeakPointers(Map& map) {
138 for (auto it = map.begin(); it != map.end();) {
139 if (it->second.expired()) {
140 it = map.erase(it);
141 } else {
142 ++it;
143 }
144 }
145 }
146
136 } // namespace 147 } // namespace
137 148
138 static bool inLiveEditScope = false; 149 static bool inLiveEditScope = false;
139 150
140 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( 151 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod(
141 const char* functionName, int argc, v8::Local<v8::Value> argv[], 152 const char* functionName, int argc, v8::Local<v8::Value> argv[],
142 bool catchExceptions) { 153 bool catchExceptions) {
143 v8::MicrotasksScope microtasks(m_isolate, 154 v8::MicrotasksScope microtasks(m_isolate,
144 v8::MicrotasksScope::kDoNotRunMicrotasks); 155 v8::MicrotasksScope::kDoNotRunMicrotasks);
145 DCHECK(m_isolate->InContext()); 156 DCHECK(m_isolate->InContext());
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 } 1021 }
1011 1022
1012 void V8Debugger::collectOldAsyncStacksIfNeeded() { 1023 void V8Debugger::collectOldAsyncStacksIfNeeded() {
1013 if (m_asyncStacksCount <= m_maxAsyncCallStacks) return; 1024 if (m_asyncStacksCount <= m_maxAsyncCallStacks) return;
1014 int halfOfLimitRoundedUp = 1025 int halfOfLimitRoundedUp =
1015 m_maxAsyncCallStacks / 2 + m_maxAsyncCallStacks % 2; 1026 m_maxAsyncCallStacks / 2 + m_maxAsyncCallStacks % 2;
1016 while (m_asyncStacksCount > halfOfLimitRoundedUp) { 1027 while (m_asyncStacksCount > halfOfLimitRoundedUp) {
1017 m_allAsyncStacks.pop_front(); 1028 m_allAsyncStacks.pop_front();
1018 --m_asyncStacksCount; 1029 --m_asyncStacksCount;
1019 } 1030 }
1020 removeOldAsyncTasks(m_asyncTaskStacks); 1031 cleanupExpiredWeakPointers(m_asyncTaskStacks);
1021 removeOldAsyncTasks(m_asyncTaskCreationStacks); 1032 cleanupExpiredWeakPointers(m_asyncTaskCreationStacks);
1022 protocol::HashSet<void*> recurringLeft; 1033 for (auto it = m_recurringTasks.begin(); it != m_recurringTasks.end();) {
1023 for (auto task : m_recurringTasks) { 1034 if (m_asyncTaskStacks.find(*it) == m_asyncTaskStacks.end()) {
1024 if (m_asyncTaskStacks.find(task) == m_asyncTaskStacks.end()) continue; 1035 it = m_recurringTasks.erase(it);
1025 recurringLeft.insert(task); 1036 } else {
1037 ++it;
1038 }
1026 } 1039 }
1027 m_recurringTasks.swap(recurringLeft); 1040 for (auto it = m_parentTask.begin(); it != m_parentTask.end();) {
1028 protocol::HashMap<void*, void*> parentLeft; 1041 if (m_asyncTaskCreationStacks.find(it->second) ==
1029 for (auto it : m_parentTask) {
1030 if (m_asyncTaskCreationStacks.find(it.second) ==
1031 m_asyncTaskCreationStacks.end()) { 1042 m_asyncTaskCreationStacks.end()) {
1032 continue; 1043 it = m_parentTask.erase(it);
1044 } else {
1045 ++it;
1033 } 1046 }
1034 parentLeft.insert(it);
1035 } 1047 }
1036 m_parentTask.swap(parentLeft); 1048 cleanupExpiredWeakPointers(m_framesCache);
1037 std::map<int, std::weak_ptr<StackFrame>> framesCache;
1038 for (auto it : m_framesCache) {
1039 if (!it.second.expired()) framesCache.insert(it);
1040 }
1041 m_framesCache.swap(framesCache);
1042 }
1043
1044 void V8Debugger::removeOldAsyncTasks(AsyncTaskToStackTrace& map) {
1045 AsyncTaskToStackTrace cleanCopy;
1046 for (auto it : map) {
1047 if (!it.second.expired()) cleanCopy.insert(it);
1048 }
1049 map.swap(cleanCopy);
1050 } 1049 }
1051 1050
1052 std::shared_ptr<StackFrame> V8Debugger::symbolize( 1051 std::shared_ptr<StackFrame> V8Debugger::symbolize(
1053 v8::Local<v8::StackFrame> v8Frame) { 1052 v8::Local<v8::StackFrame> v8Frame) {
1054 auto it = m_framesCache.end(); 1053 auto it = m_framesCache.end();
1055 int frameId = 0; 1054 int frameId = 0;
1056 if (m_maxAsyncCallStackDepth) { 1055 if (m_maxAsyncCallStackDepth) {
1057 frameId = v8::debug::GetStackFrameId(v8Frame); 1056 frameId = v8::debug::GetStackFrameId(v8Frame);
1058 it = m_framesCache.find(frameId); 1057 it = m_framesCache.find(frameId);
1059 } 1058 }
(...skipping 18 matching lines...) Expand all
1078 fprintf(stdout, "Async stacks count: %d\n", m_asyncStacksCount); 1077 fprintf(stdout, "Async stacks count: %d\n", m_asyncStacksCount);
1079 fprintf(stdout, "Scheduled async tasks: %zu\n", m_asyncTaskStacks.size()); 1078 fprintf(stdout, "Scheduled async tasks: %zu\n", m_asyncTaskStacks.size());
1080 fprintf(stdout, "Created async tasks: %zu\n", 1079 fprintf(stdout, "Created async tasks: %zu\n",
1081 m_asyncTaskCreationStacks.size()); 1080 m_asyncTaskCreationStacks.size());
1082 fprintf(stdout, "Async tasks with parent: %zu\n", m_parentTask.size()); 1081 fprintf(stdout, "Async tasks with parent: %zu\n", m_parentTask.size());
1083 fprintf(stdout, "Recurring async tasks: %zu\n", m_recurringTasks.size()); 1082 fprintf(stdout, "Recurring async tasks: %zu\n", m_recurringTasks.size());
1084 fprintf(stdout, "\n"); 1083 fprintf(stdout, "\n");
1085 } 1084 }
1086 1085
1087 } // namespace v8_inspector 1086 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-debugger.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698