Skip to content

Commit

Permalink
Added debugging of memory use
Browse files Browse the repository at this point in the history
  • Loading branch information
artyom-beilis committed Apr 8, 2024
1 parent 1383d9f commit a0bd14c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/ols_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,55 @@ bool parse_key_value(std::string arg,cppcms::json::value &cfg)

}

//#define DEBUG_ALLOCATOR
#ifdef DEBUG_ALLOCATOR

static cv::MatAllocator *stda = nullptr;



static std::atomic<int> counter_a;
static std::atomic<size_t> memory_use;
static std::atomic<size_t> memory_max;


class MyAlloc : public cv::MatAllocator
{
public:
virtual cv::UMatData * allocate (int dims, const int *sizes, int type, void *data, size_t *step, cv::AccessFlag flags, cv::UMatUsageFlags usageFlags) const override
{
cv::UMatData *p = stda->allocate(dims,sizes,type,data,step,flags,usageFlags);
p->currAllocator = this;
memory_use += p->size;
memory_max = std::max(size_t(memory_max),size_t(memory_use));
std::cerr << "A1 " << int(counter_a++) << " total " << memory_use / 1024 / 1024 << " max=" << memory_max / 1024 / 1024<< std::endl;
return p;
}
virtual bool allocate (cv::UMatData *data, cv::AccessFlag accessflags, cv::UMatUsageFlags usageFlags) const override
{
std::cerr << "A2 " << int(counter_a++) << std::endl;
return stda->allocate(data,accessflags,usageFlags);
}
virtual void deallocate ( cv::UMatData * data ) const override
{
memory_use -= data->size;
std::cerr << "D " << int(--counter_a) << " total " << memory_use / 1024 / 1024 << std::endl;
stda->deallocate(data);
}

} alloc_inst;

#endif

int main(int argc,char **argv)
{
try {

#ifdef DEBUG_ALLOCATOR
stda = cv::Mat::getStdAllocator();
cv::Mat::setDefaultAllocator(&alloc_inst);
#endif

std::string path;
std::string driver;
std::string driver_opt;
Expand Down

0 comments on commit a0bd14c

Please sign in to comment.