TODO(bevers): Allow passing custom options via query parameters.
| 933 | |
| 934 | // TODO(bevers): Allow passing custom options via query parameters. |
| 935 | Future<http::Response> MemoryProfiler::statistics( |
| 936 | const http::Request& request, |
| 937 | const Option<http::authentication::Principal>&) |
| 938 | { |
| 939 | if (!detectJemalloc()) { |
| 940 | return http::BadRequest(string(JEMALLOC_NOT_DETECTED_MESSAGE) + ".\n"); |
| 941 | } |
| 942 | |
| 943 | const string options = "J"; // 'J' selects JSON output format. |
| 944 | |
| 945 | string statistics; |
| 946 | |
| 947 | #ifdef LIBPROCESS_ALLOW_JEMALLOC |
| 948 | ::malloc_stats_print([](void* opaque, const char* msg) { |
| 949 | string* statistics = static_cast<string*>(opaque); |
| 950 | *statistics += msg; |
| 951 | }, &statistics, options.c_str()); |
| 952 | #endif |
| 953 | |
| 954 | return http::OK(statistics, "application/json; charset=utf-8"); |
| 955 | } |
| 956 | |
| 957 | |
| 958 | Future<http::Response> MemoryProfiler::state( |