| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa04f06 commit 13b6879
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "node.h" | |
| 7 | 7 | #include "node_builtins.h" | |
| 8 | 8 | #include "node_context_data.h" | |
| 9 | + #include "node_debug.h" | ||
| 9 | 10 | #include "node_errors.h" | |
| 10 | 11 | #include "node_exit_code.h" | |
| 11 | 12 | #include "node_internals.h" | |
@@ -112,17 +113,21 @@ MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context, | |||
| 112 | 113 | ||
| 113 | 114 | void* NodeArrayBufferAllocator::Allocate(size_t size) { | |
| 114 | 115 | void* ret; | |
| 115 | - if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers) | ||
| 116 | + if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers) { | ||
| 117 | + COUNT_GENERIC_USAGE("NodeArrayBufferAllocator.Allocate.ZeroFilled"); | ||
| 116 | 118 | ret = allocator_->Allocate(size); | |
| 117 | - else | ||
| 119 | + } else { | ||
| 120 | + COUNT_GENERIC_USAGE("NodeArrayBufferAllocator.Allocate.Uninitialized"); | ||
| 118 | 121 | ret = allocator_->AllocateUninitialized(size); | |
| 122 | + } | ||
| 119 | 123 | if (ret != nullptr) [[likely]] { | |
| 120 | 124 | total_mem_usage_.fetch_add(size, std::memory_order_relaxed); | |
| 121 | 125 | } | |
| 122 | 126 | return ret; | |
| 123 | 127 | } | |
| 124 | 128 | ||
| 125 | 129 | void* NodeArrayBufferAllocator::AllocateUninitialized(size_t size) { | |
| 130 | + COUNT_GENERIC_USAGE("NodeArrayBufferAllocator.Allocate.Uninitialized"); | ||
| 126 | 131 | void* ret = allocator_->AllocateUninitialized(size); | |
| 127 | 132 | if (ret != nullptr) [[likely]] { | |
| 128 | 133 | total_mem_usage_.fetch_add(size, std::memory_order_relaxed); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | #include "v8-fast-api-calls.h" | |
| 9 | 9 | #include "v8.h" | |
| 10 | 10 | ||
| 11 | + #include <string> | ||
| 11 | 12 | #include <string_view> | |
| 12 | 13 | #include <unordered_map> | |
| 13 | 14 | #endif // DEBUG | |
@@ -23,9 +24,20 @@ using v8::Number; | |||
| 23 | 24 | using v8::Object; | |
| 24 | 25 | using v8::Value; | |
| 25 | 26 | ||
| 27 | + thread_local std::unordered_map<std::string, int> generic_usage_counters; | ||
| 26 | 28 | thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash> | |
| 27 | 29 | v8_fast_api_call_counts; | |
| 28 | 30 | ||
| 31 | + void CountGenericUsage(const char* counter_name) { | ||
| 32 | + if (generic_usage_counters.find(counter_name) == generic_usage_counters.end()) | ||
| 33 | + generic_usage_counters[counter_name] = 0; | ||
| 34 | + generic_usage_counters[counter_name]++; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + int GetGenericUsageCount(const char* counter_name) { | ||
| 38 | + return generic_usage_counters[counter_name]; | ||
| 39 | + } | ||
| 40 | + | ||
| 29 | 41 | void TrackV8FastApiCall(FastStringKey key) { | |
| 30 | 42 | v8_fast_api_call_counts[key]++; | |
| 31 | 43 | } | |
@@ -34,6 +46,17 @@ int GetV8FastApiCallCount(FastStringKey key) { | |||
| 34 | 46 | return v8_fast_api_call_counts[key]; | |
| 35 | 47 | } | |
| 36 | 48 | ||
| 49 | + void GetGenericUsageCount(const FunctionCallbackInfo<Value>& args) { | ||
| 50 | + Environment* env = Environment::GetCurrent(args); | ||
| 51 | + if (!args[0]->IsString()) { | ||
| 52 | + env->ThrowError("getGenericUsageCount must be called with a string"); | ||
| 53 | + return; | ||
| 54 | + } | ||
| 55 | + Utf8Value utf8_key(env->isolate(), args[0]); | ||
| 56 | + args.GetReturnValue().Set( | ||
| 57 | + GetGenericUsageCount(utf8_key.ToStringView().data())); | ||
| 58 | + } | ||
| 59 | + | ||
| 37 | 60 | void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) { | |
| 38 | 61 | Environment* env = Environment::GetCurrent(args); | |
| 39 | 62 | if (!args[0]->IsString()) { | |
@@ -89,6 +112,7 @@ void Initialize(Local<Object> target, | |||
| 89 | 112 | Local<Context> context, | |
| 90 | 113 | void* priv) { | |
| 91 | 114 | SetMethod(context, target, "getV8FastApiCallCount", GetV8FastApiCallCount); | |
| 115 | + SetMethod(context, target, "getGenericUsageCount", GetGenericUsageCount); | ||
| 92 | 116 | SetFastMethod(context, target, "isEven", SlowIsEven, &fast_is_even); | |
| 93 | 117 | SetFastMethod(context, target, "isOdd", SlowIsOdd, &fast_is_odd); | |
| 94 | 118 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,10 +13,14 @@ namespace debug { | |||
| 13 | 13 | void TrackV8FastApiCall(FastStringKey key); | |
| 14 | 14 | int GetV8FastApiCallCount(FastStringKey key); | |
| 15 | 15 | ||
| 16 | + void CountGenericUsage(const char* counter_name); | ||
| 17 | + #define COUNT_GENERIC_USAGE(name) node::debug::CountGenericUsage(name) | ||
| 18 | + | ||
| 16 | 19 | #define TRACK_V8_FAST_API_CALL(key) \ | |
| 17 | 20 | node::debug::TrackV8FastApiCall(FastStringKey(key)) | |
| 18 | 21 | #else // !DEBUG | |
| 19 | 22 | #define TRACK_V8_FAST_API_CALL(key) | |
| 23 | + #define COUNT_GENERIC_USAGE(name) | ||
| 20 | 24 | #endif // DEBUG | |
| 21 | 25 | ||
| 22 | 26 | } // namespace debug | |
| Back | FazBrowse Home | New Git URL |
0 commit comments