-
Notifications
You must be signed in to change notification settings - Fork 5.5k
debug: Link in the debug version of tcmalloc for debug builds. #5424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
1ed5aba
49f610c
93d0bc3
1aa4196
8ff4d3a
dd61c91
301ce01
c7cd6a1
632652c
d882947
c6e72e3
98e7d95
ee8af23
ae5b1ec
b5982e6
f6eacf0
80cb279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,9 @@ The following optional features can be enabled on the Bazel build command-line: | |
| * ASSERT() can be configured to log failures and increment a stat counter in a release build with | ||
| `--define log_debug_assert_in_release=enabled`. The default behavior is to compile debug assertions out of | ||
| release builds so that the condition is not evaluated. This option has no effect in debug builds. | ||
| * tcmalloc can be disabled with `--define tcmalloc=disabled` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disabling is in section above (though, I'd argue that we could merge both).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved tcmalloc=disabled to disabling section. Merging can be left for a different PR. |
||
| * memory-debugging (scribbling over memory after allocation and before freeing) with | ||
| `--define tcmalloc=debug`. | ||
|
|
||
| ## Disabling extensions | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_test", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_test( | ||
| name = "debug_test", | ||
| srcs = ["debug_test.cc"], | ||
| deps = ["//source/common/memory:stats_lib"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #include "common/memory/stats.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Memory { | ||
|
|
||
| #ifdef ENVOY_MEMORY_DEBUG_ENABLED | ||
|
|
||
| constexpr int ArraySize = 10; | ||
|
|
||
| struct MyStruct { | ||
| MyStruct() : x_(0) {} // words_ is uninitialized; will have whatever allocator left there. | ||
| uint64_t x_; | ||
| uint64_t words_[ArraySize]; | ||
| }; | ||
|
|
||
| TEST(MemoryDebug, ByteSize) { | ||
| uint64_t before = Stats::totalCurrentlyAllocated(); | ||
| auto ptr = std::make_unique<MyStruct>(); | ||
| uint64_t after = Stats::totalCurrentlyAllocated(); | ||
| EXPECT_LE(sizeof(MyStruct), after - before); | ||
| } | ||
|
|
||
| TEST(MemoryDebug, ScribbleOnNew) { | ||
| auto ptr = std::make_unique<MyStruct>(); | ||
| for (int i = 0; i < ArraySize; ++i) { | ||
| // This is the pattern written by tcmalloc's debug library. | ||
| EXPECT_EQ(0xabababababababab, ptr->words_[i]); | ||
| } | ||
| } | ||
|
jmarantz marked this conversation as resolved.
|
||
|
|
||
| TEST(MemoryDebug, ScribbleOnDelete) { | ||
| uint64_t* words; | ||
| { | ||
| auto ptr = std::make_unique<MyStruct>(); | ||
| words = ptr->words_; | ||
| } | ||
| for (int i = 0; i < ArraySize; ++i) { | ||
| // This is the pattern written by tcmalloc's debug library on destruction. | ||
| // Note: this test cannot be run under valgrind or asan. | ||
| EXPECT_EQ(0xcdcdcdcdcdcdcdcd, words[i]); | ||
| } | ||
| } | ||
|
|
||
| TEST(MemoryDebug, ZeroByteAlloc) { auto ptr = std::make_unique<uint8_t[]>(0); } | ||
|
|
||
| #endif // ENVOY_MEMORY_DEBUG_ENABLED | ||
|
|
||
| } // namespace Memory | ||
| } // namespace Envoy | ||
Uh oh!
There was an error while loading. Please reload this page.