GeezerVison is showing github.com — src: use constant strings for memory info names · nodejs/node@e8eaa49
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.cc +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -673,13 +673,19 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb, | 673 | 673 | return ret; | 674 | 674 | } | 675 | 675 |
| 676 | | -std::string AsyncWrap::MemoryInfoName() const { | | 676 | +const char* AsyncWrap::MemoryInfoName() const { | 677 | 677 | return provider_names[provider_type()]; | 678 | 678 | } | 679 | 679 |
| 680 | 680 | 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; | 683 | 689 | } | 684 | 690 |
| 685 | 691 | Local<Object> AsyncWrap::GetOwner() { | |
Collapse file Copy file name to clipboardExpand all lines: src/async_wrap.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -209,7 +209,7 @@ class AsyncWrap : public BaseObject { | 209 | 209 | v8::Local<v8::Value>* argv); | 210 | 210 |
| 211 | 211 | virtual std::string diagnostic_name() const; | 212 | | - std::string MemoryInfoName() const override; | | 212 | + const char* MemoryInfoName() const override; | 213 | 213 |
| 214 | 214 | static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info); | 215 | 215 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_util.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -398,7 +398,7 @@ class CryptoJob : public AsyncWrap, public ThreadPoolWork { | 398 | 398 |
| 399 | 399 | AdditionalParams* params() { return ¶ms_; } | 400 | 400 |
| 401 | | - std::string MemoryInfoName() const override { | | 401 | + const char* MemoryInfoName() const override { | 402 | 402 | return CryptoJobTraits::JobName; | 403 | 403 | } | 404 | 404 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/memory_tracker-inl.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,7 +44,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node { | 44 | 44 | is_root_node_ = is_root_node; | 45 | 45 | } | 46 | 46 |
| 47 | | - const char* Name() override { return name_.c_str(); } | | 47 | + const char* Name() override { return name_; } | 48 | 48 | const char* NamePrefix() override { return "Node /"; } | 49 | 49 | size_t SizeInBytes() override { return size_; } | 50 | 50 | // TODO(addaleax): Merging this with the "official" WrapperNode() method | @@ -75,7 +75,7 @@ class MemoryRetainerNode : public v8::EmbedderGraph::Node { | 75 | 75 |
| 76 | 76 | // Otherwise (retainer == nullptr), we set these fields in an ad-hoc way | 77 | 77 | bool is_root_node_ = false; | 78 | | - std::string name_; | | 78 | + const char* name_; | 79 | 79 | size_t size_ = 0; | 80 | 80 | v8::EmbedderGraph::Node::Detachedness detachedness_ = | 81 | 81 | v8::EmbedderGraph::Node::Detachedness::kUnknown; | |
Collapse file Copy file name to clipboardExpand all lines: src/memory_tracker.h +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ namespace node { | 17 | 17 |
| 18 | 18 | // Set the node name of a MemoryRetainer to klass | 19 | 19 | #define SET_MEMORY_INFO_NAME(Klass) \ | 20 | | - inline std::string MemoryInfoName() const override { return #Klass; } | | 20 | + inline const char* MemoryInfoName() const override { return #Klass; } | 21 | 21 |
| 22 | 22 | // Set the self size of a MemoryRetainer to the stack-allocated size of a | 23 | 23 | // certain class | @@ -68,7 +68,7 @@ class CleanupHookCallback; | 68 | 68 | * } | 69 | 69 | * | 70 | 70 | * // Or use SET_MEMORY_INFO_NAME(ExampleRetainer) | 71 | | - * std::string MemoryInfoName() const override { | | 71 | + * const char* MemoryInfoName() const override { | 72 | 72 | * return "ExampleRetainer"; | 73 | 73 | * } | 74 | 74 | * | @@ -119,7 +119,7 @@ class MemoryRetainer { | 119 | 119 | // where all the edges start from the node of the current retainer, | 120 | 120 | // and point to the nodes as specified by tracker->Track* calls. | 121 | 121 | virtual void MemoryInfo(MemoryTracker* tracker) const = 0; | 122 | | - virtual std::string MemoryInfoName() const = 0; | | 122 | + virtual const char* MemoryInfoName() const = 0; | 123 | 123 | virtual size_t SelfSize() const = 0; | 124 | 124 |
| 125 | 125 | virtual v8::Local<v8::Object> WrappedObject() const { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_process_methods.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -283,14 +283,14 @@ static void GetActiveResourcesInfo(const FunctionCallbackInfo<Value>& args) { | 283 | 283 | AsyncWrap* w = req_wrap->GetAsyncWrap(); | 284 | 284 | if (w->persistent().IsEmpty()) continue; | 285 | 285 | resources_info.emplace_back( | 286 | | - OneByteString(env->isolate(), w->MemoryInfoName().c_str())); | | 286 | + OneByteString(env->isolate(), w->MemoryInfoName())); | 287 | 287 | } | 288 | 288 |
| 289 | 289 | // Active handles | 290 | 290 | for (HandleWrap* w : *env->handle_wrap_queue()) { | 291 | 291 | if (w->persistent().IsEmpty() || !HandleWrap::HasRef(w)) continue; | 292 | 292 | resources_info.emplace_back( | 293 | | - OneByteString(env->isolate(), w->MemoryInfoName().c_str())); | | 293 | + OneByteString(env->isolate(), w->MemoryInfoName())); | 294 | 294 | } | 295 | 295 |
| 296 | 296 | // Active timeouts | |
Collapse file Copy file name to clipboardExpand all lines: src/node_realm.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -357,7 +357,7 @@ void Realm::VerifyNoStrongBaseObjects() { | 357 | 357 | if (obj->IsNotIndicativeOfMemoryLeakAtExit()) return; | 358 | 358 | fprintf(stderr, | 359 | 359 | "Found bad BaseObject during clean exit: %s\n", | 360 | | - obj->MemoryInfoName().c_str()); | | 360 | + obj->MemoryInfoName()); | 361 | 361 | fflush(stderr); | 362 | 362 | ABORT(); | 363 | 363 | }); | |
Collapse file Copy file name to clipboardExpand all lines: src/tcp_wrap.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> { | 50 | 50 |
| 51 | 51 | SET_NO_MEMORY_INFO() | 52 | 52 | SET_SELF_SIZE(TCPWrap) | 53 | | - std::string MemoryInfoName() const override { | | 53 | + const char* MemoryInfoName() const override { | 54 | 54 | switch (provider_type()) { | 55 | 55 | case ProviderType::PROVIDER_TCPWRAP: | 56 | 56 | return "TCPSocketWrap"; | |
|