mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
src: use constant strings for memory info names
PR-URL: https://github.com/nodejs/node/pull/46087 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
702303d0e8
commit
80fa25bf60
8 files changed
+20
-14
No files matched your search
+9
-3
@@ -673,13 +673,19 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string AsyncWrap::MemoryInfoName() const {
|
||||
const char* AsyncWrap::MemoryInfoName() const {
|
||||
return provider_names[provider_type()];
|
||||
}
|
||||
|
||||
std::string AsyncWrap::diagnostic_name() const {
|
||||
return MemoryInfoName() + " (" + std::to_string(env()->thread_id()) + ":" +
|
||||
std::to_string(static_cast<int64_t>(async_id_)) + ")";
|
||||
char buf[64];
|
||||
snprintf(buf,
|
||||
sizeof(buf),
|
||||
"%s(%" PRIu64 ":%.0f)",
|
||||
MemoryInfoName(),
|
||||
env()->thread_id(),
|
||||
async_id_);
|
||||
return buf;
|
||||
}
|
||||
|
||||
Local<Object> AsyncWrap::GetOwner() {
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ class AsyncWrap : public BaseObject {
|
||||
v8::Local<v8::Value>* argv);
|
||||
|
||||
virtual std::string diagnostic_name() const;
|
||||
std::string MemoryInfoName() const override;
|
||||
const char* MemoryInfoName() const override;
|
||||
|
||||
static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info);
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
|
||||
|
||||
AdditionalParams* params() { return ¶ms_; }
|
||||
|
||||
std::string MemoryInfoName() const override {
|
||||
const char* MemoryInfoName() const override {
|
||||
return CryptoJobTraits::JobName;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
|
||||
is_root_node_ = is_root_node;
|
||||
}
|
||||
|
||||
const char* Name() override { return name_.c_str(); }
|
||||
const char* Name() override { return name_; }
|
||||
const char* NamePrefix() override { return "Node /"; }
|
||||
size_t SizeInBytes() override { return size_; }
|
||||
// TODO(addaleax): Merging this with the "official" WrapperNode() method
|
||||
@@ -75,7 +75,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
|
||||
|
||||
// Otherwise (retainer == nullptr), we set these fields in an ad-hoc way
|
||||
bool is_root_node_ = false;
|
||||
std::string name_;
|
||||
const char* name_;
|
||||
size_t size_ = 0;
|
||||
v8::EmbedderGraph::Node::Detachedness detachedness_ =
|
||||
v8::EmbedderGraph::Node::Detachedness::kUnknown;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace node {
|
||||
|
||||
// Set the node name of a MemoryRetainer to klass
|
||||
#define SET_MEMORY_INFO_NAME(Klass) \
|
||||
inline std::string MemoryInfoName() const override { return #Klass; }
|
||||
inline const char* MemoryInfoName() const override { return #Klass; }
|
||||
|
||||
// Set the self size of a MemoryRetainer to the stack-allocated size of a
|
||||
// certain class
|
||||
@@ -68,7 +68,7 @@ class CleanupHookCallback;
|
||||
* }
|
||||
*
|
||||
* // Or use SET_MEMORY_INFO_NAME(ExampleRetainer)
|
||||
* std::string MemoryInfoName() const override {
|
||||
* const char* MemoryInfoName() const override {
|
||||
* return "ExampleRetainer";
|
||||
* }
|
||||
*
|
||||
@@ -119,7 +119,7 @@ class MemoryRetainer {
|
||||
// where all the edges start from the node of the current retainer,
|
||||
// and point to the nodes as specified by tracker->Track* calls.
|
||||
virtual void MemoryInfo(MemoryTracker* tracker) const = 0;
|
||||
virtual std::string MemoryInfoName() const = 0;
|
||||
virtual const char* MemoryInfoName() const = 0;
|
||||
virtual size_t SelfSize() const = 0;
|
||||
|
||||
virtual v8::Local<v8::Object> WrappedObject() const {
|
||||
|
||||
@@ -283,14 +283,14 @@ static void GetActiveResourcesInfo(const FunctionCallbackInfo<Value>& args) {
|
||||
AsyncWrap* w = req_wrap->GetAsyncWrap();
|
||||
if (w->persistent().IsEmpty()) continue;
|
||||
resources_info.emplace_back(
|
||||
OneByteString(env->isolate(), w->MemoryInfoName().c_str()));
|
||||
OneByteString(env->isolate(), w->MemoryInfoName()));
|
||||
}
|
||||
|
||||
// Active handles
|
||||
for (HandleWrap* w : *env->handle_wrap_queue()) {
|
||||
if (w->persistent().IsEmpty() || !HandleWrap::HasRef(w)) continue;
|
||||
resources_info.emplace_back(
|
||||
OneByteString(env->isolate(), w->MemoryInfoName().c_str()));
|
||||
OneByteString(env->isolate(), w->MemoryInfoName()));
|
||||
}
|
||||
|
||||
// Active timeouts
|
||||
|
||||
+1
-1
@@ -357,7 +357,7 @@ void Realm::VerifyNoStrongBaseObjects() {
|
||||
if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return;
|
||||
fprintf(stderr,
|
||||
"Found bad BaseObject during clean exit: %s\n",
|
||||
obj->MemoryInfoName().c_str());
|
||||
obj->MemoryInfoName());
|
||||
fflush(stderr);
|
||||
ABORT();
|
||||
});
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
|
||||
|
||||
SET_NO_MEMORY_INFO()
|
||||
SET_SELF_SIZE(TCPWrap)
|
||||
std::string MemoryInfoName() const override {
|
||||
const char* MemoryInfoName() const override {
|
||||
switch (provider_type()) {
|
||||
case ProviderType::PROVIDER_TCPWRAP:
|
||||
return "TCPSocketWrap";
|
||||
|
||||
Reference in new issue
Block a user