diff --git a/BUILD.bazel b/BUILD.bazel index f8eaaa4643..b2a453e0c9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -61,6 +61,7 @@ LINKOPTS = [ "-Wl,-U,_MallocExtension_ReleaseFreeMemory", "-Wl,-U,_ProfilerStart", "-Wl,-U,_ProfilerStop", + "-Wl,-U,__Z13GetStackTracePPvii", "-Wl,-U,_RegisterThriftProtocol", ], "//conditions:default": [ @@ -212,6 +213,7 @@ BUTIL_SRCS = [ "src/butil/crc32c.cc", "src/butil/containers/case_ignored_flat_map.cpp", "src/butil/iobuf.cpp", + "src/butil/iobuf_profiler.cpp", "src/butil/binary_printer.cpp", "src/butil/recordio.cc", "src/butil/popen.cpp", diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bf116b6c7..4e753ead17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,7 +278,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() # for *.so @@ -400,6 +401,7 @@ set(BUTIL_SOURCES ${PROJECT_SOURCE_DIR}/src/butil/crc32c.cc ${PROJECT_SOURCE_DIR}/src/butil/containers/case_ignored_flat_map.cpp ${PROJECT_SOURCE_DIR}/src/butil/iobuf.cpp + ${PROJECT_SOURCE_DIR}/src/butil/iobuf_profiler.cpp ${PROJECT_SOURCE_DIR}/src/butil/binary_printer.cpp ${PROJECT_SOURCE_DIR}/src/butil/recordio.cc ${PROJECT_SOURCE_DIR}/src/butil/popen.cpp diff --git a/Makefile b/Makefile index 0ed8a352c2..da6ac9f49b 100644 --- a/Makefile +++ b/Makefile @@ -163,6 +163,7 @@ BUTIL_SOURCES = \ src/butil/crc32c.cc \ src/butil/containers/case_ignored_flat_map.cpp \ src/butil/iobuf.cpp \ + src/butil/iobuf_profiler.cpp \ src/butil/binary_printer.cpp \ src/butil/recordio.cc \ src/butil/popen.cpp diff --git a/config_brpc.sh b/config_brpc.sh index a660171c4a..7e459b75cb 100755 --- a/config_brpc.sh +++ b/config_brpc.sh @@ -196,6 +196,7 @@ if [ "$SYSTEM" = "Darwin" ]; then DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -Wl,-U,_MallocExtension_ReleaseFreeMemory" DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -Wl,-U,_ProfilerStart" DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -Wl,-U,_ProfilerStop" + DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -Wl,-U,__Z13GetStackTracePPvii" DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -Wl,-U,_RegisterThriftProtocol" fi append_linking() { diff --git a/example/asynchronous_echo_c++/CMakeLists.txt b/example/asynchronous_echo_c++/CMakeLists.txt index 1c8da4e57c..60854454e2 100644 --- a/example/asynchronous_echo_c++/CMakeLists.txt +++ b/example/asynchronous_echo_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(asynchronous_echo_client client.cpp ${PROTO_SRC}) diff --git a/example/auto_concurrency_limiter/CMakeLists.txt b/example/auto_concurrency_limiter/CMakeLists.txt index 213b357b5d..c19a8f4001 100644 --- a/example/auto_concurrency_limiter/CMakeLists.txt +++ b/example/auto_concurrency_limiter/CMakeLists.txt @@ -123,6 +123,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii" "-Wl,-U,_RegisterThriftProtocol") endif() diff --git a/example/backup_request_c++/CMakeLists.txt b/example/backup_request_c++/CMakeLists.txt index 5a520a4dcf..7aab5e5768 100644 --- a/example/backup_request_c++/CMakeLists.txt +++ b/example/backup_request_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(backup_request_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/bthread_tag_echo_c++/CMakeLists.txt b/example/bthread_tag_echo_c++/CMakeLists.txt index 2baea53e3d..56aec0df5d 100644 --- a/example/bthread_tag_echo_c++/CMakeLists.txt +++ b/example/bthread_tag_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/cancel_c++/CMakeLists.txt b/example/cancel_c++/CMakeLists.txt index c8f4d7f381..07d80b4c4a 100644 --- a/example/cancel_c++/CMakeLists.txt +++ b/example/cancel_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(cancel_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/cascade_echo_c++/CMakeLists.txt b/example/cascade_echo_c++/CMakeLists.txt index 56248abd29..b6d8c0b75f 100644 --- a/example/cascade_echo_c++/CMakeLists.txt +++ b/example/cascade_echo_c++/CMakeLists.txt @@ -128,7 +128,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(cascade_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/dynamic_partition_echo_c++/CMakeLists.txt b/example/dynamic_partition_echo_c++/CMakeLists.txt index dbe7addad4..2394b7fc34 100644 --- a/example/dynamic_partition_echo_c++/CMakeLists.txt +++ b/example/dynamic_partition_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(dynamic_partition_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/echo_c++/CMakeLists.txt b/example/echo_c++/CMakeLists.txt index badd49e187..7746957b17 100644 --- a/example/echo_c++/CMakeLists.txt +++ b/example/echo_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/grpc_c++/CMakeLists.txt b/example/grpc_c++/CMakeLists.txt index c1d0817aed..516735d6ec 100644 --- a/example/grpc_c++/CMakeLists.txt +++ b/example/grpc_c++/CMakeLists.txt @@ -129,6 +129,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii" "-Wl,-U,_RegisterThriftProtocol") endif() diff --git a/example/http_c++/CMakeLists.txt b/example/http_c++/CMakeLists.txt index 8d0507d2a5..3fd9a088a3 100644 --- a/example/http_c++/CMakeLists.txt +++ b/example/http_c++/CMakeLists.txt @@ -136,7 +136,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(http_client http_client.cpp) diff --git a/example/memcache_c++/CMakeLists.txt b/example/memcache_c++/CMakeLists.txt index 4f3c2ed182..5941c344cd 100644 --- a/example/memcache_c++/CMakeLists.txt +++ b/example/memcache_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(memcache_client client.cpp) diff --git a/example/multi_threaded_echo_c++/CMakeLists.txt b/example/multi_threaded_echo_c++/CMakeLists.txt index a3c47a35ff..c13b34bdde 100644 --- a/example/multi_threaded_echo_c++/CMakeLists.txt +++ b/example/multi_threaded_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/multi_threaded_echo_fns_c++/CMakeLists.txt b/example/multi_threaded_echo_fns_c++/CMakeLists.txt index 7907774364..887541b8fd 100644 --- a/example/multi_threaded_echo_fns_c++/CMakeLists.txt +++ b/example/multi_threaded_echo_fns_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(multi_threaded_echo_fns_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/nshead_extension_c++/CMakeLists.txt b/example/nshead_extension_c++/CMakeLists.txt index 0c3d18ab5b..6ddf382671 100644 --- a/example/nshead_extension_c++/CMakeLists.txt +++ b/example/nshead_extension_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(nshead_extension_client client.cpp) diff --git a/example/nshead_pb_extension_c++/CMakeLists.txt b/example/nshead_pb_extension_c++/CMakeLists.txt index 005840e6fd..8d0edf6030 100644 --- a/example/nshead_pb_extension_c++/CMakeLists.txt +++ b/example/nshead_pb_extension_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(nshead_pb_extension_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/parallel_echo_c++/CMakeLists.txt b/example/parallel_echo_c++/CMakeLists.txt index d668ed43c9..5bd081836e 100644 --- a/example/parallel_echo_c++/CMakeLists.txt +++ b/example/parallel_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(parallel_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/partition_echo_c++/CMakeLists.txt b/example/partition_echo_c++/CMakeLists.txt index 1d770a985c..636e19b431 100644 --- a/example/partition_echo_c++/CMakeLists.txt +++ b/example/partition_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/rdma_performance/CMakeLists.txt b/example/rdma_performance/CMakeLists.txt index 226aa170eb..0fe0fe20b6 100644 --- a/example/rdma_performance/CMakeLists.txt +++ b/example/rdma_performance/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/redis_c++/CMakeLists.txt b/example/redis_c++/CMakeLists.txt index 14dc839a97..1447e60698 100644 --- a/example/redis_c++/CMakeLists.txt +++ b/example/redis_c++/CMakeLists.txt @@ -139,7 +139,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(redis_cli redis_cli.cpp) diff --git a/example/selective_echo_c++/CMakeLists.txt b/example/selective_echo_c++/CMakeLists.txt index ca39217f76..4b304fb6c0 100644 --- a/example/selective_echo_c++/CMakeLists.txt +++ b/example/selective_echo_c++/CMakeLists.txt @@ -135,7 +135,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(selective_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/session_data_and_thread_local/CMakeLists.txt b/example/session_data_and_thread_local/CMakeLists.txt index bfadec79ea..3678ab761d 100644 --- a/example/session_data_and_thread_local/CMakeLists.txt +++ b/example/session_data_and_thread_local/CMakeLists.txt @@ -136,7 +136,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(session_data_and_thread_local_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/example/streaming_echo_c++/CMakeLists.txt b/example/streaming_echo_c++/CMakeLists.txt index 29ffcb1692..ca4579d308 100644 --- a/example/streaming_echo_c++/CMakeLists.txt +++ b/example/streaming_echo_c++/CMakeLists.txt @@ -129,7 +129,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") "-framework Foundation" "-Wl,-U,_MallocExtension_ReleaseFreeMemory" "-Wl,-U,_ProfilerStart" - "-Wl,-U,_ProfilerStop") + "-Wl,-U,_ProfilerStop" + "-Wl,-U,__Z13GetStackTracePPvii") endif() add_executable(streaming_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER}) diff --git a/src/brpc/builtin/common.cpp b/src/brpc/builtin/common.cpp index 9cdc72fee6..7b5d33a348 100644 --- a/src/brpc/builtin/common.cpp +++ b/src/brpc/builtin/common.cpp @@ -308,6 +308,7 @@ const char* ProfilingType2String(ProfilingType t) { case PROFILING_HEAP: return "heap"; case PROFILING_GROWTH: return "growth"; case PROFILING_CONTENTION: return "contention"; + case PROFILING_IOBUF: return "iobuf"; } return "unknown"; } diff --git a/src/brpc/builtin/common.h b/src/brpc/builtin/common.h index f4d6962729..5fd8a9c98e 100644 --- a/src/brpc/builtin/common.h +++ b/src/brpc/builtin/common.h @@ -52,6 +52,7 @@ enum ProfilingType { PROFILING_HEAP = 1, PROFILING_GROWTH = 2, PROFILING_CONTENTION = 3, + PROFILING_IOBUF = 4, }; DECLARE_string(rpc_profiling_dir); diff --git a/src/brpc/builtin/hotspots_service.cpp b/src/brpc/builtin/hotspots_service.cpp index b70266f49f..c01ce536d7 100644 --- a/src/brpc/builtin/hotspots_service.cpp +++ b/src/brpc/builtin/hotspots_service.cpp @@ -23,6 +23,7 @@ #include "butil/file_util.h" // butil::FilePath #include "butil/popen.h" // butil::read_command_output #include "butil/fd_guard.h" // butil::fd_guard +#include "butil/iobuf_profiler.h" #include "brpc/log.h" #include "brpc/controller.h" #include "brpc/server.h" @@ -154,7 +155,8 @@ struct ProfilingEnvironment { }; // Different ProfilingType have different env. -static ProfilingEnvironment g_env[4] = { +static ProfilingEnvironment g_env[5] = { + { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL }, { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL }, { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL }, { PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL, NULL }, @@ -399,7 +401,8 @@ static bool has_GOOGLE_PPROF_BINARY_PATH() { static void DisplayResult(Controller* cntl, google::protobuf::Closure* done, const char* prof_name, - const butil::IOBuf& result_prefix) { + const butil::IOBuf& result_prefix, + ProfilingType type) { ClosureGuard done_guard(done); butil::IOBuf prof_result; if (cntl->IsCanceled()) { @@ -488,7 +491,7 @@ static void DisplayResult(Controller* cntl, #if defined(OS_LINUX) cmd_builder << "perl " << pprof_tool << DisplayTypeToPProfArgument(display_type) - << (show_ccount ? " --contention " : ""); + << ((show_ccount || type == PROFILING_IOBUF) ? " --contention " : ""); if (base_name) { cmd_builder << "--base " << *base_name << ' '; } @@ -505,7 +508,7 @@ static void DisplayResult(Controller* cntl, #elif defined(OS_MACOSX) cmd_builder << s_pprof_binary_path << " " << DisplayTypeToPProfArgument(display_type) - << (show_ccount ? " -contentions " : ""); + << ((show_ccount || type == PROFILING_IOBUF) ? " --contention " : ""); if (base_name) { cmd_builder << "-base " << *base_name << ' '; } @@ -637,7 +640,7 @@ static void DoProfiling(ProfilingType type, return cntl->SetFailed( EINVAL, "The profile denoted by `view' does not exist"); } - DisplayResult(cntl, done_guard.release(), view->c_str(), os.buf()); + DisplayResult(cntl, done_guard.release(), view->c_str(), os.buf(), type); return; } @@ -774,6 +777,15 @@ static void DoProfiling(ProfilingType type, PLOG(WARNING) << "Profiling has been interrupted"; } bthread::ContentionProfilerStop(); + } else if (type == PROFILING_IOBUF) { + if (!butil::IsIOBufProfilerEnabled()) { + os << "IOBuf profiler is not enabled" + << (use_html ? "" : "\n"); + os.move_to(resp); + cntl->http_response().set_status_code(HTTP_STATUS_FORBIDDEN); + return NotifyWaiters(type, cntl, view); + } + butil::IOBufProfilerFlush(prof_name); } else if (type == PROFILING_HEAP) { MallocExtension* malloc_ext = MallocExtension::instance(); if (malloc_ext == NULL || !has_TCMALLOC_SAMPLE_PARAMETER()) { @@ -827,11 +839,11 @@ static void DoProfiling(ProfilingType type, std::vector waiters; // NOTE: Must be called before DisplayResult which calls done->Run() and // deletes cntl. - ConsumeWaiters(type, cntl, &waiters); - DisplayResult(cntl, done_guard.release(), prof_name, os.buf()); + ConsumeWaiters(type, cntl, &waiters); + DisplayResult(cntl, done_guard.release(), prof_name, os.buf(), type); for (size_t i = 0; i < waiters.size(); ++i) { - DisplayResult(waiters[i].cntl, waiters[i].done, prof_name, os.buf()); + DisplayResult(waiters[i].cntl, waiters[i].done, prof_name, os.buf(), type); } } @@ -849,7 +861,12 @@ static void StartProfiling(ProfilingType type, enabled = cpu_profiler_enabled; } else if (type == PROFILING_CONTENTION) { enabled = true; - } else if (type == PROFILING_HEAP) { + } else if (type == PROFILING_IOBUF) { + enabled = butil::IsIOBufProfilerEnabled(); + if (!enabled) { + extra_desc = " (no ENABLE_IOBUF_PROFILER=1 in env or no link tcmalloc )"; + } + } else if (type == PROFILING_HEAP) { enabled = IsHeapProfilerEnabled(); if (enabled && !has_TCMALLOC_SAMPLE_PARAMETER()) { enabled = false; @@ -925,7 +942,8 @@ static void StartProfiling(ProfilingType type, "