|
| 1 | +#include "node_tracing.h" |
| 2 | +#include "base_object-inl.h" |
| 3 | +#include "env-inl.h" |
| 4 | +#include "memory_tracker-inl.h" |
| 5 | +#include "node.h" |
| 6 | +#include "node_external_reference.h" |
| 7 | +#include "node_internals.h" |
| 8 | +#include "node_v8_platform-inl.h" |
| 9 | +#include "tracing/agent.h" |
| 10 | +#include "util-inl.h" |
| 11 | +#include "v8.h" |
| 12 | + |
| 13 | +#include <set> |
| 14 | +#include <string> |
| 15 | +#include <numeric> |
| 16 | + |
| 17 | +namespace node { |
| 18 | +namespace tracing { |
| 19 | + |
| 20 | +using v8::Context; |
| 21 | +using v8::FunctionTemplate; |
| 22 | +using v8::HandleScope; |
| 23 | +using v8::Isolate; |
| 24 | +using v8::Local; |
| 25 | +using v8::Value; |
| 26 | +using v8::Object; |
| 27 | +using v8::String; |
| 28 | +using v8::Uint8Array; |
| 29 | + |
| 30 | +void BindingData::MemoryInfo(MemoryTracker* tracker) const {} |
| 31 | + |
| 32 | +BindingData::BindingData(Realm* realm, v8::Local<v8::Object> object) |
| 33 | + : SnapshotableObject(realm, object, type_int) { |
| 34 | + |
| 35 | + // get the pointer of the memory for the flag that store if trace is enabled for http |
| 36 | + // the pointer will always be the same and if the category does not exist, it creates: https://github.com/nodejs/node/blob/6bbf2a57fcf33266c5859497f8cc32e1389a358a/deps/v8/src/libplatform/tracing/tracing-controller.cc#L322-L342 |
| 37 | + auto p = const_cast<uint8_t*>(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("node.http")); |
| 38 | + |
| 39 | + auto nop = [](void*, size_t, void*) {}; // no-op deleter |
| 40 | + auto bs = v8::ArrayBuffer::NewBackingStore(p, 1, nop, nullptr); |
| 41 | + auto ab = v8::ArrayBuffer::New(realm->isolate(), std::move(bs)); |
| 42 | + v8::Local<Uint8Array> u8 = v8::Uint8Array::New(ab, 0, 1); |
| 43 | + |
| 44 | + object |
| 45 | + ->Set(realm->context(), |
| 46 | + FIXED_ONE_BYTE_STRING(realm->isolate(), "tracingCategories"), |
| 47 | + u8) |
| 48 | + .Check(); |
| 49 | +} |
| 50 | + |
| 51 | +bool BindingData::PrepareForSerialization(v8::Local<v8::Context> context, |
| 52 | + v8::SnapshotCreator* creator) { |
| 53 | + return true; |
| 54 | +} |
| 55 | + |
| 56 | +InternalFieldInfoBase* BindingData::Serialize(int index) { |
| 57 | + DCHECK_EQ(index, BaseObject::kEmbedderType); |
| 58 | + InternalFieldInfo* info = |
| 59 | + InternalFieldInfoBase::New<InternalFieldInfo>(type()); |
| 60 | + return info; |
| 61 | +} |
| 62 | + |
| 63 | +void BindingData::Deserialize(v8::Local<v8::Context> context, |
| 64 | + v8::Local<v8::Object> holder, |
| 65 | + int index, |
| 66 | + InternalFieldInfoBase* info) { |
| 67 | + DCHECK_EQ(index, BaseObject::kEmbedderType); |
| 68 | + v8::HandleScope scope(context->GetIsolate()); |
| 69 | + Realm* realm = Realm::GetCurrent(context); |
| 70 | + BindingData* binding = realm->AddBindingData<BindingData>(context, holder); |
| 71 | + CHECK_NOT_NULL(binding); |
| 72 | +} |
| 73 | + |
| 74 | +void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, |
| 75 | + Local<FunctionTemplate> ctor) {} |
| 76 | + |
| 77 | +void BindingData::CreatePerContextProperties(Local<Object> target, |
| 78 | + Local<Value> unused, |
| 79 | + Local<Context> context, |
| 80 | + void* priv) { |
| 81 | + Realm* realm = Realm::GetCurrent(context); |
| 82 | + realm->AddBindingData<BindingData>(context, target); |
| 83 | +} |
| 84 | + |
| 85 | +void BindingData::RegisterExternalReferences(ExternalReferenceRegistry* registry) {} |
| 86 | + |
| 87 | +} // namespace tracing |
| 88 | + |
| 89 | +} // node |
| 90 | + |
| 91 | +NODE_BINDING_CONTEXT_AWARE_INTERNAL( |
| 92 | + tracing, node::tracing::BindingData::CreatePerContextProperties) |
| 93 | +NODE_BINDING_PER_ISOLATE_INIT( |
| 94 | + tracing, node::tracing::BindingData::CreatePerIsolateProperties) |
| 95 | +NODE_BINDING_EXTERNAL_REFERENCE( |
| 96 | + tracing, node::tracing::BindingData::RegisterExternalReferences) |
0 commit comments