sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 15f620c | 2021-02-13 05:30:58 +0000 | [diff] [blame] | 2 | * Copyright (C) 2016-2021 Apple Inc. All rights reserved. |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "SamplingProfiler.h" |
| 28 | |
| 29 | #if ENABLE(SAMPLING_PROFILER) |
| 30 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 31 | #include "CodeBlock.h" |
fpizlo@apple.com | 7b23164 | 2016-10-11 23:52:02 +0000 | [diff] [blame] | 32 | #include "CodeBlockSet.h" |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 33 | #include "HeapIterationScope.h" |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 34 | #include "HeapUtil.h" |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 35 | #include "InlineCallFrame.h" |
ross.kirsling@sony.com | e257a3b | 2020-05-19 23:56:00 +0000 | [diff] [blame] | 36 | #include "JSCInlines.h" |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 37 | #include "LLIntPCRanges.h" |
utatane.tea@gmail.com | 7111191 | 2017-07-19 08:43:57 +0000 | [diff] [blame] | 38 | #include "MachineContext.h" |
ross.kirsling@sony.com | 0ebe33c | 2020-05-15 19:39:36 +0000 | [diff] [blame] | 39 | #include "MarkedBlockInlines.h" |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 40 | #include "MarkedBlockSet.h" |
ggaren@apple.com | c9a6ef4 | 2016-10-28 20:04:56 +0000 | [diff] [blame] | 41 | #include "NativeExecutable.h" |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 42 | #include "VM.h" |
mark.lam@apple.com | e2166a8 | 2021-04-28 17:13:40 +0000 | [diff] [blame] | 43 | #include "VMTrapsInlines.h" |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 44 | #include "WasmCallee.h" |
| 45 | #include "WasmCalleeRegistry.h" |
mark.lam@apple.com | 9c02581 | 2020-05-26 21:32:50 +0000 | [diff] [blame] | 46 | #include "WasmCapabilities.h" |
annulen@yandex.ru | 9c4fab5 | 2017-06-20 16:32:41 +0000 | [diff] [blame] | 47 | #include <wtf/FilePrintStream.h> |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 48 | #include <wtf/HashSet.h> |
| 49 | #include <wtf/RefPtr.h> |
utatane.tea@gmail.com | 5795061 | 2017-04-25 02:53:49 +0000 | [diff] [blame] | 50 | #include <wtf/StackTrace.h> |
joepeck@webkit.org | 7e07f39 | 2016-09-22 18:59:47 +0000 | [diff] [blame] | 51 | #include <wtf/text/StringBuilder.h> |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 52 | |
| 53 | namespace JSC { |
| 54 | |
| 55 | static double sNumTotalStackTraces = 0; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 56 | static double sNumTotalWalks = 0; |
| 57 | static double sNumFailedWalks = 0; |
| 58 | static const uint32_t sNumWalkReportingFrequency = 50; |
| 59 | static const double sWalkErrorPercentage = .05; |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 60 | static constexpr bool sReportStatsOnlyWhenTheyreAboveThreshold = false; |
| 61 | static constexpr bool sReportStats = false; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 62 | |
| 63 | using FrameType = SamplingProfiler::FrameType; |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 64 | using UnprocessedStackFrame = SamplingProfiler::UnprocessedStackFrame; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 65 | |
| 66 | ALWAYS_INLINE static void reportStats() |
| 67 | { |
| 68 | if (sReportStats && sNumTotalWalks && static_cast<uint64_t>(sNumTotalWalks) % sNumWalkReportingFrequency == 0) { |
| 69 | if (!sReportStatsOnlyWhenTheyreAboveThreshold || (sNumFailedWalks / sNumTotalWalks > sWalkErrorPercentage)) { |
| 70 | dataLogF("Num total walks: %llu. Failed walks percent: %lf\n", |
utatane.tea@gmail.com | 0cf8d74 | 2016-01-30 12:53:59 +0000 | [diff] [blame] | 71 | static_cast<unsigned long long>(sNumTotalWalks), sNumFailedWalks / sNumTotalWalks); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | class FrameWalker { |
| 77 | public: |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 78 | FrameWalker(VM& vm, CallFrame* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 79 | : m_vm(vm) |
| 80 | , m_callFrame(callFrame) |
jfbastien@apple.com | d9f999e | 2017-10-20 02:23:29 +0000 | [diff] [blame] | 81 | , m_entryFrame(vm.topEntryFrame) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 82 | , m_codeBlockSetLocker(codeBlockSetLocker) |
| 83 | , m_machineThreadsLocker(machineThreadsLocker) |
| 84 | { |
| 85 | } |
| 86 | |
sbarati@apple.com | 30cd116 | 2016-02-11 21:04:43 +0000 | [diff] [blame] | 87 | SUPPRESS_ASAN |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 88 | size_t walk(Vector<UnprocessedStackFrame>& stackTrace, bool& didRunOutOfSpace) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 89 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 90 | if (sReportStats) |
| 91 | sNumTotalWalks++; |
| 92 | resetAtMachineFrame(); |
| 93 | size_t maxStackTraceSize = stackTrace.size(); |
| 94 | while (!isAtTop() && !m_bailingOut && m_depth < maxStackTraceSize) { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 95 | recordJITFrame(stackTrace); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 96 | advanceToParentFrame(); |
| 97 | resetAtMachineFrame(); |
| 98 | } |
| 99 | didRunOutOfSpace = m_depth >= maxStackTraceSize && !isAtTop(); |
| 100 | reportStats(); |
| 101 | return m_depth; |
| 102 | } |
| 103 | |
| 104 | bool wasValidWalk() const |
| 105 | { |
| 106 | return !m_bailingOut; |
| 107 | } |
| 108 | |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 109 | protected: |
| 110 | |
| 111 | SUPPRESS_ASAN |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 112 | void recordJITFrame(Vector<UnprocessedStackFrame>& stackTrace) |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 113 | { |
| 114 | CallSiteIndex callSiteIndex; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 115 | CalleeBits unsafeCallee = m_callFrame->unsafeCallee(); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 116 | CodeBlock* codeBlock = m_callFrame->unsafeCodeBlock(); |
tzagallo@apple.com | bf01be2 | 2019-10-31 22:32:52 +0000 | [diff] [blame] | 117 | if (unsafeCallee.isWasm()) |
| 118 | codeBlock = nullptr; |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 119 | if (codeBlock) { |
| 120 | ASSERT(isValidCodeBlock(codeBlock)); |
| 121 | callSiteIndex = m_callFrame->unsafeCallSiteIndex(); |
| 122 | } |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 123 | stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, unsafeCallee, callSiteIndex); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 124 | #if ENABLE(WEBASSEMBLY) |
mark.lam@apple.com | 9c02581 | 2020-05-26 21:32:50 +0000 | [diff] [blame] | 125 | if (Wasm::isSupported() && unsafeCallee.isWasm()) { |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 126 | assertIsHeld(Wasm::CalleeRegistry::singleton().getLock()); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 127 | auto* wasmCallee = unsafeCallee.asWasmCallee(); |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 128 | if (Wasm::CalleeRegistry::singleton().isValidCallee(wasmCallee)) { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 129 | // At this point, Wasm::Callee would be dying (ref count is 0), but its fields are still live. |
| 130 | // And we can safely copy Wasm::IndexOrName even when any lock is held by suspended threads. |
| 131 | stackTrace[m_depth].wasmIndexOrName = wasmCallee->indexOrName(); |
| 132 | stackTrace[m_depth].wasmCompilationMode = wasmCallee->compilationMode(); |
| 133 | } |
| 134 | } |
| 135 | #endif |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 136 | m_depth++; |
| 137 | } |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 138 | |
sbarati@apple.com | 30cd116 | 2016-02-11 21:04:43 +0000 | [diff] [blame] | 139 | SUPPRESS_ASAN |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 140 | void advanceToParentFrame() |
| 141 | { |
jfbastien@apple.com | d9f999e | 2017-10-20 02:23:29 +0000 | [diff] [blame] | 142 | m_callFrame = m_callFrame->unsafeCallerFrame(m_entryFrame); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | bool isAtTop() const |
| 146 | { |
| 147 | return !m_callFrame; |
| 148 | } |
| 149 | |
sbarati@apple.com | 30cd116 | 2016-02-11 21:04:43 +0000 | [diff] [blame] | 150 | SUPPRESS_ASAN |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 151 | void resetAtMachineFrame() |
| 152 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 153 | if (isAtTop()) |
| 154 | return; |
| 155 | |
| 156 | if (!isValidFramePointer(m_callFrame)) { |
| 157 | // Guard against pausing the process at weird program points. |
| 158 | m_bailingOut = true; |
| 159 | if (sReportStats) |
| 160 | sNumFailedWalks++; |
| 161 | return; |
| 162 | } |
| 163 | |
sbarati@apple.com | 88a5fd6 | 2016-02-16 22:01:37 +0000 | [diff] [blame] | 164 | CodeBlock* codeBlock = m_callFrame->unsafeCodeBlock(); |
mark.lam@apple.com | cadee71 | 2019-11-04 19:23:24 +0000 | [diff] [blame] | 165 | if (!codeBlock || m_callFrame->unsafeCallee().isWasm()) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 166 | return; |
| 167 | |
| 168 | if (!isValidCodeBlock(codeBlock)) { |
| 169 | m_bailingOut = true; |
| 170 | if (sReportStats) |
| 171 | sNumFailedWalks++; |
| 172 | return; |
| 173 | } |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 174 | } |
| 175 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 176 | bool isValidFramePointer(void* callFrame) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 177 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 178 | uint8_t* fpCast = bitwise_cast<uint8_t*>(callFrame); |
utatane.tea@gmail.com | 7111191 | 2017-07-19 08:43:57 +0000 | [diff] [blame] | 179 | for (auto& thread : m_vm.heap.machineThreads().threads(m_machineThreadsLocker)) { |
| 180 | uint8_t* stackBase = static_cast<uint8_t*>(thread->stack().origin()); |
| 181 | uint8_t* stackLimit = static_cast<uint8_t*>(thread->stack().end()); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 182 | RELEASE_ASSERT(stackBase); |
| 183 | RELEASE_ASSERT(stackLimit); |
mark.lam@apple.com | 8a3e337 | 2018-12-18 01:21:07 +0000 | [diff] [blame] | 184 | RELEASE_ASSERT(stackLimit <= stackBase); |
| 185 | if (fpCast < stackBase && fpCast >= stackLimit) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 186 | return true; |
| 187 | } |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | bool isValidCodeBlock(CodeBlock* codeBlock) |
| 192 | { |
| 193 | if (!codeBlock) |
| 194 | return false; |
| 195 | bool result = m_vm.heap.codeBlockSet().contains(m_codeBlockSetLocker, codeBlock); |
| 196 | return result; |
| 197 | } |
| 198 | |
| 199 | VM& m_vm; |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 200 | CallFrame* m_callFrame; |
jfbastien@apple.com | d9f999e | 2017-10-20 02:23:29 +0000 | [diff] [blame] | 201 | EntryFrame* m_entryFrame; |
mark.lam@apple.com | a2668e0 | 2017-03-09 21:05:41 +0000 | [diff] [blame] | 202 | const AbstractLocker& m_codeBlockSetLocker; |
| 203 | const AbstractLocker& m_machineThreadsLocker; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 204 | bool m_bailingOut { false }; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 205 | size_t m_depth { 0 }; |
| 206 | }; |
| 207 | |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 208 | class CFrameWalker : public FrameWalker { |
| 209 | public: |
| 210 | typedef FrameWalker Base; |
| 211 | |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 212 | CFrameWalker(VM& vm, void* machineFrame, CallFrame* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker) |
| 213 | : Base(vm, callFrame, codeBlockSetLocker, machineThreadsLocker) |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 214 | , m_machineFrame(machineFrame) |
| 215 | { |
| 216 | } |
| 217 | |
| 218 | size_t walk(Vector<UnprocessedStackFrame>& stackTrace, bool& didRunOutOfSpace) |
| 219 | { |
| 220 | if (sReportStats) |
| 221 | sNumTotalWalks++; |
| 222 | resetAtMachineFrame(); |
| 223 | size_t maxStackTraceSize = stackTrace.size(); |
| 224 | // The way the C walker decides if a frame it is about to trace is C or JS is by |
| 225 | // ensuring m_callFrame points to some frame above the machineFrame. |
| 226 | if (!isAtTop() && !m_bailingOut && m_machineFrame == m_callFrame) { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 227 | recordJITFrame(stackTrace); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 228 | Base::advanceToParentFrame(); |
| 229 | resetAtMachineFrame(); |
| 230 | } |
| 231 | |
| 232 | while (!isAtTop() && !m_bailingOut && m_depth < maxStackTraceSize) { |
| 233 | if (m_machineFrame >= m_callFrame) { |
| 234 | // If we get to this state we probably have an invalid trace. |
| 235 | m_bailingOut = true; |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | if (isCFrame()) { |
| 240 | RELEASE_ASSERT(!LLInt::isLLIntPC(frame()->callerFrame)); |
keith_miller@apple.com | e870917 | 2018-10-16 07:19:13 +0000 | [diff] [blame] | 241 | stackTrace[m_depth] = UnprocessedStackFrame(frame()->returnPC); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 242 | m_depth++; |
| 243 | } else |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 244 | recordJITFrame(stackTrace); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 245 | advanceToParentFrame(); |
| 246 | resetAtMachineFrame(); |
| 247 | } |
| 248 | didRunOutOfSpace = m_depth >= maxStackTraceSize && !isAtTop(); |
| 249 | reportStats(); |
| 250 | return m_depth; |
| 251 | } |
| 252 | |
| 253 | private: |
| 254 | |
| 255 | bool isCFrame() |
| 256 | { |
| 257 | return frame()->callerFrame != m_callFrame; |
| 258 | } |
| 259 | |
| 260 | void advanceToParentFrame() |
| 261 | { |
| 262 | if (!isCFrame()) |
| 263 | Base::advanceToParentFrame(); |
| 264 | m_machineFrame = frame()->callerFrame; |
| 265 | } |
| 266 | |
| 267 | void resetAtMachineFrame() |
| 268 | { |
| 269 | if (!isValidFramePointer(m_machineFrame)) { |
| 270 | // Guard against pausing the process at weird program points. |
| 271 | m_bailingOut = true; |
| 272 | if (sReportStats) |
| 273 | sNumFailedWalks++; |
| 274 | return; |
| 275 | } |
| 276 | Base::resetAtMachineFrame(); |
| 277 | } |
| 278 | |
| 279 | CallerFrameAndPC* frame() |
| 280 | { |
| 281 | return reinterpret_cast<CallerFrameAndPC*>(m_machineFrame); |
| 282 | } |
| 283 | |
| 284 | void* m_machineFrame; |
| 285 | }; |
| 286 | |
drousso@apple.com | 1cd5053 | 2020-05-06 16:15:16 +0000 | [diff] [blame] | 287 | SamplingProfiler::SamplingProfiler(VM& vm, Ref<Stopwatch>&& stopwatch) |
rmorisset@apple.com | 4ccbcf1 | 2019-03-12 19:07:04 +0000 | [diff] [blame] | 288 | : m_isPaused(false) |
| 289 | , m_isShutDown(false) |
| 290 | , m_vm(vm) |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 291 | , m_weakRandom() |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 292 | , m_stopwatch(WTFMove(stopwatch)) |
utatane.tea@gmail.com | 5c7039d | 2017-12-27 00:33:11 +0000 | [diff] [blame] | 293 | , m_timingInterval(Seconds::fromMicroseconds(Options::sampleInterval())) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 294 | { |
| 295 | if (sReportStats) { |
| 296 | sNumTotalWalks = 0; |
| 297 | sNumFailedWalks = 0; |
| 298 | } |
| 299 | |
| 300 | m_currentFrames.grow(256); |
ysuzuki@apple.com | b439915 | 2019-11-09 03:45:18 +0000 | [diff] [blame] | 301 | vm.heap.objectSpace().enablePreciseAllocationTracking(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 302 | } |
| 303 | |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 304 | SamplingProfiler::~SamplingProfiler() |
| 305 | { |
| 306 | } |
| 307 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 308 | void SamplingProfiler::createThreadIfNecessary() |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 309 | { |
| 310 | ASSERT(m_lock.isLocked()); |
| 311 | |
utatane.tea@gmail.com | 1e94a26 | 2017-04-12 12:08:29 +0000 | [diff] [blame] | 312 | if (m_thread) |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 313 | return; |
| 314 | |
| 315 | RefPtr<SamplingProfiler> profiler = this; |
utatane.tea@gmail.com | 1e94a26 | 2017-04-12 12:08:29 +0000 | [diff] [blame] | 316 | m_thread = Thread::create("jsc.sampling-profiler.thread", [profiler] { |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 317 | profiler->timerLoop(); |
| 318 | }); |
| 319 | } |
| 320 | |
| 321 | void SamplingProfiler::timerLoop() |
| 322 | { |
| 323 | while (true) { |
utatane.tea@gmail.com | 5c7039d | 2017-12-27 00:33:11 +0000 | [diff] [blame] | 324 | Seconds stackTraceProcessingTime = 0_s; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 325 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 326 | Locker locker { m_lock }; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 327 | if (UNLIKELY(m_isShutDown)) |
| 328 | return; |
| 329 | |
| 330 | if (!m_isPaused && m_jscExecutionThread) |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 331 | takeSample(stackTraceProcessingTime); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 332 | |
| 333 | m_lastTime = m_stopwatch->elapsedTime(); |
| 334 | } |
| 335 | |
sbarati@apple.com | 51d8007 | 2016-06-14 02:29:26 +0000 | [diff] [blame] | 336 | // Read section 6.2 of this paper for more elaboration of why we add a random |
| 337 | // fluctuation here. The main idea is to prevent our timer from being in sync |
| 338 | // with some system process such as a scheduled context switch. |
| 339 | // http://plv.colorado.edu/papers/mytkowicz-pldi10.pdf |
utatane.tea@gmail.com | 0f6fd7b | 2017-03-24 05:31:51 +0000 | [diff] [blame] | 340 | double randomSignedNumber = (m_weakRandom.get() * 2.0) - 1.0; // A random number between [-1, 1). |
utatane.tea@gmail.com | 5c7039d | 2017-12-27 00:33:11 +0000 | [diff] [blame] | 341 | Seconds randomFluctuation = m_timingInterval * 0.2 * randomSignedNumber; |
| 342 | WTF::sleep(m_timingInterval - std::min(m_timingInterval, stackTraceProcessingTime) + randomFluctuation); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 346 | void SamplingProfiler::takeSample(Seconds& stackTraceProcessingTime) |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 347 | { |
| 348 | ASSERT(m_lock.isLocked()); |
| 349 | if (m_vm.entryScope) { |
utatane.tea@gmail.com | f013068 | 2018-03-02 17:13:32 +0000 | [diff] [blame] | 350 | Seconds nowTime = m_stopwatch->elapsedTime(); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 351 | |
cdumez@apple.com | 6c3db6c | 2021-05-22 03:13:17 +0000 | [diff] [blame] | 352 | Locker machineThreadsLocker { m_vm.heap.machineThreads().getLock() }; |
| 353 | Locker codeBlockSetLocker { m_vm.heap.codeBlockSet().getLock() }; |
| 354 | Locker executableAllocatorLocker { ExecutableAllocator::singleton().getLock() }; |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 355 | std::optional<LockHolder> wasmCalleesLocker; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 356 | #if ENABLE(WEBASSEMBLY) |
mark.lam@apple.com | 9c02581 | 2020-05-26 21:32:50 +0000 | [diff] [blame] | 357 | if (Wasm::isSupported()) |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 358 | wasmCalleesLocker.emplace(Wasm::CalleeRegistry::singleton().getLock()); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 359 | #endif |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 360 | |
utatane.tea@gmail.com | 1e94a26 | 2017-04-12 12:08:29 +0000 | [diff] [blame] | 361 | auto didSuspend = m_jscExecutionThread->suspend(); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 362 | if (didSuspend) { |
| 363 | // While the JSC thread is suspended, we can't do things like malloc because the JSC thread |
| 364 | // may be holding the malloc lock. |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 365 | void* machineFrame; |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 366 | CallFrame* callFrame; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 367 | void* machinePC; |
| 368 | bool topFrameIsLLInt = false; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 369 | RegExp* regExp = nullptr; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 370 | void* llintPC; |
| 371 | { |
utatane.tea@gmail.com | 7111191 | 2017-07-19 08:43:57 +0000 | [diff] [blame] | 372 | PlatformRegisters registers; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 373 | m_jscExecutionThread->getRegisters(registers); |
utatane.tea@gmail.com | 7111191 | 2017-07-19 08:43:57 +0000 | [diff] [blame] | 374 | machineFrame = MachineContext::framePointer(registers); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 375 | callFrame = static_cast<CallFrame*>(machineFrame); |
sbarati@apple.com | 4b79829 | 2018-08-03 00:14:11 +0000 | [diff] [blame] | 376 | auto instructionPointer = MachineContext::instructionPointer(registers); |
| 377 | if (instructionPointer) |
| 378 | machinePC = instructionPointer->untaggedExecutableAddress(); |
| 379 | else |
| 380 | machinePC = nullptr; |
mark.lam@apple.com | 18b4eab | 2018-03-31 07:04:00 +0000 | [diff] [blame] | 381 | llintPC = removeCodePtrTag(MachineContext::llintInstructionPointer(registers)); |
| 382 | assertIsNotTagged(machinePC); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 383 | } |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 384 | |
| 385 | bool shouldAppendTopFrameAsCCode = false; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 386 | // FIXME: Lets have a way of detecting when we're parsing code. |
| 387 | // https://bugs.webkit.org/show_bug.cgi?id=152761 |
sbarati@apple.com | 893729f | 2017-03-29 22:55:53 +0000 | [diff] [blame] | 388 | if (ExecutableAllocator::singleton().isValidExecutableMemory(executableAllocatorLocker, machinePC)) { |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 389 | regExp = m_vm.m_executingRegExp; |
| 390 | if (regExp) |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 391 | callFrame = m_vm.topCallFrame; // We need to do this or else we'd fail our backtrace validation b/c this isn't a JS frame. |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 392 | } else if (LLInt::isLLIntPC(machinePC)) { |
| 393 | topFrameIsLLInt = true; |
| 394 | // We're okay to take a normal stack trace when the PC |
| 395 | // is in LLInt code. |
| 396 | } else { |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 397 | // RegExp evaluation is leaf. So if RegExp evaluation exists, we can say it is RegExp evaluation is the top user-visible frame. |
| 398 | regExp = m_vm.m_executingRegExp; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 399 | // We resort to topCallFrame to see if we can get anything |
| 400 | // useful. We usually get here when we're executing C code. |
| 401 | callFrame = m_vm.topCallFrame; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 402 | if (Options::collectExtraSamplingProfilerData() && !Options::sampleCCode()) |
| 403 | shouldAppendTopFrameAsCCode = true; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | size_t walkSize; |
| 407 | bool wasValidWalk; |
| 408 | bool didRunOutOfVectorSpace; |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 409 | if (Options::sampleCCode()) { |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 410 | CFrameWalker walker(m_vm, machineFrame, callFrame, codeBlockSetLocker, machineThreadsLocker); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 411 | walkSize = walker.walk(m_currentFrames, didRunOutOfVectorSpace); |
| 412 | wasValidWalk = walker.wasValidWalk(); |
| 413 | } else { |
cdumez@apple.com | b261d32 | 2021-05-29 21:08:38 +0000 | [diff] [blame] | 414 | FrameWalker walker(m_vm, callFrame, codeBlockSetLocker, machineThreadsLocker); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 415 | walkSize = walker.walk(m_currentFrames, didRunOutOfVectorSpace); |
| 416 | wasValidWalk = walker.wasValidWalk(); |
| 417 | } |
| 418 | |
| 419 | m_jscExecutionThread->resume(); |
| 420 | |
utatane.tea@gmail.com | 5c7039d | 2017-12-27 00:33:11 +0000 | [diff] [blame] | 421 | auto startTime = MonotonicTime::now(); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 422 | // We can now use data structures that malloc, and do other interesting things, again. |
| 423 | |
| 424 | // FIXME: It'd be interesting to take data about the program's state when |
| 425 | // we fail to take a stack trace: https://bugs.webkit.org/show_bug.cgi?id=152758 |
| 426 | if (wasValidWalk && walkSize) { |
| 427 | if (sReportStats) |
| 428 | sNumTotalStackTraces++; |
| 429 | Vector<UnprocessedStackFrame> stackTrace; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 430 | stackTrace.reserveInitialCapacity(walkSize + !!shouldAppendTopFrameAsCCode); |
| 431 | if (shouldAppendTopFrameAsCCode) |
| 432 | stackTrace.uncheckedAppend(UnprocessedStackFrame { machinePC }); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 433 | for (size_t i = 0; i < walkSize; i++) { |
| 434 | UnprocessedStackFrame frame = m_currentFrames[i]; |
| 435 | stackTrace.uncheckedAppend(frame); |
| 436 | } |
| 437 | |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 438 | m_unprocessedStackTraces.append(UnprocessedStackTrace { nowTime, machinePC, topFrameIsLLInt, llintPC, regExp, WTFMove(stackTrace) }); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 439 | |
| 440 | if (didRunOutOfVectorSpace) |
| 441 | m_currentFrames.grow(m_currentFrames.size() * 1.25); |
| 442 | } |
| 443 | |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 444 | auto endTime = MonotonicTime::now(); |
| 445 | stackTraceProcessingTime = endTime - startTime; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 450 | static ALWAYS_INLINE BytecodeIndex tryGetBytecodeIndex(unsigned llintPC, CodeBlock* codeBlock) |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 451 | { |
ossy@webkit.org | c8cea7b | 2016-02-18 16:45:26 +0000 | [diff] [blame] | 452 | #if ENABLE(DFG_JIT) |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 453 | RELEASE_ASSERT(!codeBlock->hasCodeOrigins()); |
ossy@webkit.org | c8cea7b | 2016-02-18 16:45:26 +0000 | [diff] [blame] | 454 | #endif |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 455 | |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 456 | unsigned bytecodeOffset = llintPC; |
| 457 | if (bytecodeOffset < codeBlock->instructionsSize()) |
| 458 | return BytecodeIndex(bytecodeOffset); |
| 459 | return BytecodeIndex(); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 460 | } |
| 461 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 462 | void SamplingProfiler::processUnverifiedStackTraces() |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 463 | { |
| 464 | // This function needs to be called from the JSC execution thread. |
| 465 | RELEASE_ASSERT(m_lock.isLocked()); |
| 466 | |
| 467 | TinyBloomFilter filter = m_vm.heap.objectSpace().blocks().filter(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 468 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 469 | for (UnprocessedStackTrace& unprocessedStackTrace : m_unprocessedStackTraces) { |
| 470 | m_stackTraces.append(StackTrace()); |
| 471 | StackTrace& stackTrace = m_stackTraces.last(); |
| 472 | stackTrace.timestamp = unprocessedStackTrace.timestamp; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 473 | |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 474 | auto populateCodeLocation = [] (CodeBlock* codeBlock, JITType jitType, BytecodeIndex bytecodeIndex, StackFrame::CodeLocation& location) { |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 475 | if (bytecodeIndex.offset() < codeBlock->instructionsSize()) { |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 476 | int divot; |
| 477 | int startOffset; |
| 478 | int endOffset; |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 479 | codeBlock->expressionRangeForBytecodeIndex(bytecodeIndex, divot, startOffset, endOffset, |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 480 | location.lineNumber, location.columnNumber); |
| 481 | location.bytecodeIndex = bytecodeIndex; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 482 | } |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 483 | if (codeBlock->hasHash()) |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 484 | location.codeBlockHash = codeBlock->hash(); |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 485 | location.jitType = jitType; |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 486 | }; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 487 | |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 488 | auto appendCodeBlock = [&] (CodeBlock* codeBlock, JITType jitType, BytecodeIndex bytecodeIndex) { |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 489 | assertIsHeld(m_lock); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 490 | stackTrace.frames.append(StackFrame(codeBlock->ownerExecutable())); |
| 491 | m_liveCellPointers.add(codeBlock->ownerExecutable()); |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 492 | populateCodeLocation(codeBlock, jitType, bytecodeIndex, stackTrace.frames.last().semanticLocation); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 495 | auto appendEmptyFrame = [&] { |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 496 | stackTrace.frames.append(StackFrame()); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 499 | auto storeCalleeIntoLastFrame = [&] (UnprocessedStackFrame& unprocessedStackFrame) { |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 500 | assertIsHeld(m_lock); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 501 | // Set the callee if it's a valid GC object. |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 502 | CalleeBits calleeBits = unprocessedStackFrame.unverifiedCallee; |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 503 | StackFrame& stackFrame = stackTrace.frames.last(); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 504 | bool alreadyHasExecutable = !!stackFrame.executable; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 505 | #if ENABLE(WEBASSEMBLY) |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 506 | if (calleeBits.isWasm()) { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 507 | stackFrame.frameType = FrameType::Wasm; |
| 508 | stackFrame.wasmIndexOrName = unprocessedStackFrame.wasmIndexOrName; |
| 509 | stackFrame.wasmCompilationMode = unprocessedStackFrame.wasmCompilationMode; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 510 | return; |
| 511 | } |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 512 | #endif |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 513 | |
| 514 | JSValue callee = calleeBits.asCell(); |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 515 | if (!HeapUtil::isValueGCObject(m_vm.heap, filter, callee)) { |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 516 | if (!alreadyHasExecutable) |
| 517 | stackFrame.frameType = FrameType::Unknown; |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 518 | return; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | JSCell* calleeCell = callee.asCell(); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 522 | auto setFallbackFrameType = [&] { |
| 523 | ASSERT(!alreadyHasExecutable); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 524 | FrameType result = FrameType::Unknown; |
ross.kirsling@sony.com | 924e750 | 2020-04-27 09:09:32 +0000 | [diff] [blame] | 525 | auto callData = getCallData(m_vm, calleeCell); |
| 526 | if (callData.type == CallData::Type::Native) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 527 | result = FrameType::Host; |
| 528 | |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 529 | stackFrame.frameType = result; |
| 530 | }; |
| 531 | |
| 532 | auto addCallee = [&] (JSObject* callee) { |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 533 | assertIsHeld(m_lock); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 534 | stackFrame.callee = callee; |
| 535 | m_liveCellPointers.add(callee); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 536 | }; |
| 537 | |
| 538 | if (calleeCell->type() != JSFunctionType) { |
mark.lam@apple.com | 5ba0779 | 2019-08-27 22:14:52 +0000 | [diff] [blame] | 539 | if (JSObject* object = jsDynamicCast<JSObject*>(calleeCell->vm(), calleeCell)) |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 540 | addCallee(object); |
| 541 | |
| 542 | if (!alreadyHasExecutable) |
| 543 | setFallbackFrameType(); |
| 544 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 545 | return; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 546 | } |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 547 | |
| 548 | addCallee(jsCast<JSFunction*>(calleeCell)); |
| 549 | |
| 550 | if (alreadyHasExecutable) |
| 551 | return; |
| 552 | |
| 553 | ExecutableBase* executable = jsCast<JSFunction*>(calleeCell)->executable(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 554 | if (!executable) { |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 555 | setFallbackFrameType(); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 556 | return; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 557 | } |
| 558 | |
fpizlo@apple.com | bc16ddb | 2016-09-06 01:02:22 +0000 | [diff] [blame] | 559 | RELEASE_ASSERT(HeapUtil::isPointerGCObjectJSCell(m_vm.heap, filter, executable)); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 560 | stackFrame.frameType = FrameType::Executable; |
| 561 | stackFrame.executable = executable; |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 562 | m_liveCellPointers.add(executable); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 565 | auto appendCodeOrigin = [&] (CodeBlock* machineCodeBlock, CodeOrigin origin) { |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 566 | assertIsHeld(m_lock); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 567 | size_t startIndex = stackTrace.frames.size(); // We want to change stack traces that we're about to append. |
| 568 | |
| 569 | CodeOrigin machineOrigin; |
| 570 | origin.walkUpInlineStack([&] (const CodeOrigin& codeOrigin) { |
| 571 | machineOrigin = codeOrigin; |
rmorisset@apple.com | b4811e7 | 2019-03-20 20:24:36 +0000 | [diff] [blame] | 572 | auto* inlineCallFrame = codeOrigin.inlineCallFrame(); |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 573 | appendCodeBlock(inlineCallFrame ? inlineCallFrame->baselineCodeBlock.get() : machineCodeBlock, machineCodeBlock->jitType(), codeOrigin.bytecodeIndex()); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 574 | }); |
| 575 | |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 576 | if (Options::collectExtraSamplingProfilerData()) { |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 577 | RELEASE_ASSERT(machineOrigin.isSet()); |
rmorisset@apple.com | b4811e7 | 2019-03-20 20:24:36 +0000 | [diff] [blame] | 578 | RELEASE_ASSERT(!machineOrigin.inlineCallFrame()); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 579 | |
| 580 | StackFrame::CodeLocation machineLocation = stackTrace.frames.last().semanticLocation; |
| 581 | |
| 582 | // We want to tell each inlined frame about the machine frame |
| 583 | // they were inlined into. Currently, we only use this for dumping |
| 584 | // output on the command line, but we could extend it to the web |
| 585 | // inspector in the future if we find a need for it there. |
| 586 | RELEASE_ASSERT(stackTrace.frames.size()); |
sbarati@apple.com | 23c0119 | 2018-09-22 07:28:39 +0000 | [diff] [blame] | 587 | m_liveCellPointers.add(machineCodeBlock); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 588 | for (size_t i = startIndex; i < stackTrace.frames.size() - 1; i++) |
sbarati@apple.com | 23c0119 | 2018-09-22 07:28:39 +0000 | [diff] [blame] | 589 | stackTrace.frames[i].machineLocation = std::make_pair(machineLocation, machineCodeBlock); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 590 | } |
| 591 | }; |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 592 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 593 | // Prepend the top-most inlined frame if needed and gather |
| 594 | // location information about where the top frame is executing. |
| 595 | size_t startIndex = 0; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 596 | if (unprocessedStackTrace.regExp) { |
| 597 | // If the stack-trace is annotated with RegExp, the top-frame must be RegExp since RegExp evaluation is leaf function. |
| 598 | appendEmptyFrame(); |
| 599 | stackTrace.frames.last().regExp = unprocessedStackTrace.regExp; |
| 600 | stackTrace.frames.last().frameType = FrameType::RegExp; |
| 601 | stackTrace.frames.last().semanticLocation.isRegExp = true; |
| 602 | m_liveCellPointers.add(unprocessedStackTrace.regExp); |
| 603 | } else if (!unprocessedStackTrace.frames.isEmpty() && !!unprocessedStackTrace.frames[0].verifiedCodeBlock) { |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 604 | CodeBlock* topCodeBlock = unprocessedStackTrace.frames[0].verifiedCodeBlock; |
| 605 | if (unprocessedStackTrace.topFrameIsLLInt) { |
| 606 | // We reuse LLInt CodeBlocks for the baseline JIT, so we need to check for both jit types. |
| 607 | // This might also be false for various reasons (known and unknown), even though |
| 608 | // it's super unlikely. One reason that this can be false is when we throw from a DFG frame, |
| 609 | // and we end up having to unwind past an EntryFrame, we will end up executing |
ysuzuki@apple.com | 9549c07 | 2020-10-06 22:04:36 +0000 | [diff] [blame] | 610 | // inside the LLInt's llint_handle_ucaught_exception. So we just protect against this |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 611 | // by ignoring it. |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 612 | BytecodeIndex bytecodeIndex = BytecodeIndex(0); |
sbarati@apple.com | 9777f7c | 2019-04-30 03:27:39 +0000 | [diff] [blame] | 613 | if (topCodeBlock->jitType() == JITType::InterpreterThunk || topCodeBlock->jitType() == JITType::BaselineJIT) { |
ysuzuki@apple.com | 5eb5965 | 2020-01-22 20:31:33 +0000 | [diff] [blame] | 614 | unsigned bits = static_cast<unsigned>(bitwise_cast<uintptr_t>(unprocessedStackTrace.llintPC)); |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 615 | bytecodeIndex = tryGetBytecodeIndex(bits, topCodeBlock); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 616 | |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 617 | UNUSED_PARAM(bytecodeIndex); // FIXME: do something with this info for the web inspector: https://bugs.webkit.org/show_bug.cgi?id=153455 |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 618 | |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 619 | appendCodeBlock(topCodeBlock, topCodeBlock->jitType(), bytecodeIndex); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 620 | storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0]); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 621 | startIndex = 1; |
| 622 | } |
yusukesuzuki@slowstart.org | 48bd0a0 | 2018-09-22 05:26:44 +0000 | [diff] [blame] | 623 | } else { |
| 624 | #if ENABLE(JIT) |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 625 | if (std::optional<CodeOrigin> codeOrigin = topCodeBlock->findPC(unprocessedStackTrace.topPC)) { |
yusukesuzuki@slowstart.org | 48bd0a0 | 2018-09-22 05:26:44 +0000 | [diff] [blame] | 626 | appendCodeOrigin(topCodeBlock, *codeOrigin); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 627 | storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0]); |
yusukesuzuki@slowstart.org | 48bd0a0 | 2018-09-22 05:26:44 +0000 | [diff] [blame] | 628 | startIndex = 1; |
| 629 | } |
| 630 | #endif |
| 631 | UNUSED_PARAM(appendCodeOrigin); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
| 635 | for (size_t i = startIndex; i < unprocessedStackTrace.frames.size(); i++) { |
| 636 | UnprocessedStackFrame& unprocessedStackFrame = unprocessedStackTrace.frames[i]; |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 637 | if (CodeBlock* codeBlock = unprocessedStackFrame.verifiedCodeBlock) { |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 638 | CallSiteIndex callSiteIndex = unprocessedStackFrame.callSiteIndex; |
| 639 | |
| 640 | auto appendCodeBlockNoInlining = [&] { |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 641 | appendCodeBlock(codeBlock, codeBlock->jitType(), tryGetBytecodeIndex(callSiteIndex.bits(), codeBlock)); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | #if ENABLE(DFG_JIT) |
| 645 | if (codeBlock->hasCodeOrigins()) { |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 646 | if (codeBlock->canGetCodeOrigin(callSiteIndex)) |
| 647 | appendCodeOrigin(codeBlock, codeBlock->codeOrigin(callSiteIndex)); |
| 648 | else |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 649 | appendCodeBlock(codeBlock, codeBlock->jitType(), BytecodeIndex()); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 650 | } else |
| 651 | appendCodeBlockNoInlining(); |
| 652 | #else |
| 653 | appendCodeBlockNoInlining(); |
| 654 | #endif |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 655 | } else if (unprocessedStackFrame.cCodePC) { |
| 656 | appendEmptyFrame(); |
| 657 | stackTrace.frames.last().cCodePC = unprocessedStackFrame.cCodePC; |
| 658 | stackTrace.frames.last().frameType = FrameType::C; |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 659 | } else |
| 660 | appendEmptyFrame(); |
| 661 | |
| 662 | // Note that this is okay to do if we walked the inline stack because |
| 663 | // the machine frame will be at the top of the processed stack trace. |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 664 | if (!unprocessedStackFrame.cCodePC) |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 665 | storeCalleeIntoLastFrame(unprocessedStackFrame); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 669 | m_unprocessedStackTraces.clear(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 670 | } |
| 671 | |
mark.lam@apple.com | 17ae490 | 2021-02-19 15:51:15 +0000 | [diff] [blame] | 672 | template<typename Visitor> |
| 673 | void SamplingProfiler::visit(Visitor& visitor) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 674 | { |
| 675 | RELEASE_ASSERT(m_lock.isLocked()); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 676 | for (JSCell* cell : m_liveCellPointers) |
mark.lam@apple.com | 15f620c | 2021-02-13 05:30:58 +0000 | [diff] [blame] | 677 | visitor.appendUnbarriered(cell); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 678 | } |
| 679 | |
mark.lam@apple.com | 17ae490 | 2021-02-19 15:51:15 +0000 | [diff] [blame] | 680 | template void SamplingProfiler::visit(AbstractSlotVisitor&); |
| 681 | template void SamplingProfiler::visit(SlotVisitor&); |
| 682 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 683 | void SamplingProfiler::shutdown() |
| 684 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 685 | Locker locker { m_lock }; |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 686 | m_isShutDown = true; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void SamplingProfiler::start() |
| 690 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 691 | Locker locker { m_lock }; |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 692 | startWithLock(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 693 | } |
| 694 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 695 | void SamplingProfiler::startWithLock() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 696 | { |
| 697 | ASSERT(m_lock.isLocked()); |
sbarati@apple.com | 207a683 | 2016-04-06 03:55:11 +0000 | [diff] [blame] | 698 | m_isPaused = false; |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 699 | createThreadIfNecessary(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 700 | } |
| 701 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 702 | void SamplingProfiler::pause() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 703 | { |
| 704 | ASSERT(m_lock.isLocked()); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 705 | m_isPaused = true; |
| 706 | reportStats(); |
| 707 | } |
| 708 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 709 | void SamplingProfiler::noticeCurrentThreadAsJSCExecutionThreadWithLock() |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 710 | { |
| 711 | ASSERT(m_lock.isLocked()); |
utatane.tea@gmail.com | 7111191 | 2017-07-19 08:43:57 +0000 | [diff] [blame] | 712 | m_jscExecutionThread = &Thread::current(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void SamplingProfiler::noticeCurrentThreadAsJSCExecutionThread() |
| 716 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 717 | Locker locker { m_lock }; |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 718 | noticeCurrentThreadAsJSCExecutionThreadWithLock(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 719 | } |
| 720 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 721 | void SamplingProfiler::noticeJSLockAcquisition() |
| 722 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 723 | Locker locker { m_lock }; |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 724 | noticeCurrentThreadAsJSCExecutionThreadWithLock(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | void SamplingProfiler::noticeVMEntry() |
| 728 | { |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 729 | Locker locker { m_lock }; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 730 | ASSERT(m_vm.entryScope); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 731 | noticeCurrentThreadAsJSCExecutionThreadWithLock(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 732 | m_lastTime = m_stopwatch->elapsedTime(); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 733 | createThreadIfNecessary(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 734 | } |
| 735 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 736 | void SamplingProfiler::clearData() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 737 | { |
| 738 | ASSERT(m_lock.isLocked()); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 739 | m_stackTraces.clear(); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 740 | m_liveCellPointers.clear(); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 741 | m_unprocessedStackTraces.clear(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 742 | } |
| 743 | |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 744 | String SamplingProfiler::StackFrame::nameFromCallee(VM& vm) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 745 | { |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 746 | if (!callee) { |
| 747 | if (regExp) |
| 748 | return regExp->toSourceString(); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 749 | return String(); |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 750 | } |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 751 | |
mark.lam@apple.com | e2166a8 | 2021-04-28 17:13:40 +0000 | [diff] [blame] | 752 | DeferTermination deferScope(vm); |
mark.lam@apple.com | 09f92b8 | 2016-09-27 20:32:13 +0000 | [diff] [blame] | 753 | auto scope = DECLARE_CATCH_SCOPE(vm); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 754 | JSGlobalObject* globalObject = callee->globalObject(vm); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 755 | auto getPropertyIfPureOperation = [&] (const Identifier& ident) -> String { |
mark.lam@apple.com | 97021a8 | 2020-07-23 00:08:50 +0000 | [diff] [blame] | 756 | PropertySlot slot(callee, PropertySlot::InternalMethodType::VMInquiry, &vm); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 757 | PropertyName propertyName(ident); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 758 | bool hasProperty = callee->getPropertySlot(globalObject, propertyName, slot); |
mark.lam@apple.com | cce7656 | 2017-05-08 16:56:32 +0000 | [diff] [blame] | 759 | scope.assertNoException(); |
mark.lam@apple.com | 09f92b8 | 2016-09-27 20:32:13 +0000 | [diff] [blame] | 760 | if (hasProperty) { |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 761 | if (slot.isValue()) { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 762 | JSValue nameValue = slot.getValue(globalObject, propertyName); |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 763 | if (isJSString(nameValue)) |
| 764 | return asString(nameValue)->tryGetValue(); |
| 765 | } |
| 766 | } |
| 767 | return String(); |
| 768 | }; |
| 769 | |
| 770 | String name = getPropertyIfPureOperation(vm.propertyNames->displayName); |
| 771 | if (!name.isEmpty()) |
| 772 | return name; |
| 773 | |
| 774 | return getPropertyIfPureOperation(vm.propertyNames->name); |
| 775 | } |
| 776 | |
| 777 | String SamplingProfiler::StackFrame::displayName(VM& vm) |
| 778 | { |
| 779 | { |
| 780 | String name = nameFromCallee(vm); |
| 781 | if (!name.isEmpty()) |
| 782 | return name; |
| 783 | } |
| 784 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 785 | switch (frameType) { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 786 | case FrameType::C: |
utatane.tea@gmail.com | 5795061 | 2017-04-25 02:53:49 +0000 | [diff] [blame] | 787 | #if HAVE(DLADDR) |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 788 | if (frameType == FrameType::C) { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 789 | auto demangled = WTF::StackTrace::demangle(const_cast<void*>(cCodePC)); |
utatane.tea@gmail.com | 5795061 | 2017-04-25 02:53:49 +0000 | [diff] [blame] | 790 | if (demangled) |
| 791 | return String(demangled->demangledName() ? demangled->demangledName() : demangled->mangledName()); |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 792 | WTF::dataLog("couldn't get a name"); |
| 793 | } |
| 794 | #endif |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 795 | return "(unknown C PC)"_s; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 796 | |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 797 | case FrameType::Unknown: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 798 | return "(unknown)"_s; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 799 | |
| 800 | case FrameType::Host: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 801 | return "(host)"_s; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 802 | |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 803 | case FrameType::RegExp: |
| 804 | return "(regexp)"_s; |
| 805 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 806 | case FrameType::Wasm: |
| 807 | #if ENABLE(WEBASSEMBLY) |
| 808 | if (wasmIndexOrName) |
| 809 | return makeString(wasmIndexOrName.value()); |
| 810 | #endif |
| 811 | return "(wasm)"_s; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 812 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 813 | case FrameType::Executable: |
| 814 | if (executable->isHostFunction()) |
| 815 | return static_cast<NativeExecutable*>(executable)->name(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 816 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 817 | if (executable->isFunctionExecutable()) |
| 818 | return static_cast<FunctionExecutable*>(executable)->ecmaName().string(); |
| 819 | if (executable->isProgramExecutable() || executable->isEvalExecutable()) |
| 820 | return "(program)"_s; |
| 821 | if (executable->isModuleProgramExecutable()) |
| 822 | return "(module)"_s; |
| 823 | |
| 824 | RELEASE_ASSERT_NOT_REACHED(); |
| 825 | return String(); |
| 826 | } |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 827 | RELEASE_ASSERT_NOT_REACHED(); |
| 828 | return String(); |
| 829 | } |
| 830 | |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 831 | String SamplingProfiler::StackFrame::displayNameForJSONTests(VM& vm) |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 832 | { |
sbarati@apple.com | 8ec5c26 | 2016-02-04 21:51:40 +0000 | [diff] [blame] | 833 | { |
| 834 | String name = nameFromCallee(vm); |
| 835 | if (!name.isEmpty()) |
| 836 | return name; |
| 837 | } |
| 838 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 839 | switch (frameType) { |
| 840 | case FrameType::Unknown: |
| 841 | case FrameType::C: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 842 | return "(unknown)"_s; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 843 | |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 844 | case FrameType::RegExp: |
| 845 | return "(regexp)"_s; |
| 846 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 847 | case FrameType::Host: |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 848 | return "(host)"_s; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 849 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 850 | case FrameType::Wasm: { |
| 851 | #if ENABLE(WEBASSEMBLY) |
| 852 | if (wasmIndexOrName) |
| 853 | return makeString(wasmIndexOrName.value()); |
| 854 | #endif |
| 855 | return "(wasm)"_s; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 856 | } |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 857 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 858 | case FrameType::Executable: |
| 859 | if (executable->isHostFunction()) |
| 860 | return static_cast<NativeExecutable*>(executable)->name(); |
| 861 | |
| 862 | if (executable->isFunctionExecutable()) { |
| 863 | String result = static_cast<FunctionExecutable*>(executable)->ecmaName().string(); |
| 864 | if (result.isEmpty()) |
| 865 | return "(anonymous function)"_s; |
| 866 | return result; |
| 867 | } |
| 868 | if (executable->isEvalExecutable()) |
| 869 | return "(eval)"_s; |
| 870 | if (executable->isProgramExecutable()) |
| 871 | return "(program)"_s; |
| 872 | if (executable->isModuleProgramExecutable()) |
| 873 | return "(module)"_s; |
| 874 | |
| 875 | RELEASE_ASSERT_NOT_REACHED(); |
| 876 | return String(); |
| 877 | } |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 878 | RELEASE_ASSERT_NOT_REACHED(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 879 | return String(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 880 | } |
| 881 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 882 | int SamplingProfiler::StackFrame::functionStartLine() |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 883 | { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 884 | switch (frameType) { |
| 885 | case FrameType::Unknown: |
| 886 | case FrameType::Host: |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 887 | case FrameType::RegExp: |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 888 | case FrameType::C: |
| 889 | case FrameType::Wasm: |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 890 | return -1; |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 891 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 892 | case FrameType::Executable: |
| 893 | if (executable->isHostFunction()) |
| 894 | return -1; |
| 895 | return static_cast<ScriptExecutable*>(executable)->firstLine(); |
| 896 | } |
| 897 | RELEASE_ASSERT_NOT_REACHED(); |
| 898 | return -1; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 899 | } |
| 900 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 901 | unsigned SamplingProfiler::StackFrame::functionStartColumn() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 902 | { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 903 | switch (frameType) { |
| 904 | case FrameType::Unknown: |
| 905 | case FrameType::Host: |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 906 | case FrameType::RegExp: |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 907 | case FrameType::C: |
| 908 | case FrameType::Wasm: |
peavo@outlook.com | a83d48a | 2016-05-02 21:20:15 +0000 | [diff] [blame] | 909 | return std::numeric_limits<unsigned>::max(); |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 910 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 911 | case FrameType::Executable: |
| 912 | if (executable->isHostFunction()) |
| 913 | return std::numeric_limits<unsigned>::max(); |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 914 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 915 | return static_cast<ScriptExecutable*>(executable)->startColumn(); |
| 916 | } |
| 917 | RELEASE_ASSERT_NOT_REACHED(); |
| 918 | return std::numeric_limits<unsigned>::max(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 919 | } |
| 920 | |
keith_miller@apple.com | c493f8e0 | 2021-10-11 16:58:40 +0000 | [diff] [blame^] | 921 | SourceID SamplingProfiler::StackFrame::sourceID() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 922 | { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 923 | switch (frameType) { |
| 924 | case FrameType::Unknown: |
| 925 | case FrameType::Host: |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 926 | case FrameType::RegExp: |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 927 | case FrameType::C: |
| 928 | case FrameType::Wasm: |
ysuzuki@apple.com | 9f19c43 | 2021-07-15 18:29:47 +0000 | [diff] [blame] | 929 | return internalSourceID; |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 930 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 931 | case FrameType::Executable: |
| 932 | if (executable->isHostFunction()) |
ysuzuki@apple.com | 9f19c43 | 2021-07-15 18:29:47 +0000 | [diff] [blame] | 933 | return internalSourceID; |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 934 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 935 | return static_cast<ScriptExecutable*>(executable)->sourceID(); |
| 936 | } |
| 937 | RELEASE_ASSERT_NOT_REACHED(); |
ysuzuki@apple.com | 9f19c43 | 2021-07-15 18:29:47 +0000 | [diff] [blame] | 938 | return internalSourceID; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | String SamplingProfiler::StackFrame::url() |
| 942 | { |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 943 | switch (frameType) { |
| 944 | case FrameType::Unknown: |
| 945 | case FrameType::Host: |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 946 | case FrameType::RegExp: |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 947 | case FrameType::C: |
| 948 | case FrameType::Wasm: |
utatane.tea@gmail.com | 988a375 | 2018-01-29 10:43:13 +0000 | [diff] [blame] | 949 | return emptyString(); |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 950 | case FrameType::Executable: |
| 951 | if (executable->isHostFunction()) |
| 952 | return emptyString(); |
jlewis3@apple.com | 5d712de | 2018-01-29 17:47:30 +0000 | [diff] [blame] | 953 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 954 | String url = static_cast<ScriptExecutable*>(executable)->sourceURL(); |
| 955 | if (url.isEmpty()) |
| 956 | return static_cast<ScriptExecutable*>(executable)->source().provider()->sourceURLDirective(); // Fall back to sourceURL directive. |
| 957 | return url; |
| 958 | } |
| 959 | RELEASE_ASSERT_NOT_REACHED(); |
| 960 | return String(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 961 | } |
| 962 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 963 | Vector<SamplingProfiler::StackTrace> SamplingProfiler::releaseStackTraces() |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 964 | { |
| 965 | ASSERT(m_lock.isLocked()); |
| 966 | { |
| 967 | HeapIterationScope heapIterationScope(m_vm.heap); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 968 | processUnverifiedStackTraces(); |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 969 | } |
| 970 | |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 971 | Vector<StackTrace> result(WTFMove(m_stackTraces)); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 972 | clearData(); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 973 | return result; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | String SamplingProfiler::stackTracesAsJSON() |
| 977 | { |
fpizlo@apple.com | 0ef4395 | 2016-12-08 22:14:50 +0000 | [diff] [blame] | 978 | DeferGC deferGC(m_vm.heap); |
cdumez@apple.com | 6c3db6c | 2021-05-22 03:13:17 +0000 | [diff] [blame] | 979 | Locker locker { m_lock }; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 980 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 981 | { |
| 982 | HeapIterationScope heapIterationScope(m_vm.heap); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 983 | processUnverifiedStackTraces(); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | StringBuilder json; |
commit-queue@webkit.org | 13c7bcc | 2016-03-02 04:30:45 +0000 | [diff] [blame] | 987 | json.append('['); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 988 | |
| 989 | bool loopedOnce = false; |
| 990 | auto comma = [&] { |
| 991 | if (loopedOnce) |
commit-queue@webkit.org | 13c7bcc | 2016-03-02 04:30:45 +0000 | [diff] [blame] | 992 | json.append(','); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 993 | }; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 994 | for (StackTrace& stackTrace : m_stackTraces) { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 995 | comma(); |
commit-queue@webkit.org | 13c7bcc | 2016-03-02 04:30:45 +0000 | [diff] [blame] | 996 | json.append('['); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 997 | loopedOnce = false; |
sbarati@apple.com | 806ca4a | 2016-01-20 21:51:00 +0000 | [diff] [blame] | 998 | for (StackFrame& stackFrame : stackTrace.frames) { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 999 | comma(); |
mark.lam@apple.com | f051557 | 2019-02-15 21:41:15 +0000 | [diff] [blame] | 1000 | json.appendQuotedJSONString(stackFrame.displayNameForJSONTests(m_vm)); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1001 | loopedOnce = true; |
| 1002 | } |
commit-queue@webkit.org | 13c7bcc | 2016-03-02 04:30:45 +0000 | [diff] [blame] | 1003 | json.append(']'); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1004 | loopedOnce = true; |
| 1005 | } |
| 1006 | |
commit-queue@webkit.org | 13c7bcc | 2016-03-02 04:30:45 +0000 | [diff] [blame] | 1007 | json.append(']'); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1008 | |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 1009 | clearData(); |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 1010 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1011 | return json.toString(); |
| 1012 | } |
| 1013 | |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1014 | void SamplingProfiler::registerForReportAtExit() |
| 1015 | { |
utatane.tea@gmail.com | e71a872 | 2018-04-05 17:22:21 +0000 | [diff] [blame] | 1016 | static Lock registrationLock; |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1017 | static HashSet<RefPtr<SamplingProfiler>>* profilesToReport; |
| 1018 | |
cdumez@apple.com | 3e035a8 | 2021-05-22 16:49:42 +0000 | [diff] [blame] | 1019 | Locker locker { registrationLock }; |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1020 | |
| 1021 | if (!profilesToReport) { |
| 1022 | profilesToReport = new HashSet<RefPtr<SamplingProfiler>>(); |
| 1023 | atexit([]() { |
ddkilzer@apple.com | fa7f50c | 2019-09-21 11:39:57 +0000 | [diff] [blame] | 1024 | for (const auto& profile : *profilesToReport) |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1025 | profile->reportDataToOptionFile(); |
| 1026 | }); |
| 1027 | } |
| 1028 | |
| 1029 | profilesToReport->add(adoptRef(this)); |
| 1030 | m_needsReportAtExit = true; |
| 1031 | } |
| 1032 | |
| 1033 | void SamplingProfiler::reportDataToOptionFile() |
| 1034 | { |
| 1035 | if (m_needsReportAtExit) { |
| 1036 | m_needsReportAtExit = false; |
tzagallo@apple.com | a4c4922 | 2019-09-16 20:48:37 +0000 | [diff] [blame] | 1037 | JSLockHolder holder(m_vm); |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1038 | const char* path = Options::samplingProfilerPath(); |
| 1039 | StringPrintStream pathOut; |
| 1040 | pathOut.print(path, "/"); |
| 1041 | pathOut.print("JSCSampilingProfile-", reinterpret_cast<uintptr_t>(this), ".txt"); |
| 1042 | auto out = FilePrintStream::open(pathOut.toCString().data(), "w"); |
| 1043 | reportTopFunctions(*out); |
| 1044 | reportTopBytecodes(*out); |
| 1045 | } |
| 1046 | } |
| 1047 | |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1048 | void SamplingProfiler::reportTopFunctions() |
| 1049 | { |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1050 | reportTopFunctions(WTF::dataFile()); |
| 1051 | } |
| 1052 | |
| 1053 | void SamplingProfiler::reportTopFunctions(PrintStream& out) |
| 1054 | { |
cdumez@apple.com | 6c3db6c | 2021-05-22 03:13:17 +0000 | [diff] [blame] | 1055 | Locker locker { m_lock }; |
sbarati@apple.com | 23c0119 | 2018-09-22 07:28:39 +0000 | [diff] [blame] | 1056 | DeferGCForAWhile deferGC(m_vm.heap); |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1057 | |
| 1058 | { |
| 1059 | HeapIterationScope heapIterationScope(m_vm.heap); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 1060 | processUnverifiedStackTraces(); |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1063 | size_t totalSamples = 0; |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1064 | HashMap<String, size_t> functionCounts; |
| 1065 | for (StackTrace& stackTrace : m_stackTraces) { |
| 1066 | if (!stackTrace.frames.size()) |
| 1067 | continue; |
| 1068 | |
| 1069 | StackFrame& frame = stackTrace.frames.first(); |
sbarati@apple.com | c7ad3d1 | 2020-09-03 22:47:33 +0000 | [diff] [blame] | 1070 | String hash = ""_s; |
| 1071 | if (frame.semanticLocation.hasCodeBlockHash()) { |
| 1072 | StringPrintStream stream; |
| 1073 | frame.semanticLocation.codeBlockHash.dump(stream); |
| 1074 | hash = stream.toString(); |
| 1075 | } else |
| 1076 | hash = "<nil>"_s; |
ysuzuki@apple.com | 9f19c43 | 2021-07-15 18:29:47 +0000 | [diff] [blame] | 1077 | intptr_t sourceID = frame.sourceID(); |
| 1078 | if (Options::samplingProfilerIgnoreExternalSourceID()) { |
| 1079 | if (sourceID != internalSourceID) |
| 1080 | sourceID = aggregatedExternalSourceID; |
| 1081 | } |
| 1082 | auto frameDescription = makeString(frame.displayName(m_vm), '#', hash, ':', sourceID); |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1083 | functionCounts.add(frameDescription, 0).iterator->value++; |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1084 | totalSamples++; |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | auto takeMax = [&] () -> std::pair<String, size_t> { |
| 1088 | String maxFrameDescription; |
| 1089 | size_t maxFrameCount = 0; |
ddkilzer@apple.com | fa7f50c | 2019-09-21 11:39:57 +0000 | [diff] [blame] | 1090 | for (const auto& entry : functionCounts) { |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1091 | if (entry.value > maxFrameCount) { |
| 1092 | maxFrameCount = entry.value; |
| 1093 | maxFrameDescription = entry.key; |
| 1094 | } |
| 1095 | } |
| 1096 | if (!maxFrameDescription.isEmpty()) |
| 1097 | functionCounts.remove(maxFrameDescription); |
| 1098 | return std::make_pair(maxFrameDescription, maxFrameCount); |
| 1099 | }; |
| 1100 | |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1101 | if (Options::samplingProfilerTopFunctionsCount()) { |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1102 | out.println("\n\nSampling rate: ", m_timingInterval.microseconds(), " microseconds. Total samples: ", totalSamples); |
| 1103 | out.println("Top functions as <numSamples 'functionName#hash:sourceID'>"); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1104 | for (size_t i = 0; i < Options::samplingProfilerTopFunctionsCount(); i++) { |
| 1105 | auto pair = takeMax(); |
| 1106 | if (pair.first.isEmpty()) |
| 1107 | break; |
| 1108 | out.printf("%6zu ", pair.second); |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1109 | out.println(" '", pair.first, "'"); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1110 | } |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | void SamplingProfiler::reportTopBytecodes() |
| 1115 | { |
keith_miller@apple.com | 3517aa4 | 2016-05-24 23:03:09 +0000 | [diff] [blame] | 1116 | reportTopBytecodes(WTF::dataFile()); |
| 1117 | } |
| 1118 | |
| 1119 | void SamplingProfiler::reportTopBytecodes(PrintStream& out) |
| 1120 | { |
cdumez@apple.com | 6c3db6c | 2021-05-22 03:13:17 +0000 | [diff] [blame] | 1121 | Locker locker { m_lock }; |
sbarati@apple.com | 23c0119 | 2018-09-22 07:28:39 +0000 | [diff] [blame] | 1122 | DeferGCForAWhile deferGC(m_vm.heap); |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1123 | |
| 1124 | { |
| 1125 | HeapIterationScope heapIterationScope(m_vm.heap); |
cdumez@apple.com | 2f48169 | 2021-05-29 21:14:39 +0000 | [diff] [blame] | 1126 | processUnverifiedStackTraces(); |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1129 | size_t totalSamples = 0; |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1130 | HashMap<String, size_t> bytecodeCounts; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1131 | HashMap<String, size_t> tierCounts; |
| 1132 | |
| 1133 | String llint = "LLInt"_s; |
| 1134 | String baseline = "Baseline"_s; |
| 1135 | String dfg = "DFG"_s; |
| 1136 | String ftl = "FTL"_s; |
| 1137 | String builtin = "js builtin"_s; |
| 1138 | String wasm = "Wasm"_s; |
| 1139 | String host = "Host"_s; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1140 | String regexp = "RegExp"_s; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1141 | String cpp = "C/C++"_s; |
| 1142 | String unknownFrame = "Unknown Frame"_s; |
| 1143 | String unknownExecutable = "Unknown Executable"_s; |
| 1144 | |
| 1145 | auto forEachTier = [&] (auto func) { |
| 1146 | func(llint); |
| 1147 | func(baseline); |
| 1148 | func(dfg); |
| 1149 | func(ftl); |
| 1150 | func(builtin); |
| 1151 | func(wasm); |
| 1152 | func(host); |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1153 | func(regexp); |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1154 | func(cpp); |
| 1155 | func(unknownFrame); |
| 1156 | func(unknownExecutable); |
| 1157 | }; |
| 1158 | |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1159 | for (StackTrace& stackTrace : m_stackTraces) { |
| 1160 | if (!stackTrace.frames.size()) |
| 1161 | continue; |
| 1162 | |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 1163 | auto descriptionForLocation = [&] (StackFrame::CodeLocation location, std::optional<Wasm::CompilationMode> wasmCompilationMode) -> String { |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1164 | String bytecodeIndex; |
| 1165 | String codeBlockHash; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 1166 | String jitType; |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1167 | if (location.hasBytecodeIndex()) |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 1168 | bytecodeIndex = toString(location.bytecodeIndex); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1169 | else |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1170 | bytecodeIndex = "<nil>"_s; |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1171 | |
| 1172 | if (location.hasCodeBlockHash()) { |
| 1173 | StringPrintStream stream; |
| 1174 | location.codeBlockHash.dump(stream); |
| 1175 | codeBlockHash = stream.toString(); |
| 1176 | } else |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1177 | codeBlockHash = "<nil>"_s; |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1178 | |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 1179 | if (wasmCompilationMode) |
| 1180 | jitType = Wasm::makeString(wasmCompilationMode.value()); |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1181 | else if (location.isRegExp) |
| 1182 | jitType = "RegExp"_s; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 1183 | else |
| 1184 | jitType = JITCode::typeName(location.jitType); |
| 1185 | |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1186 | return makeString('#', codeBlockHash, ':', jitType, ':', bytecodeIndex); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1187 | }; |
| 1188 | |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1189 | StackFrame& frame = stackTrace.frames.first(); |
darin@apple.com | e1c00f7 | 2021-05-24 21:51:47 +0000 | [diff] [blame] | 1190 | auto frameDescription = makeString(frame.displayName(m_vm), descriptionForLocation(frame.semanticLocation, frame.wasmCompilationMode)); |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 1191 | if (std::optional<std::pair<StackFrame::CodeLocation, CodeBlock*>> machineLocation = frame.machineLocation) { |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1192 | frameDescription = makeString(frameDescription, " <-- ", |
darin@apple.com | 7c840b6 | 2021-05-28 01:26:23 +0000 | [diff] [blame] | 1193 | machineLocation->second->inferredName().data(), descriptionForLocation(machineLocation->first, std::nullopt)); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1194 | } |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1195 | bytecodeCounts.add(frameDescription, 0).iterator->value++; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1196 | |
| 1197 | { |
| 1198 | String tierName; |
| 1199 | switch (frame.frameType) { |
| 1200 | case SamplingProfiler::FrameType::Executable: |
| 1201 | switch (frame.semanticLocation.jitType) { |
| 1202 | case JITType::HostCallThunk: |
| 1203 | tierName = host; |
| 1204 | break; |
| 1205 | case JITType::InterpreterThunk: |
| 1206 | tierName = llint; |
| 1207 | break; |
| 1208 | case JITType::BaselineJIT: |
| 1209 | tierName = baseline; |
| 1210 | break; |
| 1211 | case JITType::DFGJIT: |
| 1212 | tierName = dfg; |
| 1213 | break; |
| 1214 | case JITType::FTLJIT: |
| 1215 | tierName = ftl; |
| 1216 | break; |
| 1217 | default: |
| 1218 | tierName = unknownExecutable; |
| 1219 | break; |
| 1220 | } |
| 1221 | |
| 1222 | if (frame.executable) { |
| 1223 | if (auto* executable = jsDynamicCast<FunctionExecutable*>(m_vm, frame.executable)) { |
| 1224 | if (executable->isBuiltinFunction()) |
| 1225 | tierCounts.add(builtin, 0).iterator->value++; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | break; |
| 1230 | case SamplingProfiler::FrameType::Wasm: |
| 1231 | tierName = wasm; |
| 1232 | break; |
| 1233 | case SamplingProfiler::FrameType::Host: |
| 1234 | tierName = host; |
| 1235 | break; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1236 | case SamplingProfiler::FrameType::RegExp: |
| 1237 | tierName = regexp; |
| 1238 | break; |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1239 | case SamplingProfiler::FrameType::C: |
| 1240 | tierName = cpp; |
| 1241 | break; |
| 1242 | case SamplingProfiler::FrameType::Unknown: |
| 1243 | tierName = unknownFrame; |
| 1244 | break; |
| 1245 | } |
| 1246 | |
| 1247 | tierCounts.add(tierName, 0).iterator->value++; |
| 1248 | } |
| 1249 | |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1250 | totalSamples++; |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | auto takeMax = [&] () -> std::pair<String, size_t> { |
| 1254 | String maxFrameDescription; |
| 1255 | size_t maxFrameCount = 0; |
ddkilzer@apple.com | fa7f50c | 2019-09-21 11:39:57 +0000 | [diff] [blame] | 1256 | for (const auto& entry : bytecodeCounts) { |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1257 | if (entry.value > maxFrameCount) { |
| 1258 | maxFrameCount = entry.value; |
| 1259 | maxFrameDescription = entry.key; |
| 1260 | } |
| 1261 | } |
| 1262 | if (!maxFrameDescription.isEmpty()) |
| 1263 | bytecodeCounts.remove(maxFrameDescription); |
| 1264 | return std::make_pair(maxFrameDescription, maxFrameCount); |
| 1265 | }; |
| 1266 | |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1267 | if (Options::samplingProfilerTopBytecodesCount()) { |
sbarati@apple.com | 783a68c | 2021-04-29 17:42:13 +0000 | [diff] [blame] | 1268 | out.println("\n\nSampling rate: ", m_timingInterval.microseconds(), " microseconds. Total samples: ", totalSamples, "\n"); |
| 1269 | |
| 1270 | out.println("Tier breakdown:"); |
| 1271 | out.println("-----------------------------------"); |
| 1272 | unsigned maxTierNameLength = 0; |
| 1273 | forEachTier([&] (String tier) { |
| 1274 | maxTierNameLength = std::max(maxTierNameLength, tier.length()); |
| 1275 | }); |
| 1276 | auto printTier = [&] (String tier) { |
| 1277 | size_t count = tierCounts.get(tier); |
| 1278 | if (!count && (tier == unknownFrame || tier == unknownExecutable)) |
| 1279 | return; |
| 1280 | out.print(tier, ": "); |
| 1281 | for (unsigned i = 0; i < maxTierNameLength + 2 - tier.length(); ++i) |
| 1282 | out.print(" "); |
| 1283 | out.printf("%6zu ", count); |
| 1284 | out.println(" (", (static_cast<double>(count) / static_cast<double>(totalSamples)) * 100, "%)"); |
| 1285 | }; |
| 1286 | forEachTier(printTier); |
| 1287 | out.println("\n"); |
| 1288 | |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1289 | out.println("Hottest bytecodes as <numSamples 'functionName#hash:JITType:bytecodeIndex'>"); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1290 | for (size_t i = 0; i < Options::samplingProfilerTopBytecodesCount(); i++) { |
| 1291 | auto pair = takeMax(); |
| 1292 | if (pair.first.isEmpty()) |
| 1293 | break; |
| 1294 | out.printf("%6zu ", pair.second); |
keith_miller@apple.com | 5eaa04d | 2020-11-09 21:18:08 +0000 | [diff] [blame] | 1295 | out.println(" '", pair.first, "'"); |
sbarati@apple.com | 65f8e6e | 2017-01-28 01:04:06 +0000 | [diff] [blame] | 1296 | } |
sbarati@apple.com | 10ec78a | 2016-04-20 02:24:53 +0000 | [diff] [blame] | 1297 | } |
| 1298 | } |
| 1299 | |
carlosgc@webkit.org | 12f1483 | 2020-09-01 08:55:06 +0000 | [diff] [blame] | 1300 | Thread* SamplingProfiler::thread() const |
commit-queue@webkit.org | b181ba9 | 2019-01-25 23:45:04 +0000 | [diff] [blame] | 1301 | { |
carlosgc@webkit.org | 12f1483 | 2020-09-01 08:55:06 +0000 | [diff] [blame] | 1302 | return m_thread.get(); |
commit-queue@webkit.org | b181ba9 | 2019-01-25 23:45:04 +0000 | [diff] [blame] | 1303 | } |
commit-queue@webkit.org | b181ba9 | 2019-01-25 23:45:04 +0000 | [diff] [blame] | 1304 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1305 | } // namespace JSC |
| 1306 | |
| 1307 | namespace WTF { |
| 1308 | |
| 1309 | using namespace JSC; |
| 1310 | |
| 1311 | void printInternal(PrintStream& out, SamplingProfiler::FrameType frameType) |
| 1312 | { |
| 1313 | switch (frameType) { |
sbarati@apple.com | d3d0c00 | 2016-01-30 01:11:05 +0000 | [diff] [blame] | 1314 | case SamplingProfiler::FrameType::Executable: |
| 1315 | out.print("Executable"); |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1316 | break; |
ysuzuki@apple.com | 32e4305 | 2019-08-02 22:58:09 +0000 | [diff] [blame] | 1317 | case SamplingProfiler::FrameType::Wasm: |
| 1318 | out.print("Wasm"); |
| 1319 | break; |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1320 | case SamplingProfiler::FrameType::Host: |
| 1321 | out.print("Host"); |
| 1322 | break; |
ysuzuki@apple.com | 420d9a9 | 2021-07-16 04:10:49 +0000 | [diff] [blame] | 1323 | case SamplingProfiler::FrameType::RegExp: |
| 1324 | out.print("RegExp"); |
| 1325 | break; |
keith_miller@apple.com | b4a8644 | 2017-02-02 01:23:37 +0000 | [diff] [blame] | 1326 | case SamplingProfiler::FrameType::C: |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 1327 | case SamplingProfiler::FrameType::Unknown: |
| 1328 | out.print("Unknown"); |
| 1329 | break; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | } // namespace WTF |
| 1334 | |
| 1335 | #endif // ENABLE(SAMPLING_PROFILER) |