Skip to content

Commit e8eaa49

Browse files
legendecasRafaelGSS
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 0f60bc9 commit e8eaa49

8 files changed

+20
-14
lines changed

src/async_wrap.cc

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

676-
std::string AsyncWrap::MemoryInfoName() const {
676+
const char* AsyncWrap::MemoryInfoName() const {
677677
return provider_names[provider_type()];
678678
}
679679

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

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

src/async_wrap.h

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

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

214214
static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info);
215215

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
@@ -283,14 +283,14 @@ static void GetActiveResourcesInfo(const FunctionCallbackInfo<Value>& args) {
283283
AsyncWrap* w = req_wrap->GetAsyncWrap();
284284
if (w->persistent().IsEmpty()) continue;
285285
resources_info.emplace_back(
286-
OneByteString(env->isolate(), w->MemoryInfoName().c_str()));
286+
OneByteString(env->isolate(), w->MemoryInfoName()));
287287
}
288288

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

296296
// Active timeouts

src/node_realm.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void Realm::VerifyNoStrongBaseObjects() {
357357
if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return;
358358
fprintf(stderr,
359359
"Found bad BaseObject during clean exit: %s\n",
360-
obj->MemoryInfoName().c_str());
360+
obj->MemoryInfoName());
361361
fflush(stderr);
362362
ABORT();
363363
});

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)