Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code tracing support #8766

Merged
merged 3 commits into from Jun 26, 2017
Merged

Code tracing support #8766

merged 3 commits into from Jun 26, 2017

Conversation

alalek
Copy link
Member

@alalek alalek commented May 22, 2017

  • Wiki page
    • creating example for OpenCV tracing documentation
  • parallel_for support issues
    • fix issue with TBB parallel_for backend (cloning of ParallelLoopBodyWrapper)
    • fix bug with nested parallel_for calls
  • trace: IPP time measurement for all calls (CV_INSTRUMENT_FUN_IPP macro is not covered - requires C++11 support or huge refactoring). Done: added processing of CV_RUN_IPP* calls
    • fix processing of "skipped" inner calls from parallel_for
    • similar changes for OpenCL code path (with optional clFinish)
  • trace: fix timestamp measurement on Windows platform
  • analyzer sample (trace_profiler.py): sample for reading OpenCV trace logs
  • analyzer: integrate with test suite run.py script
  • analyzer: process IPP/OpenCL metrics. OpenCL metrics without clFinish calls are not useful.
  • analyzer: more accurate parallel_for calls processing (thread count amplification)
  • remove temporary DEBUG code (debug commits are moved on trace_test branch)
  • fixed Python bindings generation with CV_TRACE=OFF

Examples:

Binary size increase with enabled CV_TRACE (set to default):

  • without contrib, Linux x64, release, shared, with IPP, no MKL: ~1% (107261565 vs 107144200, diff 117365 bytes)


//! Supported logging levels and their semantic
enum LogLevel {
LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be better to use CamelCase naming for enum items to avoid possible conflicts with user-defined macros.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header should not be included automatically with any of public OpenCV header file (like opencv.hpp), so serious problems are not expected.

BTW, CamelCase for "enumeration constants" violates Naming conventions guidelines.


//! Specify region flags
enum RegionLocationFlag {
REGION_FLAG_FUNCTION = (1 << 0), //< region is function (=1) / nested named region (=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about enum item naming.

//! Macro to trace argument value (expanded version)
#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value)

#ifndef CV_DOXYGEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to use //! @cond IGNORED?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to add this definition to cvconfig.h?

@alalek
Copy link
Member Author

alalek commented Jun 20, 2017

/cc @slyalin

@mshabunin
Copy link
Contributor

Looks good to me! 👍

I have one question: are we going to add HAL-implementation and/or CPU dispatched blocks measurements?

env = {}
if not self.options.valgrind and self.options.trace:
env['OPENCV_TRACE'] = '1'
env['OPENCV_TRACE_LOCATION'] = 'OpenCVTrace-{}'.format(self.getLogBaseName(exe))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please help me to locate where this env var is really used in the tracing code? Is it in a new code (cannot find it easily)? And when we set this var, do we automatically switch to a text backend instead of ITT backend. I was just trying to follow https://github.com/opencv/opencv/wiki/Profiling-OpenCV-Applications, and searching for this part "An alternative to the ITT-based instrumentation, is to trace the OpenCV calls in the compact machine-readable text form". Could you please point me to specific file/line when I can start reviewing this specific part?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is located in modules/core/src/trace.cpp file (GitHub doesn't load its content due "Large diffs are not rendered by default") - you need to click "Load diffs" button.

There is link to parameter in .cpp file

static int param_maxRegionDepthOpenCV = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_DEPTH_OPENCV", 1);
static int param_maxRegionChildrenOpenCV = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_MAX_CHILDREN_OPENCV", 1000);
static int param_maxRegionChildren = (int)utils::getConfigurationParameterSizeT("OPENCV_TRACE_MAX_CHILDREN", 10000);
static cv::String param_traceLocation = utils::getConfigurationParameterString("OPENCV_TRACE_LOCATION", "OpenCVTrace");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slyalin OPENCV_TRACE_LOCATION is used here.

Copy link

@slyalin slyalin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct observation that there is no "loopinizer" script here?

@alalek
Copy link
Member Author

alalek commented Jun 26, 2017

It's correct. There is no script with "loop folding".

@opencv-pushbot opencv-pushbot merged commit 006966e into opencv:master Jun 26, 2017
opencv-pushbot pushed a commit that referenced this pull request Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants