Skip to content

Commit

Permalink
Add binding for source-mapping sampling profiler traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Aug 27, 2024
1 parent 8267d95 commit 3e6ea14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,15 @@ Ref<JSON::Value> SamplingProfiler::stackTracesAsJSON()
result->setDouble("sourceID"_s, sourceID);
result->setString("name"_s, stackFrame.displayName(m_vm));
result->setString("location"_s, descriptionForLocation(stackFrame.semanticLocation, stackFrame.wasmCompilationMode, stackFrame.wasmOffset));
result->setDouble("line"_s, stackFrame.semanticLocation.lineColumn.line);
result->setDouble("column"_s, stackFrame.semanticLocation.lineColumn.column);
LineColumn sourceMappedLineColumn = stackFrame.semanticLocation.lineColumn;
if (provider) {
auto& fn = m_vm.computeLineColumnWithSourcemap();
if (fn) {
fn(m_vm, provider, sourceMappedLineColumn);
}
}
result->setDouble("line"_s, sourceMappedLineColumn.line);
result->setDouble("column"_s, sourceMappedLineColumn.column);
result->setString("category"_s, tierName(stackFrame));
uint32_t flags = 0;
if (stackFrame.frameType == SamplingProfiler::FrameType::Executable && stackFrame.executable) {
Expand All @@ -1112,8 +1119,15 @@ Ref<JSON::Value> SamplingProfiler::stackTracesAsJSON()
auto inliner = JSON::Object::create();
inliner->setString("name"_s, String::fromUTF8(machineLocation->second->inferredName().span()));
inliner->setString("location"_s, descriptionForLocation(machineLocation->first, std::nullopt, BytecodeIndex()));
inliner->setDouble("line"_s, machineLocation->first.lineColumn.line);
inliner->setDouble("column"_s, machineLocation->first.lineColumn.column);
LineColumn sourceMappedLineColumn = machineLocation->first.lineColumn;
if (provider) {
auto& fn = m_vm.computeLineColumnWithSourcemap();
if (fn) {
fn(m_vm, provider, sourceMappedLineColumn);
}
}
inliner->setDouble("line"_s, sourceMappedLineColumn.line);
inliner->setDouble("column"_s, sourceMappedLineColumn.column);
inliner->setString("category"_s, tierName(stackFrame));
result->setValue("inliner"_s, WTFMove(inliner));
}
Expand Down
6 changes: 6 additions & 0 deletions Source/JavaScriptCore/runtime/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
#include <wtf/text/SymbolImpl.h>
#include <wtf/text/SymbolRegistry.h>

#include "LineColumn.h"

#if ENABLE(REGEXP_TRACING)
#include <wtf/ListHashSet.h>
#endif
Expand Down Expand Up @@ -929,6 +931,9 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {
DrainMicrotaskDelayScope drainMicrotaskDelayScope() { return DrainMicrotaskDelayScope { *this }; }
JS_EXPORT_PRIVATE void drainMicrotasks();
void setOnEachMicrotaskTick(WTF::Function<void(VM&)>&& func) { m_onEachMicrotaskTick = WTFMove(func); }

WTF::Function<void(VM&, SourceProvider*, LineColumn&)>& computeLineColumnWithSourcemap() { return m_computeLineColumnWithSourcemap; }
void setComputeLineColumnWithSourcemap(WTF::Function<void(VM&, SourceProvider*, LineColumn&)>&& func) { m_computeLineColumnWithSourcemap = WTFMove(func); }

WTF::Function<String(VM&, Vector<StackFrame>& stackTrace, unsigned &line, unsigned &column, String& sourceURL, JSC::JSObject*)>& onComputeErrorInfo() { return m_onComputeErrorInfo; }
void setOnComputeErrorInfo(WTF::Function<String(VM&, Vector<StackFrame>& stackTrace, unsigned &line, unsigned &column, String& sourceURL, JSC::JSObject*)>&& func) { m_onComputeErrorInfo = WTFMove(func); }
Expand Down Expand Up @@ -1131,6 +1136,7 @@ class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> {

WTF::Function<void(VM&)> m_onEachMicrotaskTick;
WTF::Function<String(VM&, Vector<StackFrame>& stackTrace, unsigned &line, unsigned &column, String& sourceURL, JSC::JSObject*)> m_onComputeErrorInfo;
WTF::Function<void(VM&, SourceProvider*, LineColumn&)> m_computeLineColumnWithSourcemap;
uintptr_t m_currentWeakRefVersion { 0 };

bool m_hasSideData { false };
Expand Down

0 comments on commit 3e6ea14

Please sign in to comment.