Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"target_name": "dd_pprof",
"sources": [
"bindings/profilers/heap.cc",
"bindings/profilers/near-oom.cc",
"bindings/profilers/wall.cc",
"bindings/per-isolate-data.cc",
"bindings/thread-cpu-clock.cc",
Expand Down Expand Up @@ -40,6 +41,7 @@
"target_name": "test_dd_pprof",
"sources": [
"bindings/profilers/heap.cc",
"bindings/profilers/near-oom.cc",
"bindings/profilers/wall.cc",
"bindings/per-isolate-data.cc",
"bindings/thread-cpu-clock.cc",
Expand Down
492 changes: 297 additions & 195 deletions bindings/otel-thread-ctx.cc

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions bindings/per-isolate-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <cassert>
#include <mutex>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -64,4 +65,22 @@ std::shared_ptr<HeapProfilerState>& PerIsolateData::GetHeapProfilerState() {
return heap_profiler_state;
}

#if DD_V8_HAS_DICTIONARY_TEMPLATE
v8::Local<v8::DictionaryTemplate> PerIsolateData::GetDictionaryTemplate(
v8::Isolate* isolate,
DictionaryTemplateId id,
v8::MemorySpan<const std::string_view> names) {
const size_t index = static_cast<size_t>(id);
auto& tmpl = dictionary_templates[index];
auto& arity = dictionary_template_arities[index];
if (tmpl.IsEmpty()) {
arity = names.size();
tmpl.Reset(v8::DictionaryTemplate::New(isolate, names));
} else {
assert(arity == names.size());
}
return Nan::New(tmpl);
}
#endif

} // namespace dd
32 changes: 32 additions & 0 deletions bindings/per-isolate-data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,45 @@

#include <nan.h>
#include <node.h>
#include <v8-version.h>
#include <v8.h>
#include <array>
#include <cstddef>
#include <memory>
#include <string_view>

// v8::DictionaryTemplate landed in V8 12.3, i.e. Node.js >= 22.
#if V8_MAJOR_VERSION > 12 || (V8_MAJOR_VERSION == 12 && V8_MINOR_VERSION >= 3)
#define DD_V8_HAS_DICTIONARY_TEMPLATE 1
#else
#define DD_V8_HAS_DICTIONARY_TEMPLATE 0
#endif

namespace dd {

struct HeapProfilerState;

#if DD_V8_HAS_DICTIONARY_TEMPLATE
enum class DictionaryTemplateId : size_t {
kWallSampleContext,
kCount,
};

constexpr size_t kDictionaryTemplateCount =
static_cast<size_t>(DictionaryTemplateId::kCount);
#endif

class PerIsolateData {
private:
Nan::Global<v8::Function> wall_profiler_constructor;
Nan::Global<v8::Function> allocation_node_constructor;
Nan::Global<v8::Function> time_profile_node_constructor;
std::shared_ptr<HeapProfilerState> heap_profiler_state;
#if DD_V8_HAS_DICTIONARY_TEMPLATE
std::array<Nan::Global<v8::DictionaryTemplate>, kDictionaryTemplateCount>
dictionary_templates;
std::array<size_t, kDictionaryTemplateCount> dictionary_template_arities{};
#endif

PerIsolateData() {}

Expand All @@ -41,6 +67,12 @@ class PerIsolateData {
Nan::Global<v8::Function>& AllocationNodeConstructor();
Nan::Global<v8::Function>& TimeProfileNodeConstructor();
std::shared_ptr<HeapProfilerState>& GetHeapProfilerState();
#if DD_V8_HAS_DICTIONARY_TEMPLATE
v8::Local<v8::DictionaryTemplate> GetDictionaryTemplate(
v8::Isolate* isolate,
DictionaryTemplateId id,
v8::MemorySpan<const std::string_view> names);
#endif
};

} // namespace dd
Loading
Loading