ClickHouse/src/Common/AllocationTrace.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
943 B
C++
Raw Normal View History

#pragma once
#include <cstddef>
2023-01-16 15:48:44 +00:00
#include <base/defines.h>
/// This is a structure which is returned by MemoryTracker.
/// Methods onAlloc/onFree should be called after actual memory allocation if it succeed.
/// For now, it will only collect allocation trace with sample_probability.
struct AllocationTrace
{
AllocationTrace() = default;
2023-01-17 14:44:42 +00:00
explicit AllocationTrace(double sample_probability_) : sample_probability(sample_probability_) {}
2023-01-16 15:48:44 +00:00
ALWAYS_INLINE void onAlloc(void * ptr, size_t size) const
{
2023-07-20 16:10:56 +00:00
if (likely(sample_probability <= 0))
2023-01-16 15:48:44 +00:00
return;
2023-01-16 15:48:44 +00:00
onAllocImpl(ptr, size);
}
ALWAYS_INLINE void onFree(void * ptr, size_t size) const
{
2023-07-20 16:10:56 +00:00
if (likely(sample_probability <= 0))
2023-01-16 15:48:44 +00:00
return;
onFreeImpl(ptr, size);
}
private:
double sample_probability = 0;
2023-01-16 15:48:44 +00:00
void onAllocImpl(void * ptr, size_t size) const;
void onFreeImpl(void * ptr, size_t size) const;
};