mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
src: clean up generic counter implementation
This addresses late review comments for the recently
landed cfbfc1b050 and aligns the new code with the
pre-existing V8 fast call counters.
Refs: https://github.com/nodejs/node/pull/60434#pullrequestreview-3386035944
PR-URL: https://github.com/nodejs/node/pull/60447
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
88080944ce
commit
b470ba08e1
|
|
@ -24,17 +24,16 @@ using v8::Number;
|
||||||
using v8::Object;
|
using v8::Object;
|
||||||
using v8::Value;
|
using v8::Value;
|
||||||
|
|
||||||
thread_local std::unordered_map<std::string, int> generic_usage_counters;
|
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
|
||||||
|
generic_usage_counters;
|
||||||
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
|
thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash>
|
||||||
v8_fast_api_call_counts;
|
v8_fast_api_call_counts;
|
||||||
|
|
||||||
void CountGenericUsage(const char* counter_name) {
|
void CountGenericUsage(FastStringKey counter_name) {
|
||||||
if (generic_usage_counters.find(counter_name) == generic_usage_counters.end())
|
|
||||||
generic_usage_counters[counter_name] = 0;
|
|
||||||
generic_usage_counters[counter_name]++;
|
generic_usage_counters[counter_name]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetGenericUsageCount(const char* counter_name) {
|
int GetGenericUsageCount(FastStringKey counter_name) {
|
||||||
return generic_usage_counters[counter_name];
|
return generic_usage_counters[counter_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,8 +52,8 @@ void GetGenericUsageCount(const FunctionCallbackInfo<Value>& args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Utf8Value utf8_key(env->isolate(), args[0]);
|
Utf8Value utf8_key(env->isolate(), args[0]);
|
||||||
args.GetReturnValue().Set(
|
args.GetReturnValue().Set(GetGenericUsageCount(
|
||||||
GetGenericUsageCount(utf8_key.ToStringView().data()));
|
FastStringKey::AllowDynamic(utf8_key.ToStringView())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) {
|
void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) {
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,9 @@ namespace debug {
|
||||||
void TrackV8FastApiCall(FastStringKey key);
|
void TrackV8FastApiCall(FastStringKey key);
|
||||||
int GetV8FastApiCallCount(FastStringKey key);
|
int GetV8FastApiCallCount(FastStringKey key);
|
||||||
|
|
||||||
void CountGenericUsage(const char* counter_name);
|
void CountGenericUsage(FastStringKey counter_name);
|
||||||
#define COUNT_GENERIC_USAGE(name) node::debug::CountGenericUsage(name)
|
#define COUNT_GENERIC_USAGE(name) \
|
||||||
|
node::debug::CountGenericUsage(FastStringKey(name))
|
||||||
|
|
||||||
#define TRACK_V8_FAST_API_CALL(key) \
|
#define TRACK_V8_FAST_API_CALL(key) \
|
||||||
node::debug::TrackV8FastApiCall(FastStringKey(key))
|
node::debug::TrackV8FastApiCall(FastStringKey(key))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user