Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/live_allocation-c.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0. This product includes software
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

#pragma once

namespace ddprof {
namespace liveallocation {
static constexpr auto kMaxTracked = 200000;
}
}
7 changes: 6 additions & 1 deletion include/live_allocation.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0. This product includes software
// developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present
// Datadog, Inc.

#pragma once

#include "ddprof_defs.hpp"
#include "logger.hpp"
#include "unwind_output.hpp"
#include "live_allocation-c.hpp"

#include <unordered_map>

namespace ddprof {

class LiveAllocation {
public:
static constexpr auto kMaxTracked = 200000;
void register_allocation(const UnwindOutput &stack, uintptr_t addr,
size_t size, int watcher_pos, pid_t pid) {
StackMap &stack_map = _pid_map[pid];
Expand Down
2 changes: 1 addition & 1 deletion src/ddprof_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static DDRes aggregate_live_allocations(DDProfContext *ctx) {
LG_NTC("Number of Live allocations for PID%d = %lu ", stack_map.first,
stack_map.second.size());
// Safety to avoid spending all the time reporting allocations
if (stack_map.second.size() >= LiveAllocation::kMaxTracked) {
if (stack_map.second.size() >= liveallocation::kMaxTracked) {
stack_map.second.clear();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/allocation_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ringbuffer_utils.hpp"
#include "savecontext.hpp"
#include "syscalls.hpp"
#include "live_allocation-c.hpp"

#include <atomic>
#include <cassert>
Expand Down Expand Up @@ -225,6 +226,10 @@ void AllocationTracker::track_deallocation(uintptr_t addr,

// Inserting / Erasing addresses is done within the lock
if (_address_set.erase(addr)) {
if (_address_set.size() >= liveallocation::kMaxTracked) {
// avoid unbounded growth
_address_set.clear();
}
bool success = IsDDResOK(push_dealloc_sample(addr, tl_state));
free_on_consecutive_failures(success);
}
Expand Down