Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | 4 |
| 5 #include "base/profiler/stack_sampling_profiler.h" | 5 #include "base/profiler/stack_sampling_profiler.h" |
| 6 | 6 |
| 7 #include <dbghelp.h> | 7 #include <dbghelp.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <windows.h> | 10 #include <windows.h> |
|
Peter Kasting
2015/03/26 04:29:08
I would place this with dbghelp.h and then put a b
Mike Wittman
2015/03/27 22:42:04
Done.
| |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/win/pe_image.h" | 14 #include "base/win/pe_image.h" |
| 15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class NativeStackSamplerWin : public StackSamplingProfiler::NativeStackSampler { | 21 class NativeStackSamplerWin : public StackSamplingProfiler::NativeStackSampler { |
| 22 public: | 22 public: |
| 23 explicit NativeStackSamplerWin(win::ScopedHandle thread_handle); | 23 explicit NativeStackSamplerWin(win::ScopedHandle thread_handle); |
| 24 ~NativeStackSamplerWin() override; | 24 ~NativeStackSamplerWin() override; |
| 25 | 25 |
| 26 // StackSamplingProfiler::NativeStackSampler: | 26 // StackSamplingProfiler::NativeStackSampler: |
| 27 void ProfileRecordingStarting( | 27 void ProfileRecordingStarting( |
| 28 StackSamplingProfiler::Profile* profile) override; | 28 StackSamplingProfiler::Profile* profile) override; |
| 29 void RecordStackSample(StackSamplingProfiler::Sample* sample) override; | 29 void RecordStackSample(StackSamplingProfiler::Sample* sample) override; |
| 30 void ProfileRecordingStopped() override; | 30 void ProfileRecordingStopped() override; |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 static bool GetModuleInfo(HMODULE module, | 33 static bool GetModuleInfo(HMODULE module, |
|
Peter Kasting
2015/03/26 04:29:09
These functions need descriptive comments.
Mike Wittman
2015/03/27 22:42:04
Done.
| |
| 34 StackSamplingProfiler::Module* module_info); | 34 StackSamplingProfiler::Module* module_info); |
| 35 | 35 |
| 36 void CopyToSample(const void* const instruction_pointers[], | 36 void CopyToSample(const void* const instruction_pointers[], |
|
Peter Kasting
2015/03/26 04:29:08
You use a lot of arrays in this file, which is a b
Mike Wittman
2015/03/27 22:42:05
Yes, the reason is that we can't do any memory all
Peter Kasting
2015/03/27 23:44:46
Ahhh... that's a good reason (and a scary one; the
Mike Wittman
2015/03/30 21:01:13
Done.
| |
| 37 const HMODULE modules[], | 37 const HMODULE modules[], |
| 38 int stack_depth, | 38 int stack_depth, |
| 39 StackSamplingProfiler::Sample* sample, | 39 StackSamplingProfiler::Sample* sample, |
| 40 std::vector<StackSamplingProfiler::Module>* module_infos); | 40 std::vector<StackSamplingProfiler::Module>* module_infos); |
| 41 | 41 |
| 42 win::ScopedHandle thread_handle_; | 42 win::ScopedHandle thread_handle_; |
| 43 // Weak. Points to the profile being recorded between | 43 // Weak. Points to the profile being recorded between |
| 44 // ProfileRecordingStarting() and ProfileRecordingStopped(). | 44 // ProfileRecordingStarting() and ProfileRecordingStopped(). |
| 45 StackSamplingProfiler::Profile* current_profile_; | 45 StackSamplingProfiler::Profile* current_profile_; |
| 46 // Maps a module to the module's index within current_profile_->modules. | 46 // Maps a module to the module's index within current_profile_->modules. |
| 47 std::map<HMODULE, int> profile_module_index_; | 47 std::map<HMODULE, int> profile_module_index_; |
|
Peter Kasting
2015/03/26 04:29:08
Note that if you change Frame::module_index to a s
Mike Wittman
2015/03/27 22:42:04
Done.
| |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerWin); | 49 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerWin); |
| 50 }; | 50 }; |
|
Peter Kasting
2015/03/26 04:29:08
If possible, try to put the declaration of this cl
Mike Wittman
2015/03/27 22:42:05
Done.
| |
| 51 | 51 |
| 52 // Walk the stack represented by |context| from the current frame downwards, | 52 // Walk the stack represented by |context| from the current frame downwards, |
| 53 // recording the instruction pointers for each frame in |instruction_pointers|. | 53 // recording the instruction pointers for each frame in |instruction_pointers|. |
| 54 int RecordStack(CONTEXT* context, | 54 int RecordStack(CONTEXT* context, |
| 55 int max_stack_size, | 55 int max_stack_size, |
| 56 const void* instruction_pointers[], | 56 const void* instruction_pointers[], |
| 57 bool* last_frame_is_unknown_function) { | 57 bool* last_frame_is_unknown_function) { |
| 58 #ifdef _WIN64 | 58 #ifdef _WIN64 |
| 59 *last_frame_is_unknown_function = false; | 59 *last_frame_is_unknown_function = false; |
| 60 | 60 |
| 61 IMAGEHLP_SYMBOL64 sym; | 61 IMAGEHLP_SYMBOL64 sym; |
| 62 sym.SizeOfStruct = sizeof(sym); | 62 sym.SizeOfStruct = sizeof(sym); |
|
Peter Kasting
2015/03/26 04:29:09
Nit: While not required, I tend to initialize Wind
Mike Wittman
2015/03/27 22:42:05
This struct is actually unused, so I just removed
| |
| 63 sym.MaxNameLength = 0; | 63 sym.MaxNameLength = 0; |
| 64 | 64 |
| 65 for (int i = 0; i < max_stack_size; ++i) { | 65 for (int i = 0; i < max_stack_size; ++i) { |
| 66 // Try to look up unwind metadata for the current function. | 66 // Try to look up unwind metadata for the current function. |
| 67 ULONG64 image_base; | 67 ULONG64 image_base; |
| 68 PRUNTIME_FUNCTION runtime_function = | 68 PRUNTIME_FUNCTION runtime_function = |
| 69 RtlLookupFunctionEntry(context->Rip, &image_base, nullptr); | 69 RtlLookupFunctionEntry(context->Rip, &image_base, nullptr); |
| 70 | 70 |
| 71 instruction_pointers[i] = reinterpret_cast<void*>(context->Rip); | 71 instruction_pointers[i] = reinterpret_cast<void*>(context->Rip); |
|
Peter Kasting
2015/03/26 04:29:09
It's not obvious to me whether it's correct that t
Mike Wittman
2015/03/27 22:42:05
It is correct based on observation of collected st
| |
| 72 | 72 |
| 73 if (runtime_function) { | 73 if (runtime_function) { |
| 74 KNONVOLATILE_CONTEXT_POINTERS nvcontext = {0}; | 74 KNONVOLATILE_CONTEXT_POINTERS nvcontext = {0}; |
| 75 void* handler_data; | 75 void* handler_data; |
| 76 ULONG64 establisher_frame; | 76 ULONG64 establisher_frame; |
| 77 RtlVirtualUnwind(0, image_base, context->Rip, runtime_function, context, | 77 RtlVirtualUnwind(0, image_base, context->Rip, runtime_function, context, |
| 78 &handler_data, &establisher_frame, &nvcontext); | 78 &handler_data, &establisher_frame, &nvcontext); |
|
Peter Kasting
2015/03/26 04:29:09
Subsequent lines of args must be aligned with the
Mike Wittman
2015/03/27 22:42:05
Done.
| |
| 79 } else { | 79 } else { |
| 80 // If we don't have a RUNTIME_FUNCTION, then we've encountered | 80 // If we don't have a RUNTIME_FUNCTION, then we've encountered |
| 81 // a leaf function. Adjust the stack appropriately. | 81 // a leaf function. Adjust the stack appropriately. |
| 82 context->Rip = *reinterpret_cast<PDWORD64>(context->Rsp); | 82 context->Rip = *reinterpret_cast<PDWORD64>(context->Rsp); |
| 83 context->Rsp += 8; | 83 context->Rsp += 8; |
| 84 *last_frame_is_unknown_function = true; | 84 *last_frame_is_unknown_function = true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (!context->Rip) | 87 if (!context->Rip) |
|
Peter Kasting
2015/03/26 04:29:08
We always do one iteration of the loop before chec
Mike Wittman
2015/03/27 22:42:04
I'm inclined to check it beforehand and use your s
| |
| 88 return i; | 88 return i; |
| 89 } | 89 } |
| 90 return max_stack_size; | 90 return max_stack_size; |
| 91 #else | 91 #else |
| 92 return 0; | 92 return 0; |
| 93 #endif | 93 #endif |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Fills in |modules| corresponding to the pointers to code in |addresses|. The | 96 // Fills in |modules| corresponding to the pointers to code in |addresses|. The |
| 97 // modules are returned with reference counts incremented should be freed with | 97 // modules are returned with reference counts incremented should be freed with |
| 98 // FreeModules. | 98 // FreeModules. |
| 99 void FindModulesForAddresses(const void* const addresses[], HMODULE modules[], | 99 void FindModulesForAddresses(const void* const addresses[], HMODULE modules[], |
| 100 int stack_depth, | 100 int stack_depth, |
| 101 bool last_frame_is_unknown_function) { | 101 bool last_frame_is_unknown_function) { |
| 102 const int module_frames = last_frame_is_unknown_function ? stack_depth - 1 : | 102 const int module_frames = last_frame_is_unknown_function ? stack_depth - 1 : |
| 103 stack_depth; | 103 stack_depth; |
|
Peter Kasting
2015/03/26 04:29:08
Nit: This wrapping is a bit unusual; consider some
Mike Wittman
2015/03/27 22:42:05
Done.
| |
| 104 for (int i = 0; i < module_frames; ++i) { | 104 for (int i = 0; i < module_frames; ++i) { |
| 105 HMODULE module = NULL; | 105 HMODULE module = NULL; |
| 106 if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, | 106 if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, |
| 107 reinterpret_cast<LPCTSTR>(addresses[i]), | 107 reinterpret_cast<LPCTSTR>(addresses[i]), |
| 108 &module)) { | 108 &module)) { |
| 109 // HMODULE is the base address of the module. | 109 // HMODULE is the base address of the module. |
|
Peter Kasting
2015/03/26 04:29:08
I'm not actually sure what this comment is adding.
Mike Wittman
2015/03/27 22:42:05
It was intended to document that the value of an H
Peter Kasting
2015/03/27 23:44:46
Yes, that makes more sense.
| |
| 110 DCHECK_LT(reinterpret_cast<const void*>(module), addresses[i]); | 110 DCHECK_LT(reinterpret_cast<const void*>(module), addresses[i]); |
|
Peter Kasting
2015/03/26 04:29:09
Should this be LE instead of LT? Are we guarantee
Mike Wittman
2015/03/27 22:42:04
It should be LE. Fixed.
| |
| 111 modules[i] = module; | 111 modules[i] = module; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Free the modules returned by FindModulesForAddresses. | 116 // Free the modules returned by FindModulesForAddresses. |
| 117 void FreeModules(int stack_depth, HMODULE modules[]) { | 117 void FreeModules(int stack_depth, HMODULE modules[]) { |
| 118 for (int i = 0; i < stack_depth; ++i) { | 118 for (int i = 0; i < stack_depth; ++i) { |
| 119 if (modules[i]) | 119 if (modules[i]) |
| 120 ::FreeLibrary(modules[i]); | 120 ::FreeLibrary(modules[i]); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(ScopedDisablePriorityBoost); | 135 DISALLOW_COPY_AND_ASSIGN(ScopedDisablePriorityBoost); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 ScopedDisablePriorityBoost::ScopedDisablePriorityBoost(HANDLE thread_handle) | 138 ScopedDisablePriorityBoost::ScopedDisablePriorityBoost(HANDLE thread_handle) |
| 139 : thread_handle_(thread_handle), | 139 : thread_handle_(thread_handle), |
| 140 got_previous_boost_state_(false), | 140 got_previous_boost_state_(false), |
| 141 boost_state_was_disabled_(false) { | 141 boost_state_was_disabled_(false) { |
| 142 got_previous_boost_state_ = | 142 got_previous_boost_state_ = |
| 143 ::GetThreadPriorityBoost(thread_handle_, &boost_state_was_disabled_); | 143 ::GetThreadPriorityBoost(thread_handle_, &boost_state_was_disabled_); |
| 144 if (got_previous_boost_state_ && !boost_state_was_disabled_) { | 144 if (got_previous_boost_state_ && !boost_state_was_disabled_) { |
|
Peter Kasting
2015/03/26 04:29:08
Nit: Technically, the second part of the condition
Mike Wittman
2015/03/27 22:42:04
I don't have reason to believe this function is ex
| |
| 145 // Confusingly, TRUE disables priority boost ... | 145 // Confusingly, TRUE disables priority boost ... |
| 146 ::SetThreadPriorityBoost(thread_handle_, TRUE); | 146 ::SetThreadPriorityBoost(thread_handle_, TRUE); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 ScopedDisablePriorityBoost::~ScopedDisablePriorityBoost() { | 150 ScopedDisablePriorityBoost::~ScopedDisablePriorityBoost() { |
| 151 if (got_previous_boost_state_ && !boost_state_was_disabled_) { | 151 if (got_previous_boost_state_ && !boost_state_was_disabled_) { |
| 152 // ... and FALSE enables priority boost. | 152 // ... and FALSE enables priority boost. |
|
Peter Kasting
2015/03/26 04:29:08
Nit: This comment would be unnecessary (because th
Mike Wittman
2015/03/27 22:42:05
Done.
| |
| 153 ::SetThreadPriorityBoost(thread_handle_, FALSE); | 153 ::SetThreadPriorityBoost(thread_handle_, FALSE); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Suspends the thread with |thread_handle|, records the stack into | 157 // Suspends the thread with |thread_handle|, records the stack into |
| 158 // |instruction_pointers|, then resumes the thread. Returns the size of the | 158 // |instruction_pointers|, then resumes the thread. Returns the size of the |
| 159 // stack. | 159 // stack. |
| 160 int SuspendThreadAndRecordStack(HANDLE thread_handle, int max_stack_size, | 160 int SuspendThreadAndRecordStack(HANDLE thread_handle, int max_stack_size, |
| 161 const void* instruction_pointers[], | 161 const void* instruction_pointers[], |
| 162 bool* last_frame_is_unknown_function) { | 162 bool* last_frame_is_unknown_function) { |
| 163 #if defined(_WIN64) | 163 #if defined(_WIN64) |
| 164 if (RtlVirtualUnwind == nullptr || RtlLookupFunctionEntry == nullptr) | 164 if (RtlVirtualUnwind == nullptr || RtlLookupFunctionEntry == nullptr) |
|
Peter Kasting
2015/03/26 04:29:08
Tiny nit: Personally I prefer the brevity of "!foo
Mike Wittman
2015/03/27 22:42:04
Done.
| |
| 165 return 0; | 165 return 0; |
| 166 #endif | 166 #endif |
| 167 | 167 |
| 168 if (::SuspendThread(thread_handle) == -1) { | 168 if (::SuspendThread(thread_handle) == -1) { |
| 169 LOG(ERROR) << "SuspendThread failed: " << GetLastError(); | 169 LOG(ERROR) << "SuspendThread failed: " << GetLastError(); |
| 170 return 0; | 170 return 0; |
| 171 } | 171 } |
| 172 | 172 |
| 173 CONTEXT thread_context = {0}; | 173 CONTEXT thread_context = {0}; |
| 174 thread_context.ContextFlags = CONTEXT_FULL; | 174 thread_context.ContextFlags = CONTEXT_FULL; |
| 175 if (!::GetThreadContext(thread_handle, &thread_context)) { | 175 if (!::GetThreadContext(thread_handle, &thread_context)) { |
| 176 LOG(ERROR) << "GetThreadContext failed: " << GetLastError(); | 176 LOG(ERROR) << "GetThreadContext failed: " << GetLastError(); |
|
Peter Kasting
2015/03/26 04:29:08
Do we need to return 0 here, or is calling RecordS
Mike Wittman
2015/03/27 22:42:05
Presumably we don't have a valid CONTEXT at this p
| |
| 177 } | 177 } |
| 178 | 178 |
| 179 int stack_depth = RecordStack(&thread_context, max_stack_size, | 179 int stack_depth = RecordStack(&thread_context, max_stack_size, |
| 180 instruction_pointers, | 180 instruction_pointers, |
| 181 last_frame_is_unknown_function); | 181 last_frame_is_unknown_function); |
| 182 | 182 |
| 183 { | 183 { |
| 184 ScopedDisablePriorityBoost disable_priority_boost(thread_handle); | 184 ScopedDisablePriorityBoost disable_priority_boost(thread_handle); |
|
Peter Kasting
2015/03/26 04:29:08
While I like scoping objects, if this is the only
Mike Wittman
2015/03/27 22:42:05
Done.
| |
| 185 if (::ResumeThread(thread_handle) == -1) | 185 if (::ResumeThread(thread_handle) == -1) |
| 186 LOG(ERROR) << "ResumeThread failed: " << GetLastError(); | 186 LOG(ERROR) << "ResumeThread failed: " << GetLastError(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 return stack_depth; | 189 return stack_depth; |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 scoped_ptr<StackSamplingProfiler::NativeStackSampler> | 194 scoped_ptr<StackSamplingProfiler::NativeStackSampler> |
| 195 StackSamplingProfiler::NativeStackSampler::Create(PlatformThreadId thread_id) { | 195 StackSamplingProfiler::NativeStackSampler::Create(PlatformThreadId thread_id) { |
| 196 #if _WIN64 | 196 #if _WIN64 |
| 197 // Get the thread's handle. | 197 // Get the thread's handle. |
| 198 HANDLE thread_handle = ::OpenThread( | 198 HANDLE thread_handle = ::OpenThread( |
| 199 THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_QUERY_INFORMATION, | 199 THREAD_GET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_QUERY_INFORMATION, |
| 200 FALSE, | 200 FALSE, |
| 201 thread_id); | 201 thread_id); |
| 202 DCHECK(thread_handle) << "OpenThread failed"; | 202 DCHECK(thread_handle) << "OpenThread failed"; |
|
Peter Kasting
2015/03/26 04:29:09
Can the call ever actually fail?
If so, a DCHECK
Mike Wittman
2015/03/27 22:42:05
Presumably this can fail if the thread exits befor
| |
| 203 | 203 |
| 204 return scoped_ptr<NativeStackSampler>(new NativeStackSamplerWin( | 204 return scoped_ptr<NativeStackSampler>(new NativeStackSamplerWin( |
| 205 win::ScopedHandle(thread_handle))); | 205 win::ScopedHandle(thread_handle))); |
| 206 #else | 206 #else |
| 207 return scoped_ptr<NativeStackSampler>(); | 207 return scoped_ptr<NativeStackSampler>(); |
| 208 #endif | 208 #endif |
| 209 } | 209 } |
| 210 | 210 |
| 211 NativeStackSamplerWin::NativeStackSamplerWin(win::ScopedHandle thread_handle) | 211 NativeStackSamplerWin::NativeStackSamplerWin(win::ScopedHandle thread_handle) |
| 212 : thread_handle_(thread_handle.Take()) { | 212 : thread_handle_(thread_handle.Take()) { |
| 213 #ifdef _WIN64 | 213 #ifdef _WIN64 |
| 214 if (RtlVirtualUnwind == nullptr && RtlLookupFunctionEntry == nullptr) { | 214 if (RtlVirtualUnwind == nullptr && RtlLookupFunctionEntry == nullptr) { |
| 215 const HMODULE nt_dll_handle = ::GetModuleHandle(L"ntdll.dll"); | 215 const HMODULE nt_dll_handle = ::GetModuleHandle(L"ntdll.dll"); |
| 216 // This should always be non-null, but handle just in case. | 216 // This should always be non-null, but handle just in case. |
| 217 if (nt_dll_handle) { | 217 if (nt_dll_handle) { |
| 218 reinterpret_cast<void*&>(RtlVirtualUnwind) = | 218 reinterpret_cast<void*&>(RtlVirtualUnwind) = |
|
Peter Kasting
2015/03/26 04:29:08
I'm confused. Where is this declared? I thought
Mike Wittman
2015/03/27 22:42:04
To be honest, I'm not sure why these checks are he
Peter Kasting
2015/03/27 23:44:46
\o/
| |
| 219 ::GetProcAddress(nt_dll_handle, "RtlVirtualUnwind"); | 219 ::GetProcAddress(nt_dll_handle, "RtlVirtualUnwind"); |
| 220 reinterpret_cast<void*&>(RtlLookupFunctionEntry) = | 220 reinterpret_cast<void*&>(RtlLookupFunctionEntry) = |
| 221 ::GetProcAddress(nt_dll_handle, "RtlLookupFunctionEntry"); | 221 ::GetProcAddress(nt_dll_handle, "RtlLookupFunctionEntry"); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 #endif | 224 #endif |
| 225 } | 225 } |
| 226 | 226 |
| 227 NativeStackSamplerWin::~NativeStackSamplerWin() { | 227 NativeStackSamplerWin::~NativeStackSamplerWin() { |
| 228 } | 228 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 if (result_length == 0) | 266 if (result_length == 0) |
| 267 return false; | 267 return false; |
| 268 | 268 |
| 269 module_info->filename = base::FilePath(module_name); | 269 module_info->filename = base::FilePath(module_name); |
| 270 | 270 |
| 271 module_info->base_address = reinterpret_cast<const void*>(module); | 271 module_info->base_address = reinterpret_cast<const void*>(module); |
| 272 | 272 |
| 273 GUID guid; | 273 GUID guid; |
| 274 DWORD age; | 274 DWORD age; |
| 275 win::PEImage(module).GetDebugId(&guid, &age); | 275 win::PEImage(module).GetDebugId(&guid, &age); |
| 276 module_info->id.insert(module_info->id.end(), | 276 module_info->id.insert(module_info->id.end(), |
|
Peter Kasting
2015/03/26 04:29:08
How come you're appending to |id| here instead of
Mike Wittman
2015/03/27 22:42:05
Sure, that's much clearer.
| |
| 277 reinterpret_cast<char*>(&guid), | 277 reinterpret_cast<char*>(&guid), |
| 278 reinterpret_cast<char*>(&guid + 1)); | 278 reinterpret_cast<char*>(&guid + 1)); |
| 279 module_info->id.insert(module_info->id.end(), | 279 module_info->id.insert(module_info->id.end(), |
| 280 reinterpret_cast<char*>(&age), | 280 reinterpret_cast<char*>(&age), |
| 281 reinterpret_cast<char*>(&age + 1)); | 281 reinterpret_cast<char*>(&age + 1)); |
| 282 | 282 |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| 285 | 285 |
| 286 void NativeStackSamplerWin::CopyToSample( | 286 void NativeStackSamplerWin::CopyToSample( |
| 287 const void* const instruction_pointers[], | 287 const void* const instruction_pointers[], |
| 288 const HMODULE modules[], | 288 const HMODULE modules[], |
| 289 int stack_depth, | 289 int stack_depth, |
| 290 StackSamplingProfiler::Sample* sample, | 290 StackSamplingProfiler::Sample* sample, |
| 291 std::vector<StackSamplingProfiler::Module>* module_infos) { | 291 std::vector<StackSamplingProfiler::Module>* module_infos) { |
| 292 sample->clear(); | 292 sample->clear(); |
| 293 sample->reserve(stack_depth); | 293 sample->reserve(stack_depth); |
| 294 | 294 |
| 295 for (int i = 0; i < stack_depth; ++i) { | 295 for (int i = 0; i < stack_depth; ++i) { |
| 296 sample->push_back(StackSamplingProfiler::Frame()); | 296 sample->push_back(StackSamplingProfiler::Frame()); |
|
Peter Kasting
2015/03/26 04:29:08
The reason we need a push_back() and then non-cons
Mike Wittman
2015/03/27 22:42:04
Done.
| |
| 297 StackSamplingProfiler::Frame& frame = sample->back(); | 297 StackSamplingProfiler::Frame& frame = sample->back(); |
| 298 | 298 |
| 299 frame.instruction_pointer = instruction_pointers[i]; | 299 frame.instruction_pointer = instruction_pointers[i]; |
| 300 | 300 |
| 301 // Record an invalid module index if we don't have a valid module. | 301 // Record an invalid module index if we don't have a valid module. |
| 302 if (!modules[i]) { | 302 if (!modules[i]) { |
| 303 frame.module_index = -1; | 303 frame.module_index = -1; |
| 304 continue; | 304 continue; |
| 305 } | 305 } |
| 306 | 306 |
| 307 auto loc = profile_module_index_.find(modules[i]); | 307 auto loc = profile_module_index_.find(modules[i]); |
| 308 if (loc == profile_module_index_.end()) { | 308 if (loc == profile_module_index_.end()) { |
| 309 StackSamplingProfiler::Module module_info; | 309 StackSamplingProfiler::Module module_info; |
| 310 // Record an invalid module index if we have a module but can't find | 310 // Record an invalid module index if we have a module but can't find |
| 311 // information on it. | 311 // information on it. |
| 312 if (!GetModuleInfo(modules[i], &module_info)) { | 312 if (!GetModuleInfo(modules[i], &module_info)) { |
| 313 frame.module_index = -1; | 313 frame.module_index = -1; |
| 314 continue; | 314 continue; |
| 315 } | 315 } |
| 316 module_infos->push_back(module_info); | 316 module_infos->push_back(module_info); |
| 317 loc = profile_module_index_.insert(std::make_pair( | 317 loc = profile_module_index_.insert(std::make_pair( |
| 318 modules[i], static_cast<int>(module_infos->size() - 1))).first; | 318 modules[i], static_cast<int>(module_infos->size() - 1))).first; |
| 319 } | 319 } |
| 320 | 320 |
| 321 frame.module_index = loc->second; | 321 frame.module_index = loc->second; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace base | 325 } // namespace base |
| 326 | |
| OLD | NEW |