Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4e56c132
Commit
4e56c132
authored
Jan 21, 2020
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: adjust type of allocator_stats counter, allow to disable
parent
3a99ebb4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
23 deletions
+84
-23
OpenCVDetectCXXCompiler.cmake
cmake/OpenCVDetectCXXCompiler.cmake
+13
-2
CMakeLists.txt
modules/core/CMakeLists.txt
+17
-0
allocator_stats.impl.hpp
.../core/include/opencv2/core/utils/allocator_stats.impl.hpp
+54
-21
No files found.
cmake/OpenCVDetectCXXCompiler.cmake
View file @
4e56c132
...
@@ -212,7 +212,13 @@ if(NOT HAVE_CXX11)
...
@@ -212,7 +212,13 @@ if(NOT HAVE_CXX11)
endif
()
endif
()
endif
()
endif
()
if
((
HAVE_CXX11
set
(
__OPENCV_ENABLE_ATOMIC_LONG_LONG OFF
)
if
(
HAVE_CXX11
AND
(
X86 OR X86_64
))
set
(
__OPENCV_ENABLE_ATOMIC_LONG_LONG ON
)
endif
()
option
(
OPENCV_ENABLE_ATOMIC_LONG_LONG
"Enable C++ compiler support for atomic<long long>"
${
__OPENCV_ENABLE_ATOMIC_LONG_LONG
}
)
if
((
HAVE_CXX11 AND OPENCV_ENABLE_ATOMIC_LONG_LONG
AND NOT MSVC
AND NOT MSVC
AND
NOT
(
X86 OR X86_64
)
AND
NOT
(
X86 OR X86_64
)
AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK
)
AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK
)
...
@@ -223,9 +229,14 @@ if((HAVE_CXX11
...
@@ -223,9 +229,14 @@ if((HAVE_CXX11
list
(
APPEND CMAKE_REQUIRED_LIBRARIES atomic
)
list
(
APPEND CMAKE_REQUIRED_LIBRARIES atomic
)
ocv_check_compiler_flag
(
CXX
""
HAVE_CXX_ATOMICS_WITH_LIB
"
${
OpenCV_SOURCE_DIR
}
/cmake/checks/atomic_check.cpp"
)
ocv_check_compiler_flag
(
CXX
""
HAVE_CXX_ATOMICS_WITH_LIB
"
${
OpenCV_SOURCE_DIR
}
/cmake/checks/atomic_check.cpp"
)
if
(
HAVE_CXX_ATOMICS_WITH_LIB
)
if
(
HAVE_CXX_ATOMICS_WITH_LIB
)
set
(
HAVE_ATOMIC_LONG_LONG ON
)
list
(
APPEND OPENCV_LINKER_LIBS atomic
)
list
(
APPEND OPENCV_LINKER_LIBS atomic
)
else
()
else
()
message
(
FATAL_ERROR
"C++11 compiler must support std::atomic
"
)
message
(
STATUS
"Compiler doesn't support std::atomic<long long>
"
)
endif
()
endif
()
else
()
set
(
HAVE_ATOMIC_LONG_LONG ON
)
endif
()
endif
()
else
(
HAVE_CXX11 AND OPENCV_ENABLE_ATOMIC_LONG_LONG
)
set
(
HAVE_ATOMIC_LONG_LONG
${
OPENCV_ENABLE_ATOMIC_LONG_LONG
}
)
endif
()
endif
()
modules/core/CMakeLists.txt
View file @
4e56c132
...
@@ -78,6 +78,23 @@ if(HAVE_MEMALIGN)
...
@@ -78,6 +78,23 @@ if(HAVE_MEMALIGN)
ocv_append_source_file_compile_definitions
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/alloc.cpp
"HAVE_MEMALIGN=1"
)
ocv_append_source_file_compile_definitions
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/alloc.cpp
"HAVE_MEMALIGN=1"
)
endif
()
endif
()
option
(
OPENCV_ENABLE_ALLOCATOR_STATS
"Enable Allocator metrics"
ON
)
if
(
NOT OPENCV_ENABLE_ALLOCATOR_STATS
)
add_definitions
(
-DOPENCV_DISABLE_ALLOCATOR_STATS=1
)
else
()
if
(
NOT DEFINED OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
)
if
(
HAVE_ATOMIC_LONG_LONG AND OPENCV_ENABLE_ATOMIC_LONG_LONG
)
set
(
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
"long long"
)
else
()
set
(
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
"int"
)
endif
()
endif
()
message
(
STATUS
"Allocator metrics storage type: '
${
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
}
'"
)
add_definitions
(
"-DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=
${
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
}
"
)
endif
()
ocv_create_module
(
${
extra_libs
}
)
ocv_create_module
(
${
extra_libs
}
)
ocv_target_link_libraries
(
${
the_module
}
PRIVATE
ocv_target_link_libraries
(
${
the_module
}
PRIVATE
...
...
modules/core/include/opencv2/core/utils/allocator_stats.impl.hpp
View file @
4e56c132
...
@@ -11,32 +11,55 @@
...
@@ -11,32 +11,55 @@
#include <atomic>
#include <atomic>
#endif
#endif
//#define OPENCV_DISABLE_ALLOCATOR_STATS
namespace
cv
{
namespace
utils
{
namespace
cv
{
namespace
utils
{
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
#if defined(__GNUC__) && (\
(defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4) || \
(defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \
)
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int
#endif
#endif
#ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
#define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long
#endif
#ifdef CV__ALLOCATOR_STATS_LOG
#ifdef CV__ALLOCATOR_STATS_LOG
namespace
{
namespace
{
#endif
#endif
class
AllocatorStatistics
:
public
AllocatorStatisticsInterface
class
AllocatorStatistics
:
public
AllocatorStatisticsInterface
{
{
protected
:
#ifdef OPENCV_DISABLE_ALLOCATOR_STATS
#ifdef CV_CXX11
std
::
atomic
<
long
long
>
curr
,
total
,
total_allocs
,
peak
;
#else
volatile
long
long
curr
,
total
,
total_allocs
,
peak
;
// overflow is possible, CV_XADD operates with 'int' only
#endif
public
:
public
:
AllocatorStatistics
()
AllocatorStatistics
()
{}
#ifndef CV_CXX11
:
curr
(
0
),
total
(
0
),
total_allocs
(
0
),
peak
(
0
)
#endif
{}
~
AllocatorStatistics
()
CV_OVERRIDE
{}
~
AllocatorStatistics
()
CV_OVERRIDE
{}
// AllocatorStatisticsInterface
uint64_t
getCurrentUsage
()
const
CV_OVERRIDE
{
return
0
;
}
uint64_t
getTotalUsage
()
const
CV_OVERRIDE
{
return
0
;
}
uint64_t
getNumberOfAllocations
()
const
CV_OVERRIDE
{
return
0
;
}
uint64_t
getPeakUsage
()
const
CV_OVERRIDE
{
return
0
;
}
/** set peak usage = current usage */
void
resetPeakUsage
()
CV_OVERRIDE
{};
void
onAllocate
(
size_t
/*sz*/
)
{}
void
onFree
(
size_t
/*sz*/
)
{}
#elif defined(CV_CXX11)
protected
:
typedef
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
counter_t
;
std
::
atomic
<
counter_t
>
curr
,
total
,
total_allocs
,
peak
;
public
:
AllocatorStatistics
()
{}
~
AllocatorStatistics
()
CV_OVERRIDE
{}
#ifdef CV_CXX11
uint64_t
getCurrentUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
curr
.
load
();
}
uint64_t
getCurrentUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
curr
.
load
();
}
uint64_t
getTotalUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total
.
load
();
}
uint64_t
getTotalUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total
.
load
();
}
uint64_t
getNumberOfAllocations
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total_allocs
.
load
();
}
uint64_t
getNumberOfAllocations
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total_allocs
.
load
();
}
...
@@ -52,7 +75,7 @@ public:
...
@@ -52,7 +75,7 @@ public:
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"allocate: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
.
load
()));
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"allocate: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
.
load
()));
#endif
#endif
long
long
new_curr
=
curr
.
fetch_add
((
long
long
)
sz
)
+
(
long
long
)
sz
;
counter_t
new_curr
=
curr
.
fetch_add
((
counter_t
)
sz
)
+
(
counter_t
)
sz
;
// peak = std::max((uint64_t)peak, new_curr);
// peak = std::max((uint64_t)peak, new_curr);
auto
prev_peak
=
peak
.
load
();
auto
prev_peak
=
peak
.
load
();
...
@@ -63,7 +86,7 @@ public:
...
@@ -63,7 +86,7 @@ public:
}
}
// end of peak = max(...)
// end of peak = max(...)
total
+=
(
long
long
)
sz
;
total
+=
(
counter_t
)
sz
;
total_allocs
++
;
total_allocs
++
;
}
}
void
onFree
(
size_t
sz
)
void
onFree
(
size_t
sz
)
...
@@ -71,10 +94,20 @@ public:
...
@@ -71,10 +94,20 @@ public:
#ifdef CV__ALLOCATOR_STATS_LOG
#ifdef CV__ALLOCATOR_STATS_LOG
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"free: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
.
load
()));
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"free: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
.
load
()));
#endif
#endif
curr
-=
(
long
long
)
sz
;
curr
-=
(
counter_t
)
sz
;
}
}
#else
#else // non C++11
protected
:
typedef
OPENCV_ALLOCATOR_STATS_COUNTER_TYPE
counter_t
;
volatile
counter_t
curr
,
total
,
total_allocs
,
peak
;
// overflow is possible, CV_XADD operates with 'int' only
public
:
AllocatorStatistics
()
:
curr
(
0
),
total
(
0
),
total_allocs
(
0
),
peak
(
0
)
{}
~
AllocatorStatistics
()
CV_OVERRIDE
{}
uint64_t
getCurrentUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
curr
;
}
uint64_t
getCurrentUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
curr
;
}
uint64_t
getTotalUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total
;
}
uint64_t
getTotalUsage
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total
;
}
uint64_t
getNumberOfAllocations
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total_allocs
;
}
uint64_t
getNumberOfAllocations
()
const
CV_OVERRIDE
{
return
(
uint64_t
)
total_allocs
;
}
...
@@ -89,21 +122,21 @@ public:
...
@@ -89,21 +122,21 @@ public:
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"allocate: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
));
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"allocate: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
));
#endif
#endif
uint64_t
new_curr
=
(
uint64_t
)
CV_XADD
(
&
curr
,
(
uint64_t
)
sz
)
+
sz
;
counter_t
new_curr
=
(
counter_t
)
CV_XADD
(
&
curr
,
(
counter_t
)
sz
)
+
(
counter_t
)
sz
;
peak
=
std
::
max
((
uint64
_t
)
peak
,
new_curr
);
// non-thread safe
peak
=
std
::
max
((
counter
_t
)
peak
,
new_curr
);
// non-thread safe
//CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable...
//CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable...
total
+=
sz
;
total
+=
sz
;
CV_XADD
(
&
total_allocs
,
(
uint64
_t
)
1
);
CV_XADD
(
&
total_allocs
,
(
counter
_t
)
1
);
}
}
void
onFree
(
size_t
sz
)
void
onFree
(
size_t
sz
)
{
{
#ifdef CV__ALLOCATOR_STATS_LOG
#ifdef CV__ALLOCATOR_STATS_LOG
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"free: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
));
CV__ALLOCATOR_STATS_LOG
(
cv
::
format
(
"free: %lld (curr=%lld)"
,
(
long
long
int
)
sz
,
(
long
long
int
)
curr
));
#endif
#endif
CV_XADD
(
&
curr
,
(
uint64
_t
)
-
sz
);
CV_XADD
(
&
curr
,
(
counter
_t
)
-
sz
);
}
}
#endif
#endif
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment