-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: expose node.http trace flag inside array
- Loading branch information
Showing
9 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ | |
V(task_queue) \ | ||
V(tcp_wrap) \ | ||
V(timers) \ | ||
V(tracing) \ | ||
V(trace_events) \ | ||
V(tty_wrap) \ | ||
V(types) \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "node_tracing.h" | ||
#include "base_object-inl.h" | ||
#include "env-inl.h" | ||
#include "memory_tracker-inl.h" | ||
#include "node.h" | ||
#include "node_external_reference.h" | ||
#include "node_internals.h" | ||
#include "node_v8_platform-inl.h" | ||
#include "tracing/agent.h" | ||
#include "util-inl.h" | ||
#include "v8.h" | ||
|
||
#include <set> | ||
#include <string> | ||
#include <numeric> | ||
|
||
namespace node { | ||
namespace tracing { | ||
|
||
using v8::Context; | ||
using v8::FunctionTemplate; | ||
using v8::HandleScope; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::ObjectTemplate; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
void BindingData::MemoryInfo(MemoryTracker* tracker) const { | ||
tracker->TrackField("tracing_categories_buffer", tracing_categories_buffer_); | ||
} | ||
|
||
BindingData::BindingData(Realm* realm, v8::Local<v8::Object> object) | ||
: SnapshotableObject(realm, object, type_int), | ||
tracing_categories_buffer_(realm->isolate(), kTracingCategoriesLength) { | ||
object | ||
->Set(realm->context(), | ||
FIXED_ONE_BYTE_STRING(realm->isolate(), "tracingCategories"), | ||
tracing_categories_buffer_.GetJSArray()) | ||
.Check(); | ||
|
||
// get the pointer of the memory for the flag that store if trace is enabled for http | ||
// 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 | ||
tracing_categories_buffer_[0] = const_cast<uint8_t*>(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("node.http")); | ||
} | ||
|
||
bool BindingData::PrepareForSerialization(v8::Local<v8::Context> context, | ||
v8::SnapshotCreator* creator) { | ||
// We'll just re-initialize the buffers in the constructor since their | ||
// contents can be thrown away once consumed in the previous call. | ||
tracing_categories_buffer_.Release(); | ||
// Return true because we need to maintain the reference to the binding from | ||
// JS land. | ||
return true; | ||
} | ||
|
||
InternalFieldInfoBase* BindingData::Serialize(int index) { | ||
DCHECK_EQ(index, BaseObject::kEmbedderType); | ||
InternalFieldInfo* info = | ||
InternalFieldInfoBase::New<InternalFieldInfo>(type()); | ||
return info; | ||
} | ||
|
||
void BindingData::Deserialize(v8::Local<v8::Context> context, | ||
v8::Local<v8::Object> holder, | ||
int index, | ||
InternalFieldInfoBase* info) { | ||
DCHECK_EQ(index, BaseObject::kEmbedderType); | ||
v8::HandleScope scope(context->GetIsolate()); | ||
Realm* realm = Realm::GetCurrent(context); | ||
BindingData* binding = realm->AddBindingData<BindingData>(context, holder); | ||
CHECK_NOT_NULL(binding); | ||
} | ||
|
||
void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data, | ||
Local<FunctionTemplate> ctor) { | ||
Isolate* isolate = isolate_data->isolate(); | ||
Local<ObjectTemplate> target = ctor->InstanceTemplate(); | ||
|
||
} | ||
|
||
void BindingData::CreatePerContextProperties(Local<Object> target, | ||
Local<Value> unused, | ||
Local<Context> context, | ||
void* priv) { | ||
Realm* realm = Realm::GetCurrent(context); | ||
realm->AddBindingData<BindingData>(context, target); | ||
} | ||
|
||
void BindingData::RegisterExternalReferences( | ||
ExternalReferenceRegistry* registry) { | ||
|
||
} | ||
|
||
} // namespace tracing | ||
|
||
} // node | ||
|
||
NODE_BINDING_CONTEXT_AWARE_INTERNAL( | ||
tracing, node::tracing::BindingData::CreatePerContextProperties) | ||
NODE_BINDING_PER_ISOLATE_INIT( | ||
tracing, node::tracing::BindingData::CreatePerIsolateProperties) | ||
NODE_BINDING_EXTERNAL_REFERENCE( | ||
tracing, node::tracing::BindingData::RegisterExternalReferences) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef SRC_NODE_TRACING_H_ | ||
#define SRC_NODE_TRACING_H_ | ||
|
||
#include <cinttypes> | ||
#include "aliased_buffer.h" | ||
#include "node.h" | ||
#include "node_snapshotable.h" | ||
#include "util.h" | ||
#include "v8-fast-api-calls.h" | ||
#include "v8.h" | ||
|
||
#include <string> | ||
|
||
namespace node { | ||
class ExternalReferenceRegistry; | ||
|
||
namespace tracing { | ||
|
||
class BindingData : public SnapshotableObject { | ||
public: | ||
BindingData(Realm* realm, v8::Local<v8::Object> obj); | ||
|
||
using InternalFieldInfo = InternalFieldInfoBase; | ||
|
||
SERIALIZABLE_OBJECT_METHODS() | ||
SET_BINDING_ID(tracing_binding_data) | ||
|
||
void MemoryInfo(MemoryTracker* tracker) const override; | ||
SET_SELF_SIZE(BindingData) | ||
SET_MEMORY_INFO_NAME(BindingData) | ||
|
||
static void CreatePerIsolateProperties(IsolateData* isolate_data, | ||
v8::Local<v8::FunctionTemplate> ctor); | ||
static void CreatePerContextProperties(v8::Local<v8::Object> target, | ||
v8::Local<v8::Value> unused, | ||
v8::Local<v8::Context> context, | ||
void* priv); | ||
static void RegisterExternalReferences(ExternalReferenceRegistry* registry); | ||
|
||
private: | ||
static constexpr size_t kTracingCategoriesLength = 1; | ||
AliasedUint8Array tracing_categories_buffer_; | ||
}; | ||
|
||
} // namespace tracing | ||
|
||
} // namespace node | ||
|
||
#endif // SRC_NODE_TRACING_H_ |