jvm-profiling-tools / honest-profiler

A sampling JVM profiler without the safepoint sample bias
https://github.com/RichardWarburton/honest-profiler/wiki
MIT License
1.25k stars 146 forks source link

agent: Protect ThreadBucket* returned from ThreadMap #229

Closed ikavalio closed 6 years ago

ikavalio commented 6 years ago

Hi,

This PR changes ThreadMap::get public API (as well as some internal parts of the class), so instead of returning a pointer to internally allocated ThreadBucket and managing it's lifecycle directly by calling release() method in LogWriter::record, the method will return a ThreadBucketPtr wrapper of it. Wrapper will do automatic and atomic reference counting upon construction/destruction and can only be moved. It is moved from signal handler callback to CircularQueue and then to LogWriter. There's no need to explicitly call any methods (except for std::move in certain cases), once Bucket goes out of scope pointer will be processed correctly. I added a couple of unit tests for thread map as well.

I also did 2 minor changes:

  1. Removed #ifdef GETENV_NEW_THREAD_ASYNC_UNSAFE that protects controller->start(). It allows to use controller on Mac when both port and host are defined. If controller doesn't work properly for someone, it can be disabled easily at runtime, there's no need to remove it completely.
  2. Added .clang-format file, so uniform cpp code style can be used reused. I only applied it to thread_map.h, thread_map.cpp and corresponding test, since I'm not sure everyone will like it.
RichardWarburton commented 6 years ago

Thanks for the PR @ikavalio - sorry I missed this one.