Skip to content

Commit 65d8054

Browse files
committed
Linter fixes
- Clang tidy - Cleanup of unused fields
1 parent ec2f932 commit 65d8054

File tree

4 files changed

+23
-40
lines changed

4 files changed

+23
-40
lines changed

include/live_allocation.hpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ class LiveAllocation {
8282
using PidMap = std::unordered_map<pid_t, PidStacks>;
8383
using WatcherVector = std::vector<PidMap>;
8484

85-
WatcherVector _watcher_vector;
86-
87-
int64_t upscale_with_mapping(const PprofStacks::value_type &stack,
88-
PidStacks &pid_stacks);
89-
9085
void register_allocation(const UnwindOutput &uo, uintptr_t addr, size_t size,
9186
int watcher_pos, pid_t pid) {
9287
PidMap &pid_map = access_resize(_watcher_vector, watcher_pos);
@@ -122,12 +117,13 @@ class LiveAllocation {
122117

123118
static std::vector<SmapsEntry> parse_smaps(pid_t pid);
124119

125-
void cycle() { _stats = {}; }
120+
static int64_t upscale_with_mapping(const PprofStacks::value_type &stack,
121+
PidStacks &pid_stacks);
126122

127-
void set_default_unwind_output(const UnwindOutput &uo) {
128-
_default_uw_output = uo;
129-
}
123+
void cycle() { _stats = {}; }
130124

125+
// no lint to avoid warning about member being public (should be refactored)
126+
WatcherVector _watcher_vector; // NOLINT
131127
private:
132128
static bool register_deallocation_internal(uintptr_t address,
133129
PidStacks &pid_stacks);
@@ -139,7 +135,6 @@ class LiveAllocation {
139135
struct {
140136
unsigned _unmatched_deallocations = {};
141137
} _stats;
142-
UnwindOutput _default_uw_output;
143138
};
144139

145140
} // namespace ddprof

src/ddprof_worker.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,10 @@ DDRes aggregate_livealloc_stack(
253253
int64_t upscalled_value, DDProfContext &ctx, const PerfWatcher *watcher,
254254
DDProfPProf *pprof, const SymbolHdr &symbol_hdr) {
255255

256-
if (upscalled_value)
256+
if (upscalled_value) {
257257
LG_DBG("Upscaling from %ld to %ld", alloc_info.second._value,
258258
upscalled_value);
259+
}
259260
// default to the sampled value
260261
const DDProfValuePack pack{
261262
upscalled_value ? upscalled_value : alloc_info.second._value,
@@ -269,7 +270,6 @@ DDRes aggregate_livealloc_stack(
269270
}
270271

271272
DDRes aggregate_live_allocations_common(DDProfContext &ctx,
272-
LiveAllocation &live_allocations,
273273
unsigned watcher_pos, pid_t pid,
274274
LiveAllocation::PidStacks &pid_stacks) {
275275
UnwindState *us = ctx.worker_ctx.us;
@@ -289,8 +289,8 @@ DDRes aggregate_live_allocations_common(DDProfContext &ctx,
289289

290290
// Step 1: Process existing samples
291291
for (const auto &alloc_info : pid_stacks._unique_stacks) {
292-
int64_t upscaled_value =
293-
live_allocations.upscale_with_mapping(alloc_info, pid_stacks);
292+
const int64_t upscaled_value =
293+
ddprof::LiveAllocation::upscale_with_mapping(alloc_info, pid_stacks);
294294
DDRES_CHECK_FWD(aggregate_livealloc_stack(alloc_info, upscaled_value, ctx,
295295
watcher, pprof, symbol_hdr));
296296
}
@@ -307,7 +307,7 @@ DDRes aggregate_live_allocations_common(DDProfContext &ctx,
307307
for (const auto &el : pid_stacks.entries) {
308308
if (el.accounted_size == 0) {
309309
// Use the RSS value for this mapping as the "unsampled" value
310-
int64_t unsampled_value = el.rss_kb * 1000; // RSS in bytes
310+
const int64_t unsampled_value = el.rss_kb * 1000; // RSS in bytes
311311
// Add the frame using the fake UnwindOutput
312312
const DDProfValuePack pack{unsampled_value, 1, 0};
313313
DDRES_CHECK_FWD(
@@ -335,8 +335,8 @@ DDRes aggregate_live_allocations_for_pid(DDProfContext &ctx, pid_t pid) {
335335
auto &pid_map = live_allocations._watcher_vector[watcher_pos];
336336
auto &pid_stacks = pid_map[pid]; // Get PidStacks for the specific pid
337337
// Call the common function to handle the aggregation
338-
DDRES_CHECK_FWD(aggregate_live_allocations_common(
339-
ctx, live_allocations, watcher_pos, pid, pid_stacks));
338+
DDRES_CHECK_FWD(
339+
aggregate_live_allocations_common(ctx, watcher_pos, pid, pid_stacks));
340340
}
341341

342342
return {};
@@ -353,7 +353,7 @@ DDRes aggregate_live_allocations(DDProfContext &ctx) {
353353
auto &pid_stacks = pid_vt.second;
354354
// Call the common function to handle the aggregation for each PID
355355
DDRES_CHECK_FWD(aggregate_live_allocations_common(
356-
ctx, live_allocations, watcher_pos, pid_vt.first, pid_stacks));
356+
ctx, watcher_pos, pid_vt.first, pid_stacks));
357357
}
358358
}
359359

@@ -440,12 +440,6 @@ DDRes worker_library_init(DDProfContext &ctx,
440440
ctx.worker_ctx.exp[1] = nullptr;
441441
ctx.worker_ctx.pprof[0] = nullptr;
442442
ctx.worker_ctx.pprof[1] = nullptr;
443-
444-
// live allocation - create default unwind output
445-
add_common_frame(ctx.worker_ctx.us, SymbolErrors::unsampled_mapping);
446-
ctx.worker_ctx.live_allocation.set_default_unwind_output(
447-
ctx.worker_ctx.us->output);
448-
ctx.worker_ctx.us->output.clear();
449443
}
450444
CatchExcept2DDRes();
451445
return {};

src/live_allocation.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool LiveAllocation::register_deallocation_internal(uintptr_t address,
3636
// object
3737
if (v._unique_stack) {
3838
// Adjust the mapping values map for the allocation being deallocated
39-
ProcessAddress_t mapping_start = v._unique_stack->first.start_mmap;
39+
const ProcessAddress_t mapping_start = v._unique_stack->first.start_mmap;
4040
mapping_values[mapping_start]._value -= v._value;
4141
if (mapping_values[mapping_start]._count > 0) {
4242
--mapping_values[mapping_start]._count;
@@ -88,17 +88,14 @@ bool LiveAllocation::register_allocation_internal(const UnwindOutput &uo,
8888
if (entry == pid_stacks.entries.end() || address < entry->start) {
8989
// Address not within any known mapping
9090
LG_DBG("(LIVE_ALLOC) Address not within any known mapping: %lx", address);
91-
if (entry != pid_stacks.entries.end())
92-
LG_DBG("(LIVE_ALLOC) matched entry start: %lx, end: %lx", entry->start,
93-
entry->end);
9491
} else {
9592
start_addr = entry->start;
9693
}
9794

9895
// Create or find the PprofStacks::value_type object corresponding to the
9996
// UnwindOutput
10097
auto &stacks = pid_stacks._unique_stacks;
101-
StackAndMapping stack_key{uo_ptr, start_addr};
98+
const StackAndMapping stack_key{uo_ptr, start_addr};
10299
auto iter = stacks.find(stack_key);
103100
if (iter == stacks.end()) {
104101
iter = stacks.emplace(stack_key, ValueAndCount{}).first;
@@ -151,7 +148,7 @@ bool LiveAllocation::register_allocation_internal(const UnwindOutput &uo,
151148
}
152149

153150
std::vector<SmapsEntry> LiveAllocation::parse_smaps(pid_t pid) {
154-
std::string smaps_file = absl::StrFormat("%s/%d/smaps", "/proc", pid);
151+
const std::string smaps_file = absl::StrFormat("%s/%d/smaps", "/proc", pid);
155152

156153
std::vector<SmapsEntry> entries;
157154
FILE *file = fopen(smaps_file.c_str(), "r");
@@ -164,7 +161,7 @@ std::vector<SmapsEntry> LiveAllocation::parse_smaps(pid_t pid) {
164161
SmapsEntry current_entry;
165162

166163
while (fgets(buffer, sizeof(buffer), file)) {
167-
std::string_view line(buffer);
164+
const std::string_view line(buffer);
168165

169166
if (line.find("Rss:") == 0) {
170167
// Extract RSS value (take characters after "Rss: ")
@@ -180,12 +177,12 @@ std::vector<SmapsEntry> LiveAllocation::parse_smaps(pid_t pid) {
180177
}
181178
current_entry.rss_kb = rss;
182179
// push back as we are not parsing other values
183-
entries.push_back(std::move(current_entry));
180+
entries.push_back(current_entry);
184181
current_entry = SmapsEntry(); // Reset for next entry
185182
} else if (line.find('-') != std::string_view::npos) {
186183
// Extract address
187-
std::string_view address = line.substr(0, line.find(' '));
188-
size_t dash_position = address.find('-');
184+
const std::string_view address = line.substr(0, line.find(' '));
185+
const size_t dash_position = address.find('-');
189186
unsigned long long start;
190187
unsigned long long end;
191188
// Convert start address
@@ -268,7 +265,9 @@ LiveAllocation::upscale_with_mapping(const PprofStacks::value_type &stack,
268265
//
269266
// What if we have a different profile type to show this?
270267
//
271-
return stack.second._value * entry->rss_kb * 1000 / accounted_value._value;
268+
constexpr int KILOBYTES_TO_BYTES = 1000;
269+
return stack.second._value * entry->rss_kb * KILOBYTES_TO_BYTES /
270+
accounted_value._value;
272271
}
273272

274273
} // namespace ddprof

src/pprof/ddprof_pprof.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ size_t prepare_labels(const UnwindOutput &uw_output, const PerfWatcher &watcher,
251251
labels[labels_num].str = to_CharSlice(uw_output.container_id);
252252
++labels_num;
253253
}
254-
if (mapping_addr) {
255-
labels[labels_num].key = to_CharSlice(k_mapping_label);
256-
labels[labels_num].str = to_CharSlice(pid_str(mapping_addr, pid_strs));
257-
++labels_num;
258-
}
259254

260255
// Add any configured labels. Note that TID alone has the same cardinality as
261256
// (TID;PID) tuples, so except for symbol table overhead it doesn't matter

0 commit comments

Comments
 (0)