Skip to content

Commit

Permalink
[#15990] docdb: Update /pprof/heap to work with new tcmalloc.
Browse files Browse the repository at this point in the history
Summary:
The new tcmalloc (--use-google-tcmalloc) uses a sampling-based profiler (and got rid of the old all-allocation profiler).

This diff updates /pprof/heap to use the sampling profiler. The output of this endpoint was previously parsed by yb-prof, but since the new format is structured, it's easy enough to output directly as a table (and makes testability and symbolization easier).

There are 3 arguments that can passed to passed to /pprof/heap as url arguments:
1. `seconds` controls how long to profile for
2. `sample_freq_bytes` controls how often we sample for allocations.
3. `only_growth` controls whether we output only call stacks for allocations for which we did not observe a corresponding deallocation. Pass only growth if you want the equivalent of `yb-prof`'s in_use_bytes.html, and do not pass it if you want the equivalent of `alloc_bytes.html`. NB: Both alloc_bytes.html and in_use_bytes were essentially the same data, just sorted differently (i.e. both had the allocated bytes and in use bytes for each call stack). In the new endpoints, I kept the information separate (if we want this back we can change it though).

For example, if you want to profile allocations for 60s, sampling every 2MiB, you would go to (for a tserver):
```
IP:9000/pprof/heap?seconds=60&sample_freq_bytes=2000000
```
If you wanted the same as above but with only allocations that were not deallocated you would go to:
```
IP:9000/pprof/heap?seconds=60&sample_freq_bytes=2000000&only_growth=true
```

Example output for the /pprof/heap endpoint:
{F34511}

{F34512}

This diff also adds a /pprof/heap_snapshot endpoint that gives an instantaneous view of the heap at either the time of peak heap usage (if the `peak_heap` url argument is true) or at the current time (if `peak_heap` is false). For this endpoint to be used, the `enable_process_lifetime_heap_profiling` gflag must have been set to true since the last restart (samples are taken according to the frequency in the new `profiler_sample_freq_bytes` gflag).

Test Plan: Manually tested by running `CassandraBatchTimeseries` against a cluster and verifying that for `only_growth = True` we only see stacks that were not deallocated (rocksdb inserts), and with `only_growth = False` we see all stacks.

Reviewers: amitanand, bogdan, esheng

Reviewed By: esheng

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D22780
  • Loading branch information
SrivastavaAnubhav committed Mar 13, 2023
1 parent 3d4ce59 commit 9554847
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 85 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ ADD_CXX_FLAGS("-DYB_COMPILER_TYPE=$ENV{YB_COMPILER_TYPE}")
ADD_CXX_FLAGS("-DYB_COMPILER_VERSION=${COMPILER_VERSION}")
ADD_CXX_FLAGS("-DSNAPPY")
ADD_CXX_FLAGS("-DLZ4")
ADD_CXX_FLAGS("-DZLIB")
ADD_CXX_FLAGS("-DYB_ZLIB")

############################################################
# Compiler flags
Expand Down
54 changes: 27 additions & 27 deletions build-support/thirdparty_archives.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
sha_for_local_checkout: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha_for_local_checkout: 229715f75bf29b2bea1a7f14b93ab515ea244e91
archives:
- os_type: almalinux8
architecture: x86_64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052457-9dadefc8ee-almalinux8-x86_64-clang15
tag: v20230310192906-229715f75b-almalinux8-x86_64-clang15
- os_type: almalinux8
architecture: x86_64
compiler_type: clang15
is_linuxbrew: true
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052456-9dadefc8ee-almalinux8-x86_64-clang15-linuxbrew
tag: v20230310192852-229715f75b-almalinux8-x86_64-clang15-linuxbrew
- os_type: almalinux8
architecture: x86_64
compiler_type: clang15
is_linuxbrew: true
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type: full
tag: v20230207052440-9dadefc8ee-almalinux8-x86_64-clang15-linuxbrew-full-lto
tag: v20230310192825-229715f75b-almalinux8-x86_64-clang15-linuxbrew-full-lto
- os_type: almalinux8
architecture: x86_64
compiler_type: gcc11
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052439-9dadefc8ee-almalinux8-x86_64-gcc11
tag: v20230310192835-229715f75b-almalinux8-x86_64-gcc11
- os_type: centos7
architecture: aarch64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052621-9dadefc8ee-centos7-aarch64-clang15
tag: v20230310192855-229715f75b-centos7-aarch64-clang15
- os_type: centos7
architecture: aarch64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type: full
tag: v20230207052619-9dadefc8ee-centos7-aarch64-clang15-full-lto
tag: v20230310192850-229715f75b-centos7-aarch64-clang15-full-lto
- os_type: centos7
architecture: x86_64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052503-9dadefc8ee-centos7-x86_64-clang15
tag: v20230310192851-229715f75b-centos7-x86_64-clang15
- os_type: centos7
architecture: x86_64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type: full
tag: v20230207052556-9dadefc8ee-centos7-x86_64-clang15-full-lto
tag: v20230310192919-229715f75b-centos7-x86_64-clang15-full-lto
- os_type: centos7
architecture: x86_64
compiler_type: gcc11
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052511-9dadefc8ee-centos7-x86_64-gcc11
tag: v20230310192842-229715f75b-centos7-x86_64-gcc11
- os_type: macos
architecture: arm64
compiler_type: clang
Expand All @@ -74,27 +74,27 @@ archives:
architecture: x86_64
compiler_type: clang
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052521-9dadefc8ee-macos-x86_64
tag: v20230310192842-229715f75b-macos-x86_64
- os_type: ubuntu20.04
architecture: x86_64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052447-9dadefc8ee-ubuntu2004-x86_64-clang15
tag: v20230310192846-229715f75b-ubuntu2004-x86_64-clang15
- os_type: ubuntu22.04
architecture: x86_64
compiler_type: clang15
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052452-9dadefc8ee-ubuntu2204-x86_64-clang15
tag: v20230310192911-229715f75b-ubuntu2204-x86_64-clang15
- os_type: ubuntu22.04
architecture: x86_64
compiler_type: gcc11
is_linuxbrew: false
sha: 9dadefc8ee5edc7c643ee89d8325804f146bdf18
sha: 229715f75bf29b2bea1a7f14b93ab515ea244e91
lto_type:
tag: v20230207052449-9dadefc8ee-ubuntu2204-x86_64-gcc11
tag: v20230310192834-229715f75b-ubuntu2204-x86_64-gcc11
17 changes: 8 additions & 9 deletions src/yb/rocksdb/port/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
#undef PLATFORM_IS_LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN true

#include <stdint.h>
#include <windows.h>

#include <string>
#include <string.h>
#include <mutex>
#include <limits>
#include <condition_variable>

#include <stdint.h>

#include "yb/rocksdb/options.h"

#undef min
Expand All @@ -69,7 +68,7 @@ typedef SSIZE_T ssize_t;

#define __attribute__(A)

#ifdef ZLIB
#ifdef YB_ZLIB
#include <zlib.h>
#endif

Expand Down Expand Up @@ -114,7 +113,7 @@ const uint64_t kMaxUint64 = std::numeric_limits<uint64_t>::max();

const size_t kMaxSizet = std::numeric_limits<size_t>::max();

#else //_MSC_VER
#else // _MSC_VER

// VS 15 has snprintf
#define snprintf _snprintf
Expand All @@ -133,7 +132,7 @@ const size_t kMaxSizet = UINT64_MAX;
const size_t kMaxSizet = UINT_MAX;
#endif

#endif //_MSC_VER
#endif // _MSC_VER

const bool kLittleEndian = true;

Expand All @@ -142,11 +141,11 @@ class CondVar;
class Mutex {
public:

/* implicit */ Mutex(bool adaptive = false)
/* implicit */ Mutex(bool adaptive = false) // NOLINT
#ifndef NDEBUG
: locked_(false)
#endif
{ }
{ }

~Mutex();

Expand Down Expand Up @@ -244,7 +243,7 @@ struct OnceType {
struct Init {};

OnceType() {}
OnceType(const Init&) {}
explicit OnceType(const Init&) {}
OnceType(const OnceType&) = delete;
OnceType& operator=(const OnceType&) = delete;

Expand Down
24 changes: 12 additions & 12 deletions src/yb/rocksdb/util/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <snappy.h>
#endif

#ifdef ZLIB
#ifdef YB_ZLIB
#include <zlib.h>
#endif

Expand All @@ -61,7 +61,7 @@ inline bool Snappy_Supported() {
}

inline bool Zlib_Supported() {
#ifdef ZLIB
#ifdef YB_ZLIB
return true;
#endif
return false;
Expand Down Expand Up @@ -199,7 +199,7 @@ inline bool Zlib_Compress(const CompressionOptions& opts,
uint32_t compress_format_version,
const char* input, size_t length,
::std::string* output) {
#ifdef ZLIB
#ifdef YB_ZLIB
if (length > std::numeric_limits<uint32_t>::max()) {
// Can't compress more than 4GB
return false;
Expand Down Expand Up @@ -229,7 +229,7 @@ inline bool Zlib_Compress(const CompressionOptions& opts,
}

// Compress the input, and put compressed data in output.
_stream.next_in = (Bytef *)input;
_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(input));
_stream.avail_in = static_cast<unsigned int>(length);

// Initialize the output size.
Expand Down Expand Up @@ -269,7 +269,7 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length,
int* decompress_size,
uint32_t compress_format_version,
int windowBits = -14) {
#ifdef ZLIB
#ifdef YB_ZLIB
uint32_t output_len = 0;
if (compress_format_version == 2) {
if (!compression::GetDecompressedSizeInfo(&input_data, &input_length,
Expand Down Expand Up @@ -297,12 +297,12 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length,
return nullptr;
}

_stream.next_in = (Bytef *)input_data;
_stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(input_data));
_stream.avail_in = static_cast<unsigned int>(input_length);

char* output = new char[output_len];

_stream.next_out = (Bytef *)output;
_stream.next_out = reinterpret_cast<Bytef*>(output);
_stream.avail_out = static_cast<unsigned int>(output_len);

bool done = false;
Expand All @@ -326,7 +326,7 @@ inline char* Zlib_Uncompress(const char* input_data, size_t input_length,
output = tmp;

// Set more output.
_stream.next_out = (Bytef *)(output + old_sz);
_stream.next_out = reinterpret_cast<Bytef*>(output + old_sz);
_stream.avail_out = static_cast<unsigned int>(output_len - old_sz);
break;
}
Expand Down Expand Up @@ -383,7 +383,7 @@ inline bool BZip2_Compress(const CompressionOptions& opts,
}

// Compress the input, and put compressed data in output.
_stream.next_in = (char *)input;
_stream.next_in = const_cast<char*>(input);
_stream.avail_in = static_cast<unsigned int>(length);

// Initialize the output size.
Expand Down Expand Up @@ -444,12 +444,12 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length,
return nullptr;
}

_stream.next_in = (char *)input_data;
_stream.next_in = const_cast<char*>(input_data);
_stream.avail_in = static_cast<unsigned int>(input_length);

char* output = new char[output_len];

_stream.next_out = (char *)output;
_stream.next_out = const_cast<char*>(output);
_stream.avail_out = static_cast<unsigned int>(output_len);

bool done = false;
Expand All @@ -472,7 +472,7 @@ inline char* BZip2_Uncompress(const char* input_data, size_t input_length,
output = tmp;

// Set more output.
_stream.next_out = (char *)(output + old_sz);
_stream.next_out = const_cast<char*>(output + old_sz);
_stream.avail_out = static_cast<unsigned int>(output_len - old_sz);
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/yb/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ set(SERVER_PROCESS_SRCS
glog_metrics.cc
monitored_task.cc
pgsql_webserver_wrapper.cc
pprof-path-handlers_util.cc
pprof-path-handlers.cc
rpc_server.cc
rpcz-path-handler.cc
Expand Down
Loading

0 comments on commit 9554847

Please sign in to comment.