|
| 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::Object; |
| 26 | +using v8::ObjectTemplate; |
| 27 | +using v8::String; |
| 28 | +using v8::Value; |
| 29 | + |
| 30 | +void BindingData::MemoryInfo(MemoryTracker* tracker) const { |
| 31 | + tracker->TrackField("tracing_categories_buffer", tracing_categories_buffer_); |
| 32 | +} |
| 33 | + |
| 34 | +BindingData::BindingData(Realm* realm, v8::Local<v8::Object> object) |
| 35 | + : SnapshotableObject(realm, object, type_int), |
| 36 | + tracing_categories_buffer_(realm->isolate(), kTracingCategoriesLength) { |
| 37 | + object |
| 38 | + ->Set(realm->context(), |
| 39 | + FIXED_ONE_BYTE_STRING(realm->isolate(), "tracingCategories"), |
| 40 | + tracing_categories_buffer_.GetJSArray()) |
| 41 | + .Check(); |
| 42 | + |
| 43 | + // get the pointer of the memory for the flag that store if trace is enabled for http |
| 44 | + // 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 |
| 45 | + tracing_categories_buffer_[0] = const_cast<uint8_t*>(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("node.http")); |
| 46 | +} |
| 47 | + |
| 48 | +bool BindingData::PrepareForSerialization(v8::Local<v8::Context> context, |
| 49 | + v8::SnapshotCreator* creator) { |
| 50 | + // We'll just re-initialize the buffers in the constructor since their |
| 51 | + // contents can be thrown away once consumed in the previous call. |
| 52 | + tracing_categories_buffer_.Release(); |
| 53 | + // Return true because we need to maintain the reference to the binding from |
| 54 | + // JS land. |
| 55 | + return true; |
| 56 | +} |
| 57 | + |
| 58 | +InternalFieldInfoBase* BindingData::Serialize(int index) { |
| 59 | + DCHECK_EQ(index, BaseObject::kEmbedderType); |
| 60 | + InternalFieldInfo* info = |
| 61 | + InternalFieldInfoBase::New<InternalFieldInfo>(type()); |
| 62 | + return info; |
| 63 | +} |
| 64 | + |
| 65 | +void BindingData::Deserialize(v8::Local<v8::Context> context, |
| 66 | + v8::Local<v8::Object> holder, |
| 67 | + int index, |
| 68 | + InternalFieldInfoBase* info) { |
| 69 | + DCHECK_EQ(index, BaseObject::kEmbedderType); |
| 70 | + v8::HandleScope scope(context->GetIsolate()); |
| 71 | + Realm* realm = Realm::GetCurrent(context); |
| 72 | + BindingData* binding = realm->AddBindingData<BindingData>(context, holder); |
| 73 | + CHECK_NOT_NULL(binding); |
| 74 | +} |
| 75 | + |
| 76 | +void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, |
| 77 | + Local<FunctionTemplate> ctor) { |
| 78 | + Isolate* isolate = isolate_data->isolate(); |
| 79 | + Local<ObjectTemplate> target = ctor->InstanceTemplate(); |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +void BindingData::CreatePerContextProperties(Local<Object> target, |
| 84 | + Local<Value> unused, |
| 85 | + Local<Context> context, |
| 86 | + void* priv) { |
| 87 | + Realm* realm = Realm::GetCurrent(context); |
| 88 | + realm->AddBindingData<BindingData>(context, target); |
| 89 | +} |
| 90 | + |
| 91 | +void BindingData::RegisterExternalReferences( |
| 92 | + ExternalReferenceRegistry* registry) { |
| 93 | + |
| 94 | +} |
| 95 | + |
| 96 | +} // namespace tracing |
| 97 | + |
| 98 | +} // node |
| 99 | + |
| 100 | +NODE_BINDING_CONTEXT_AWARE_INTERNAL( |
| 101 | + tracing, node::tracing::BindingData::CreatePerContextProperties) |
| 102 | +NODE_BINDING_PER_ISOLATE_INIT( |
| 103 | + tracing, node::tracing::BindingData::CreatePerIsolateProperties) |
| 104 | +NODE_BINDING_EXTERNAL_REFERENCE( |
| 105 | + tracing, node::tracing::BindingData::RegisterExternalReferences) |
0 commit comments