Skip to content
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

Clean up leak detection code #4888

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dev/host_memory_leaks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ I didn't even create a `Makefile` for this because 1. this is kind of hacky and
using this ahead of time, and 2, it is only 1 file anyways...

```
g++ -fPIC hack.cpp
g++ -shared -Wl,-init,init_hack -o libhack.so hack.o
g++ -fPIC -c leak_detect.cpp
g++ -shared -Wl,-init,init_leak_detect -o libleak_detect.so leak_detect.o
```

## Running

Running with this change is quite a bit more complicated. Generally you set `LD_PRELOAD` to point to the full
path to where libhack.so is located and capture stderr for later processing
path to where `libleak_detect.so` is located and capture stderr for later processing

```
LD_PRELOAD=$PWD/libhack.so java -cp ... com.nvidia.MyTest 2>alloc_log.txt
LD_PRELOAD=$PWD/libleak_detect.so java -cp ... com.nvidia.MyTest 2>alloc_log.txt
```

But things start to get complicated if you are running pyspark or the pytest integration tests. This is because
Expand Down Expand Up @@ -93,7 +93,7 @@ index c3f73ed745..82203659c3 100644

By default only the address of what was allocated is printed out when something is allocated. This is
helpful in detecting if there was a memory leak, but not in telling what leaked the memory. If you set
the environment variable `HACK_TRACE` to anything C++ stack traces will be output with each allocation.
the environment variable `LEAK_DETECT_TRACE` to anything C++ stack traces will be output with each allocation.
Not doing the stack traces speeds up the runs a lot, which is why it is off by default.

## Interpreting The Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <cstdlib>
#include <pthread.h>

static bool include_traces = getenv("HACK_TRACE") != nullptr;
static bool include_traces = getenv("LEAK_DETECT_TRACE") != nullptr;
static pthread_mutex_t mutex_lock;

extern "C" {
void init_hack() {
void init_leak_detect() {
pthread_mutex_init(&mutex_lock, NULL);
}
}
Expand Down