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

Unified Diff: chrome/chrome_watcher/wait_chain_util_win.cc

Issue 1834463002: Identify the hung thread using the Wait Chain Traversal API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/chrome_watcher/wait_chain_util_win.cc
diff --git a/chrome/chrome_watcher/wait_chain_util_win.cc b/chrome/chrome_watcher/wait_chain_util_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..22ef56f138ac20da534d27f1529907297ceb2f27
--- /dev/null
+++ b/chrome/chrome_watcher/wait_chain_util_win.cc
@@ -0,0 +1,115 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/chrome_watcher/wait_chain_util_win.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+
+namespace {
+
+// Helper deleter to hold a HWCT into a unique_ptr.
+struct WaitChainSessionDeleter {
+ using pointer = HWCT;
+ void operator()(HWCT session_handle) {
+ ::CloseThreadWaitChainSession(session_handle);
+ }
+};
+
+const wchar_t* WctObjectTypeToString(WCT_OBJECT_TYPE type) {
+ switch (type) {
+ case WctCriticalSectionType:
+ return L"CriticalSection";
+ case WctSendMessageType:
+ return L"SendMessage";
+ case WctMutexType:
+ return L"Mutex";
+ case WctAlpcType:
+ return L"Alpc";
+ case WctComType:
+ return L"Com";
+ case WctThreadWaitType:
+ return L"ThreadWait";
+ case WctProcessWaitType:
+ return L"ProcessWait";
+ case WctThreadType:
+ return L"Thread";
+ case WctComActivationType:
+ return L"ComActivation";
+ case WctUnknownType:
+ return L"Unknown";
+ default:
+ NOTREACHED();
+ return L"";
+ }
+}
+
+const wchar_t* WctObjectStatusToString(WCT_OBJECT_STATUS status) {
+ switch (status) {
+ case WctStatusNoAccess:
+ return L"NoAccess";
+ case WctStatusRunning:
+ return L"Running";
+ case WctStatusBlocked:
+ return L"Blocked";
+ case WctStatusPidOnly:
+ return L"PidOnly";
+ case WctStatusPidOnlyRpcss:
+ return L"PidOnlyRpcss";
+ case WctStatusOwned:
+ return L"Owned";
+ case WctStatusNotOwned:
+ return L"NotOwned";
+ case WctStatusAbandoned:
+ return L"Abandoned";
+ case WctStatusUnknown:
+ return L"Unknown";
+ case WctStatusError:
+ return L"Error";
+ default:
Sigurður Ásgeirsson 2016/03/24 19:30:18 I seem to remember there's a way to get compile-ti
Patrick Monette 2016/03/24 23:21:03 I'm not sure I understand your suggestion. The enu
+ NOTREACHED();
+ return L"";
+ }
+}
+
+} // namespace
+
+bool GetThreadWaitChain(DWORD thread_id,
+ std::vector<WAITCHAIN_NODE_INFO>* wait_chain,
+ bool* is_deadlock) {
+ DCHECK(wait_chain);
+ DCHECK(is_deadlock);
+
+ std::unique_ptr<HWCT, WaitChainSessionDeleter> session_handle(
Sigurður Ásgeirsson 2016/03/24 19:30:18 nit: more readable to typedef a ScopedWaitChainSes
manzagop (departed) 2016/03/24 19:36:36 Nit: comment to mention it's a synchronous session
Patrick Monette 2016/03/24 23:21:03 Done.
Patrick Monette 2016/03/24 23:21:03 I like it. Done.
+ ::OpenThreadWaitChainSession(0, nullptr));
+ if (!session_handle) {
+ return false;
manzagop (departed) 2016/03/24 19:36:36 Should you log the error message?
Patrick Monette 2016/03/24 23:21:03 Done.
Sigurður Ásgeirsson 2016/03/29 16:57:32 Not to be too contrary, but verbose logging is gen
+ }
+
+ DWORD nb_nodes = WCT_MAX_NODE_COUNT;
+ WAITCHAIN_NODE_INFO nodes[WCT_MAX_NODE_COUNT];
manzagop (departed) 2016/03/24 19:36:36 I guess you could put it directly in the vector?
Patrick Monette 2016/03/24 23:21:03 Done.
+ BOOL is_cycle;
+ if (!::GetThreadWaitChain(session_handle.get(), NULL, WCTP_GETINFO_ALL_FLAGS,
manzagop (departed) 2016/03/24 19:36:36 We should double check this is the right flag.
Patrick Monette 2016/03/24 23:21:03 I removed it. They aren't doing anything.
+ thread_id, &nb_nodes, nodes, &is_cycle))
+ return false;
manzagop (departed) 2016/03/24 19:36:36 Again, log an error message? I'm guessing we shoul
Patrick Monette 2016/03/24 23:21:03 Probably not but logging the error message is a go
+
+ *is_deadlock = !!is_cycle;
Sigurður Ásgeirsson 2016/03/24 19:30:18 we use the !! notion for coercing to bool?
Patrick Monette 2016/03/24 23:21:03 Hem.. yeah I don't think so. What should I then?
Sigurður Ásgeirsson 2016/03/29 16:57:32 I dunno.
+ wait_chain->insert(wait_chain->end(), &nodes[0], &nodes[nb_nodes]);
+
+ return true;
+}
+
+std::wstring WaitChainNodeToString(const WAITCHAIN_NODE_INFO& node) {
+ if (node.ObjectType == WctThreadType) {
+ return base::StringPrintf(L"Thread #%d with status %ls",
+ node.ThreadObject.ThreadId,
+ WctObjectStatusToString(node.ObjectStatus));
+ } else {
+ return base::StringPrintf(L"Lock of type %ls with status %ls",
+ WctObjectTypeToString(node.ObjectType),
+ WctObjectStatusToString(node.ObjectStatus));
+ }
+}
« chrome/chrome_watcher/wait_chain_util_win.h ('K') | « chrome/chrome_watcher/wait_chain_util_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698