5
#ifndef OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP
6
#define OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP
8
#include "./allocator_stats.hpp"
16
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
17
#if defined(__GNUC__) && (\
18
(defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4) || \
19
(defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \
21
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int
25
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
26
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long
31
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
32
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int
37
namespace
cv
{
namespace
utils {
39
#ifdef CV__ALLOCATOR_STATS_LOG
45
#ifdef OPENCV_DISABLE_ALLOCATOR_STATS
51
uint64_t getCurrentUsage()
const
CV_OVERRIDE {
return
0; }
52
uint64_t getTotalUsage()
const
CV_OVERRIDE {
return
0; }
53
uint64_t getNumberOfAllocations()
const
CV_OVERRIDE {
return
0; }
54
uint64_t getPeakUsage()
const
CV_OVERRIDE {
return
0; }
59
void
onAllocate(
size_t
) {}
60
void
onFree(
size_t
) {}
62
#elif defined(CV_CXX11)
65
typedef
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
66
std::atomic<counter_t> curr, total, total_allocs, peak;
71
uint64_t getCurrentUsage()
const
CV_OVERRIDE {
return
(uint64_t)curr.load(); }
72
uint64_t getTotalUsage()
const
CV_OVERRIDE {
return
(uint64_t)total.load(); }
73
uint64_t getNumberOfAllocations()
const
CV_OVERRIDE {
return
(uint64_t)total_allocs.load(); }
74
uint64_t getPeakUsage()
const
CV_OVERRIDE {
return
(uint64_t)peak.load(); }
80
void
onAllocate(
size_t
sz)
82
#ifdef CV__ALLOCATOR_STATS_LOG
83
CV__ALLOCATOR_STATS_LOG(cv::format(
"allocate: %lld (curr=%lld)", (
long
long
int)sz, (
long
long
int)curr.load()));
86
counter_t new_curr = curr.fetch_add((counter_t)sz) + (counter_t)sz;
89
auto
prev_peak = peak.load();
90
while
(prev_peak < new_curr)
92
if
(peak.compare_exchange_weak(prev_peak, new_curr))
97
total += (counter_t)sz;
100
void
onFree(
size_t
sz)
102
#ifdef CV__ALLOCATOR_STATS_LOG
103
CV__ALLOCATOR_STATS_LOG(cv::format(
"free: %lld (curr=%lld)", (
long
long
int)sz, (
long
long
int)curr.load()));
105
curr -= (counter_t)sz;
111
typedef
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t;
112
volatile
counter_t curr, total, total_allocs, peak;
115
: curr(0), total(0), total_allocs(0), peak(0)
119
uint64_t getCurrentUsage()
const
CV_OVERRIDE {
return
(uint64_t)curr; }
120
uint64_t getTotalUsage()
const
CV_OVERRIDE {
return
(uint64_t)total; }
121
uint64_t getNumberOfAllocations()
const
CV_OVERRIDE {
return
(uint64_t)total_allocs; }
122
uint64_t getPeakUsage()
const
CV_OVERRIDE {
return
(uint64_t)peak; }
127
void
onAllocate(
size_t
sz)
129
#ifdef CV__ALLOCATOR_STATS_LOG
130
CV__ALLOCATOR_STATS_LOG(cv::format(
"allocate: %lld (curr=%lld)", (
long
long
int)sz, (
long
long
int)curr));
133
counter_t new_curr = (counter_t)CV_XADD(&curr, (counter_t)sz) + (counter_t)sz;
135
peak =
std::max((counter_t)peak, new_curr);
140
CV_XADD(&total_allocs, (counter_t)1);
142
void
onFree(
size_t
sz)
144
#ifdef CV__ALLOCATOR_STATS_LOG
145
CV__ALLOCATOR_STATS_LOG(cv::format(
"free: %lld (curr=%lld)", (
long
long
int)sz, (
long
long
int)curr));
147
CV_XADD(&curr, (counter_t)-sz);
152
#ifdef CV__ALLOCATOR_STATS_LOG
Definition:
allocator_stats.impl.hpp:44
void resetPeakUsage() CV_OVERRIDE
Definition:
allocator_stats.impl.hpp:124
Definition:
allocator_stats.hpp:13
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst)
Calculates per-element maximum of two arrays or an array and a scalar.
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75