Skip to content

Commit

Permalink
msg
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Nov 16, 2023
1 parent 45fba17 commit e9fb9e2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/http/pprof_http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@

namespace dsn {

bool check_TCMALLOC_SAMPLE_PARAMETER() {
char* str = getenv("TCMALLOC_SAMPLE_PARAMETER");
bool check_TCMALLOC_SAMPLE_PARAMETER()
{
char *str = getenv("TCMALLOC_SAMPLE_PARAMETER");
if (str == nullptr) {
return false;
}
char* endptr;
char *endptr;
int val = strtol(str, &endptr, 10);
return (*endptr == '\0' && val > 0);
}

bool has_TCMALLOC_SAMPLE_PARAMETER() {
bool has_TCMALLOC_SAMPLE_PARAMETER()
{
static bool val = check_TCMALLOC_SAMPLE_PARAMETER();
return val;
}
Expand Down Expand Up @@ -367,14 +369,14 @@ void pprof_http_service::heap_handler(const http_request &req, http_response &re
bool use_heap_profile = false;
const std::string kSecondParam = "seconds";
uint32_t seconds = 0;
const auto& iter = req.query_args.find(kSecondParam);
const auto &iter = req.query_args.find(kSecondParam);
if (iter != req.query_args.end() && buf2uint32(iter->second, seconds)) {
// This is true between calls to HeapProfilerStart() and HeapProfilerStop(), and
// also if the program has been run with HEAPPROFILER, or some other
// way to turn on whole-program profiling.
if (IsHeapProfilerRunning()) {
LOG_WARNING("heap profiling is running, dump the full profile directly");
char* profile = GetHeapProfile();
char *profile = GetHeapProfile();
resp.status_code = http_status_code::ok;
resp.body = profile;
free(profile);
Expand All @@ -393,13 +395,13 @@ void pprof_http_service::heap_handler(const http_request &req, http_response &re
resp.body = profile;
free(profile);
} else {
// The environment variable TCMALLOC_SAMPLE_PARAMETER should set to a positive value, such
// as 524288, before running.
if (!has_TCMALLOC_SAMPLE_PARAMETER()) {
static const char *msg = "no TCMALLOC_SAMPLE_PARAMETER in env";
LOG_WARNING(msg);
static const std::string kNoEnvMsg = "The environment variable "
"TCMALLOC_SAMPLE_PARAMETER should set to a "
"positive value, such as 524288, before running.";
LOG_WARNING(kNoEnvMsg);
resp.status_code = http_status_code::internal_server_error;
resp.body = msg;
resp.body = kNoEnvMsg;
return;
}

Expand Down

0 comments on commit e9fb9e2

Please sign in to comment.