Skip to content

Commit

Permalink
trace: initial support for code trace
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Jun 26, 2017
1 parent 07aff8e commit 006966e
Show file tree
Hide file tree
Showing 58 changed files with 2,953 additions and 175 deletions.
13 changes: 13 additions & 0 deletions 3rdparty/ittnotify/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ if(NOT ITT_LIBRARY)
endif()
project(${ITT_LIBRARY} C)

if(NOT WIN32)
include(CheckLibraryExists)
if(COMMAND CHECK_LIBRARY_EXISTS)
CHECK_LIBRARY_EXISTS(dl dlerror "" HAVE_DL_LIBRARY)
endif()
endif()

ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
set(ITT_INCLUDE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")

Expand All @@ -30,6 +37,12 @@ set(ITT_SRCS

add_library(${ITT_LIBRARY} STATIC ${ITT_SRCS} ${ITT_PUBLIC_HDRS} ${ITT_PRIVATE_HDRS})

if(NOT WIN32)
if(HAVE_DL_LIBRARY)
target_link_libraries(${ITT_LIBRARY} dl)
endif()
endif()

if(UNIX)
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
Expand Down
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF
OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" ON IF (UNIX AND NOT ANDROID) )
OCV_OPTION(WITH_LAPACK "Include Lapack library support" ON IF (NOT ANDROID AND NOT IOS) )
OCV_OPTION(WITH_ITT "Include Intel ITT support" ON IF (NOT APPLE_FRAMEWORK) )

# OpenCV build components
# ===================================================
Expand Down Expand Up @@ -291,6 +292,7 @@ OCV_OPTION(BUILD_PNG "Build libpng from source" WIN32 O
OCV_OPTION(BUILD_OPENEXR "Build openexr from source" (WIN32 OR ANDROID OR APPLE) AND NOT WINRT)
OCV_OPTION(BUILD_TBB "Download and build TBB from source" ANDROID )
OCV_OPTION(BUILD_IPP_IW "Build IPP IW from source" NOT MINGW IF (X86_64 OR X86) AND NOT WINRT )
OCV_OPTION(BUILD_ITT "Build Intel ITT from source" NOT MINGW IF (X86_64 OR X86) AND NOT WINRT AND NOT APPLE_FRAMEWORK )

# OpenCV installation options
# ===================================================
Expand Down Expand Up @@ -324,7 +326,7 @@ OCV_OPTION(ENABLE_BUILD_HARDENING "Enable hardening of the resulting binarie
OCV_OPTION(GENERATE_ABI_DESCRIPTOR "Generate XML file for abi_compliance_checker tool" OFF IF UNIX)
OCV_OPTION(CV_ENABLE_INTRINSICS "Use intrinsic-based optimized code" ON )
OCV_OPTION(CV_DISABLE_OPTIMIZATION "Disable explicit optimized code (dispatched code/intrinsics/loop unrolling/etc)" OFF )

OCV_OPTION(CV_TRACE "Enable OpenCV code trace" ON)


if(ENABLE_IMPL_COLLECTION)
Expand Down Expand Up @@ -733,6 +735,16 @@ if(HAVE_CUDA)
endif()
endforeach()
endif()


# ----------------------------------------------------------------------------
# Code trace support
# ----------------------------------------------------------------------------
if(CV_TRACE)
include(cmake/OpenCVDetectTrace.cmake)
endif()


# ----------------------------------------------------------------------------
# Solution folders:
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1278,6 +1290,14 @@ endif()
status("")
status(" Parallel framework:" TRUE THEN "${CV_PARALLEL_FRAMEWORK}" ELSE NO)

if(CV_TRACE OR OPENCV_TRACE)
set(__msg "")
if(HAVE_ITT)
set(__msg "with Intel ITT")
endif()
status("")
status(" Trace: " OPENCV_TRACE THEN "YES (${__msg})" ELSE NO)
endif()

# ========================== Other third-party libraries ==========================
status("")
Expand Down
2 changes: 2 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
add_definitions(-D__OPENCV_BUILD=1)
add_definitions(-D__OPENCV_APPS=1)

link_libraries(${OPENCV_LINKER_LIBS})

add_subdirectory(traincascade)
Expand Down
6 changes: 6 additions & 0 deletions apps/version/opencv_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/core/utils/trace.hpp>

int main(int argc, const char** argv)
{
CV_TRACE_FUNCTION();
CV_TRACE_ARG(argc);
CV_TRACE_ARG_VALUE(argv0, "argv0", argv[0]);
CV_TRACE_ARG_VALUE(argv1, "argv1", argv[1]);

cv::CommandLineParser parser(argc, argv,
"{ help h usage ? | | show this help message }"
"{ verbose v | | show build configuration log }"
Expand Down
13 changes: 13 additions & 0 deletions cmake/OpenCVDetectTrace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if(WITH_ITT)
if(BUILD_ITT)
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/ittnotify")
set(ITT_INCLUDE_DIR "${OpenCV_SOURCE_DIR}/3rdparty/ittnotify/include")
set(ITT_INCLUDE_DIRS "${ITT_INCLUDE_DIR}")
set(ITT_LIBRARIES "ittnotify")
set(HAVE_ITT 1)
else()
#TODO
endif()
endif()

set(OPENCV_TRACE 1)
6 changes: 5 additions & 1 deletion cmake/OpenCVModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ macro(ocv_glob_module_sources)
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/hal/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/hal/*.h"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/utils/*.hpp"
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/utils/*.h"
)
file(GLOB lib_hdrs_detail
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/detail/*.hpp"
Expand Down Expand Up @@ -927,7 +929,7 @@ macro(_ocv_create_module)
if(OPENCV_MODULE_${m}_HEADERS AND ";${OPENCV_MODULES_PUBLIC};" MATCHES ";${m};")
foreach(hdr ${OPENCV_MODULE_${m}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(NOT hdr2 MATCHES "opencv2/${m}/private.*" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
if(NOT hdr2 MATCHES "private" AND hdr2 MATCHES "^(opencv2/?.*)/[^/]+.h(..)?$" )
install(FILES ${hdr} OPTIONAL DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev)
endif()
endforeach()
Expand Down Expand Up @@ -1158,6 +1160,8 @@ function(ocv_add_accuracy_tests)
RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
)

ocv_append_target_property(${the_target} COMPILE_DEFINITIONS "__OPENCV_TESTS=1")

if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/templates/cvconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,8 @@
#define HAVE_VIDEO_OUTPUT
#endif

/* OpenCV trace utilities */
#cmakedefine OPENCV_TRACE


#endif // OPENCV_CVCONFIG_H_INCLUDED
3 changes: 3 additions & 0 deletions modules/calib3d/test/test_stereomatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,11 @@ TEST(Calib3d_StereoSGBM_HH4, regression)
{
String path = cvtest::TS::ptr()->get_data_path() + "cv/stereomatching/datasets/teddy/";
Mat leftImg = imread(path + "im2.png", 0);
ASSERT_FALSE(leftImg.empty());
Mat rightImg = imread(path + "im6.png", 0);
ASSERT_FALSE(rightImg.empty());
Mat testData = imread(path + "disp2_hh4.png",-1);
ASSERT_FALSE(testData.empty());
Mat leftDisp;
Mat toCheck;
{
Expand Down
13 changes: 12 additions & 1 deletion modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ if(HAVE_CUDA)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wenum-compare -Wunused-function -Wshadow)
endif()

if(CV_TRACE AND HAVE_ITT AND BUILD_ITT)
add_definitions(-DOPENCV_WITH_ITT=1)
endif()

file(GLOB lib_cuda_hdrs "include/opencv2/${name}/cuda/*.hpp" "include/opencv2/${name}/cuda/*.h")
file(GLOB lib_cuda_hdrs_detail "include/opencv2/${name}/cuda/detail/*.hpp" "include/opencv2/${name}/cuda/detail/*.h")

Expand All @@ -37,9 +41,16 @@ if(ANDROID AND HAVE_CPUFEATURES)
ocv_append_sourge_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/system.cpp "HAVE_CPUFEATURES=1")
ocv_module_include_directories(${CPUFEATURES_INCLUDE_DIRS})
endif()
if(ITT_INCLUDE_DIRS)
ocv_module_include_directories(${ITT_INCLUDE_DIRS})
endif()
ocv_create_module(${extra_libs})

ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}")
ocv_target_link_libraries(${the_module}
"${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
"${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}"
"${ITT_LIBRARIES}"
)

ocv_add_accuracy_tests()
ocv_add_perf_tests()
16 changes: 9 additions & 7 deletions modules/core/include/opencv2/core/cvstd.inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@

//! @cond IGNORED

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4127 )
#endif

namespace cv
{
#ifndef OPENCV_NOSTL
Expand Down Expand Up @@ -233,14 +238,7 @@ template<typename _Tp, int n> static inline
std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
{
out << "[";
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4127 )
#endif
if(Vec<_Tp, n>::depth < CV_32F)
#ifdef _MSC_VER
#pragma warning( pop )
#endif
{
for (int i = 0; i < n - 1; ++i) {
out << (int)vec[i] << ", ";
Expand Down Expand Up @@ -285,6 +283,10 @@ static inline std::ostream& operator << (std::ostream& out, const MatSize& msize
#endif // OPENCV_NOSTL
} // cv

#ifdef _MSC_VER
#pragma warning( pop )
#endif

//! @endcond

#endif // OPENCV_CORE_CVSTDINL_HPP
9 changes: 9 additions & 0 deletions modules/core/include/opencv2/core/mat.inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
# error mat.inl.hpp header must be compiled as C++
#endif

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable: 4127 )
#endif

namespace cv
{

Expand Down Expand Up @@ -3855,4 +3860,8 @@ inline UMatDataAutoLock::~UMatDataAutoLock() { u->unlock(); }

} //cv

#ifdef _MSC_VER
#pragma warning( pop )
#endif

#endif
33 changes: 17 additions & 16 deletions modules/core/include/opencv2/core/private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "opencv2/core.hpp"
#include "cvconfig.h"

#include <opencv2/core/utils/trace.hpp>

#ifdef HAVE_EIGEN
# if defined __GNUC__ && defined __APPLE__
# pragma GCC diagnostic ignored "-Wshadow"
Expand Down Expand Up @@ -548,6 +550,7 @@ static struct __IppInitializer__ __ipp_initializer__;
{ \
if (cv::ipp::useIPP() && (condition)) \
{ \
CV__TRACE_REGION_("IPP:" #func, CV_TRACE_NS::details::REGION_FLAG_IMPL_IPP) \
if(func) \
{ \
CV_IMPL_ADD(CV_IMPL_IPP); \
Expand All @@ -562,23 +565,21 @@ static struct __IppInitializer__ __ipp_initializer__;
}
#else
#define CV_IPP_RUN_(condition, func, ...) \
if (cv::ipp::useIPP() && (condition) && (func)) \
{ \
CV_IMPL_ADD(CV_IMPL_IPP); \
return __VA_ARGS__; \
}
if (cv::ipp::useIPP() && (condition)) \
{ \
CV__TRACE_REGION_("IPP:" #func, CV_TRACE_NS::details::REGION_FLAG_IMPL_IPP) \
if(func) \
{ \
CV_IMPL_ADD(CV_IMPL_IPP); \
return __VA_ARGS__; \
} \
}
#endif
#define CV_IPP_RUN_FAST(func, ...) \
if (cv::ipp::useIPP() && (func)) \
{ \
CV_IMPL_ADD(CV_IMPL_IPP); \
return __VA_ARGS__; \
}
#else
#define CV_IPP_RUN_(condition, func, ...)
#define CV_IPP_RUN_FAST(func, ...)
#endif

#define CV_IPP_RUN_FAST(func, ...) CV_IPP_RUN_(true, func, __VA_ARGS__)
#define CV_IPP_RUN(condition, func, ...) CV_IPP_RUN_((condition), (func), __VA_ARGS__)


Expand Down Expand Up @@ -768,15 +769,15 @@ CV_EXPORTS InstrNode* getCurrentNode();
#else
#define CV_INSTRUMENT_REGION_META(...)

#define CV_INSTRUMENT_REGION_()
#define CV_INSTRUMENT_REGION_NAME(...)
#define CV_INSTRUMENT_REGION_() CV_TRACE_FUNCTION()
#define CV_INSTRUMENT_REGION_NAME(...) CV_TRACE_REGION(__VA_ARGS__)
#define CV_INSTRUMENT_REGION_MT_FORK()

#define CV_INSTRUMENT_REGION_IPP()
#define CV_INSTRUMENT_REGION_IPP() CV__TRACE_REGION_("IPP", CV_TRACE_NS::details::REGION_FLAG_IMPL_IPP)
#define CV_INSTRUMENT_FUN_IPP(FUN, ...) ((FUN)(__VA_ARGS__))
#define CV_INSTRUMENT_MARK_IPP(...)

#define CV_INSTRUMENT_REGION_OPENCL()
#define CV_INSTRUMENT_REGION_OPENCL() CV__TRACE_REGION_("OpenCL", CV_TRACE_NS::details::REGION_FLAG_IMPL_OPENCL)
#define CV_INSTRUMENT_REGION_OPENCL_COMPILE(...)
#define CV_INSTRUMENT_REGION_OPENCL_RUN(...)
#define CV_INSTRUMENT_MARK_OPENCL(...)
Expand Down
7 changes: 7 additions & 0 deletions modules/core/include/opencv2/core/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ class TLSData : protected TLSDataContainer
inline TLSData() {}
inline ~TLSData() { release(); } // Release key and delete associated data
inline T* get() const { return (T*)getData(); } // Get data associated with key
inline T& getRef() const { T* ptr = (T*)getData(); CV_Assert(ptr); return *ptr; } // Get data associated with key

// Get data from all threads
inline void gather(std::vector<T*> &data) const
Expand Down Expand Up @@ -1168,6 +1169,12 @@ static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); }
CV_EXPORTS FLAGS getFlags();
}

namespace utils {

CV_EXPORTS int getThreadID();

} // namespace

} //namespace cv

#ifndef DISABLE_OPENCV_24_COMPATIBILITY
Expand Down
Loading

0 comments on commit 006966e

Please sign in to comment.