Skip to content

Commit 6772996

Browse files
legendecasjuanarbol
authored andcommitted
src: use constant strings for memory info names
PR-URL: #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>
1 parent 40d52fb commit 6772996

8 files changed

+20
-14
lines changed

src/async_wrap.cc

+9-3
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,19 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
671671
return ret;
672672
}
673673

674-
std::string AsyncWrap::MemoryInfoName() const {
674+
const char* AsyncWrap::MemoryInfoName() const {
675675
return provider_names[provider_type()];
676676
}
677677

678678
std::string AsyncWrap::diagnostic_name() const {
679-
return MemoryInfoName() + " (" + std::to_string(env()->thread_id()) + ":" +
680-
std::to_string(static_cast<int64_t>(async_id_)) + ")";
679+
char buf[64];
680+
snprintf(buf,
681+
sizeof(buf),
682+
"%s(%" PRIu64 ":%.0f)",
683+
MemoryInfoName(),
684+
env()->thread_id(),
685+
async_id_);
686+
return buf;
681687
}
682688

683689
Local<Object> AsyncWrap::GetOwner() {

src/async_wrap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class AsyncWrap : public BaseObject {
207207
v8::Local<v8::Value>* argv);
208208

209209
virtual std::string diagnostic_name() const;
210-
std::string MemoryInfoName() const override;
210+
const char* MemoryInfoName() const override;
211211

212212
static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info);
213213

src/crypto/crypto_util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork {
398398

399399
AdditionalParams* params() { return &params_; }
400400

401-
std::string MemoryInfoName() const override {
401+
const char* MemoryInfoName() const override {
402402
return CryptoJobTraits::JobName;
403403
}
404404

src/memory_tracker-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
4444
is_root_node_ = is_root_node;
4545
}
4646

47-
const char* Name() override { return name_.c_str(); }
47+
const char* Name() override { return name_; }
4848
const char* NamePrefix() override { return "Node /"; }
4949
size_t SizeInBytes() override { return size_; }
5050
// TODO(addaleax): Merging this with the "official" WrapperNode() method
@@ -75,7 +75,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node {
7575

7676
// Otherwise (retainer == nullptr), we set these fields in an ad-hoc way
7777
bool is_root_node_ = false;
78-
std::string name_;
78+
const char* name_;
7979
size_t size_ = 0;
8080
v8::EmbedderGraph::Node::Detachedness detachedness_ =
8181
v8::EmbedderGraph::Node::Detachedness::kUnknown;

src/memory_tracker.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace node {
1717

1818
// Set the node name of a MemoryRetainer to klass
1919
#define SET_MEMORY_INFO_NAME(Klass) \
20-
inline std::string MemoryInfoName() const override { return #Klass; }
20+
inline const char* MemoryInfoName() const override { return #Klass; }
2121

2222
// Set the self size of a MemoryRetainer to the stack-allocated size of a
2323
// certain class
@@ -68,7 +68,7 @@ class CleanupHookCallback;
6868
* }
6969
*
7070
* // Or use SET_MEMORY_INFO_NAME(ExampleRetainer)
71-
* std::string MemoryInfoName() const override {
71+
* const char* MemoryInfoName() const override {
7272
* return "ExampleRetainer";
7373
* }
7474
*
@@ -119,7 +119,7 @@ class MemoryRetainer {
119119
// where all the edges start from the node of the current retainer,
120120
// and point to the nodes as specified by tracker->Track* calls.
121121
virtual void MemoryInfo(MemoryTracker* tracker) const = 0;
122-
virtual std::string MemoryInfoName() const = 0;
122+
virtual const char* MemoryInfoName() const = 0;
123123
virtual size_t SelfSize() const = 0;
124124

125125
virtual v8::Local<v8::Object> WrappedObject() const {

src/node_process_methods.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ static void GetActiveResourcesInfo(const FunctionCallbackInfo<Value>& args) {
282282
AsyncWrap* w = req_wrap->GetAsyncWrap();
283283
if (w->persistent().IsEmpty()) continue;
284284
resources_info.emplace_back(
285-
OneByteString(env->isolate(), w->MemoryInfoName().c_str()));
285+
OneByteString(env->isolate(), w->MemoryInfoName()));
286286
}
287287

288288
// Active handles
289289
for (HandleWrap* w : *env->handle_wrap_queue()) {
290290
if (w->persistent().IsEmpty() || !HandleWrap::HasRef(w)) continue;
291291
resources_info.emplace_back(
292-
OneByteString(env->isolate(), w->MemoryInfoName().c_str()));
292+
OneByteString(env->isolate(), w->MemoryInfoName()));
293293
}
294294

295295
// Active timeouts

src/node_realm.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void Realm::VerifyNoStrongBaseObjects() {
366366
if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return;
367367
fprintf(stderr,
368368
"Found bad BaseObject during clean exit: %s\n",
369-
obj->MemoryInfoName().c_str());
369+
obj->MemoryInfoName());
370370
fflush(stderr);
371371
ABORT();
372372
});

src/tcp_wrap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
5050

5151
SET_NO_MEMORY_INFO()
5252
SET_SELF_SIZE(TCPWrap)
53-
std::string MemoryInfoName() const override {
53+
const char* MemoryInfoName() const override {
5454
switch (provider_type()) {
5555
case ProviderType::PROVIDER_TCPWRAP:
5656
return "TCPSocketWrap";

0 commit comments

Comments
 (0)