Skip to content

Commit

Permalink
heaptrace: Apply manual fixes to resolve clang-tidy warnings
Browse files Browse the repository at this point in the history
This patch resolves some clang-tidy warnings by applying manual fixes.

Signed-off-by: Honggyu Kim <[email protected]>
  • Loading branch information
honggyukim committed Apr 18, 2023
1 parent 57615b0 commit be077cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/heaptrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions src/libheaptrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

Expand Down Expand Up @@ -315,7 +315,7 @@ print_dump_stackmap_flamegraph(std::vector<std::pair<stack_trace_t, stack_info_t

const stack_trace_t &stack_trace = sorted_stack[i].first;

for (int j = info.stack_depth - 1; j >= 0; j--) {
for (size_t j = info.stack_depth - 1; j >= 0; j--) {
print_backtrace_symbol_flamegraph(stack_trace[j], semicolon);
semicolon = ";";
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef std::chrono::duration<uint64_t, std::kilo> kilobytes;
typedef std::chrono::duration<uint64_t, std::mega> megabytes;
typedef std::chrono::duration<uint64_t, std::giga> gigabytes;

static int gettid(void)
static long gettid(void)
{
return syscall(SYS_gettid);
}
Expand Down

0 comments on commit be077cd

Please sign in to comment.