Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/chrome_watcher/wait_chain_util_win.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/strings/stringprintf.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // Helper deleter to hold a HWCT into a unique_ptr. | |
| 15 struct WaitChainSessionDeleter { | |
| 16 using pointer = HWCT; | |
| 17 void operator()(HWCT session_handle) { | |
| 18 ::CloseThreadWaitChainSession(session_handle); | |
| 19 } | |
| 20 }; | |
| 21 | |
| 22 const wchar_t* WctObjectTypeToString(WCT_OBJECT_TYPE type) { | |
| 23 switch (type) { | |
| 24 case WctCriticalSectionType: | |
| 25 return L"CriticalSection"; | |
| 26 case WctSendMessageType: | |
| 27 return L"SendMessage"; | |
| 28 case WctMutexType: | |
| 29 return L"Mutex"; | |
| 30 case WctAlpcType: | |
| 31 return L"Alpc"; | |
| 32 case WctComType: | |
| 33 return L"Com"; | |
| 34 case WctThreadWaitType: | |
| 35 return L"ThreadWait"; | |
| 36 case WctProcessWaitType: | |
| 37 return L"ProcessWait"; | |
| 38 case WctThreadType: | |
| 39 return L"Thread"; | |
| 40 case WctComActivationType: | |
| 41 return L"ComActivation"; | |
| 42 case WctUnknownType: | |
| 43 return L"Unknown"; | |
| 44 default: | |
| 45 NOTREACHED(); | |
| 46 return L""; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 const wchar_t* WctObjectStatusToString(WCT_OBJECT_STATUS status) { | |
| 51 switch (status) { | |
| 52 case WctStatusNoAccess: | |
| 53 return L"NoAccess"; | |
| 54 case WctStatusRunning: | |
| 55 return L"Running"; | |
| 56 case WctStatusBlocked: | |
| 57 return L"Blocked"; | |
| 58 case WctStatusPidOnly: | |
| 59 return L"PidOnly"; | |
| 60 case WctStatusPidOnlyRpcss: | |
| 61 return L"PidOnlyRpcss"; | |
| 62 case WctStatusOwned: | |
| 63 return L"Owned"; | |
| 64 case WctStatusNotOwned: | |
| 65 return L"NotOwned"; | |
| 66 case WctStatusAbandoned: | |
| 67 return L"Abandoned"; | |
| 68 case WctStatusUnknown: | |
| 69 return L"Unknown"; | |
| 70 case WctStatusError: | |
| 71 return L"Error"; | |
| 72 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
| |
| 73 NOTREACHED(); | |
| 74 return L""; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace | |
| 79 | |
| 80 bool GetThreadWaitChain(DWORD thread_id, | |
| 81 std::vector<WAITCHAIN_NODE_INFO>* wait_chain, | |
| 82 bool* is_deadlock) { | |
| 83 DCHECK(wait_chain); | |
| 84 DCHECK(is_deadlock); | |
| 85 | |
| 86 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.
| |
| 87 ::OpenThreadWaitChainSession(0, nullptr)); | |
| 88 if (!session_handle) { | |
| 89 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
| |
| 90 } | |
| 91 | |
| 92 DWORD nb_nodes = WCT_MAX_NODE_COUNT; | |
| 93 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.
| |
| 94 BOOL is_cycle; | |
| 95 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.
| |
| 96 thread_id, &nb_nodes, nodes, &is_cycle)) | |
| 97 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
| |
| 98 | |
| 99 *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.
| |
| 100 wait_chain->insert(wait_chain->end(), &nodes[0], &nodes[nb_nodes]); | |
| 101 | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 std::wstring WaitChainNodeToString(const WAITCHAIN_NODE_INFO& node) { | |
| 106 if (node.ObjectType == WctThreadType) { | |
| 107 return base::StringPrintf(L"Thread #%d with status %ls", | |
| 108 node.ThreadObject.ThreadId, | |
| 109 WctObjectStatusToString(node.ObjectStatus)); | |
| 110 } else { | |
| 111 return base::StringPrintf(L"Lock of type %ls with status %ls", | |
| 112 WctObjectTypeToString(node.ObjectType), | |
| 113 WctObjectStatusToString(node.ObjectStatus)); | |
| 114 } | |
| 115 } | |
| OLD | NEW |