diff --git a/src/heaptrace.cc b/src/heaptrace.cc index b64bad1..24f3e1e 100644 --- a/src/heaptrace.cc +++ b/src/heaptrace.cc @@ -47,7 +47,7 @@ static error_t parse_option(int key, char *arg, struct argp_state *state) break; case OPT_top: - opts->top = strtol(arg, nullptr, 0); + opts->top = std::stoi(arg); break; case 's': diff --git a/src/libheaptrace.cc b/src/libheaptrace.cc index 72dfd3d..d78f1c6 100644 --- a/src/libheaptrace.cc +++ b/src/libheaptrace.cc @@ -90,13 +90,13 @@ __constructor static void heaptrace_init() // setup option values // TODO: create constexpr variables instead of default magic values. env = getenv("HEAPTRACE_NUM_TOP_BACKTRACE"); - opts.top = env ? strtol(env, nullptr, 0) : 10; + opts.top = env ? std::stoi(env) : 10; env = getenv("HEAPTRACE_SORT_KEYS"); opts.sort_keys = env ? env : "size"; env = getenv("HEAPTRACE_FLAME_GRAPH"); - opts.flamegraph = env ? strtol(env, nullptr, 0) : false; + opts.flamegraph = env ? std::stoi(env) : false; opts.outfile = getenv("HEAPTRACE_OUTFILE"); if (opts.outfile) { diff --git a/src/stacktrace.cc b/src/stacktrace.cc index 0894fe9..354a30d 100644 --- a/src/stacktrace.cc +++ b/src/stacktrace.cc @@ -228,8 +228,8 @@ static std::string get_byte_unit(uint64_t size) std::string read_statm() { - int vss, rss, shared; - int pagesize_kb = sysconf(_SC_PAGESIZE); + long vss, rss, shared; + long pagesize_kb = sysconf(_SC_PAGESIZE); std::ifstream fs("/proc/self/statm"); fs >> vss >> rss >> shared; @@ -244,7 +244,7 @@ std::string read_statm() static void print_dump_stackmap_header(const char *sort_key) { - pr_out("[heaptrace] dump allocation sorted by '%s' for /proc/%d/maps (%s)\n", sort_key, + pr_out("[heaptrace] dump allocation sorted by '%s' for /proc/%ld/maps (%s)\n", sort_key, utils::gettid(), utils::get_comm_name().c_str()); } @@ -315,7 +315,7 @@ print_dump_stackmap_flamegraph(std::vector= 0; j--) { + for (size_t j = info.stack_depth - 1; j >= 0; j--) { print_backtrace_symbol_flamegraph(stack_trace[j], semicolon); semicolon = ";"; } diff --git a/src/utils.cc b/src/utils.cc index 907c492..6f3d8bd 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -34,9 +34,8 @@ std::string get_comm_name(void) { std::string comm; std::stringstream ss; - int tid = utils::gettid(); - ss << "/proc/" << tid << "/comm"; + ss << "/proc/" << utils::gettid() << "/comm"; std::ifstream fs(ss.str()); fs >> comm; @@ -78,7 +77,7 @@ static std::string mmap_string(int val, const struct enum_table *et, int len) /* exact match */ for (int i = len - 1; i >= 0; i--) { if (val == et[i].val) - return std::string(et[i].str); + return { et[i].str }; } /* OR-ing bit flags */ diff --git a/src/utils.h b/src/utils.h index 0430032..0b5f3f2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -23,7 +23,7 @@ typedef std::chrono::duration kilobytes; typedef std::chrono::duration megabytes; typedef std::chrono::duration gigabytes; -static int gettid(void) +static long gettid(void) { return syscall(SYS_gettid); }