instrumentation.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef OPENCV_UTILS_INSTR_HPP
  5. #define OPENCV_UTILS_INSTR_HPP
  6. #include <opencv2/core/utility.hpp>
  7. #include <opencv2/core/utils/tls.hpp>
  8. namespace cv {
  9. //! @addtogroup core_utils
  10. //! @{
  11. #ifdef CV_COLLECT_IMPL_DATA
  12. CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays
  13. CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays
  14. // Get stored implementation flags and functions names arrays
  15. // Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function
  16. CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName);
  17. CV_EXPORTS bool useCollection(); // return implementation collection state
  18. CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state
  19. #define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation
  20. #define CV_IMPL_OCL 0x02 // OpenCL implementation
  21. #define CV_IMPL_IPP 0x04 // IPP implementation
  22. #define CV_IMPL_MT 0x10 // multithreaded implementation
  23. #undef CV_IMPL_ADD
  24. #define CV_IMPL_ADD(impl) \
  25. if(cv::useCollection()) \
  26. { \
  27. cv::addImpl(impl, CV_Func); \
  28. }
  29. #endif
  30. // Instrumentation external interface
  31. namespace instr
  32. {
  33. #if !defined OPENCV_ABI_CHECK
  34. enum TYPE
  35. {
  36. TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function
  37. TYPE_MARKER, // Information marker
  38. TYPE_WRAPPER, // Wrapper function for implementation
  39. TYPE_FUN, // Simple function call
  40. };
  41. enum IMPL
  42. {
  43. IMPL_PLAIN = 0,
  44. IMPL_IPP,
  45. IMPL_OPENCL,
  46. };
  47. struct NodeDataTls
  48. {
  49. NodeDataTls()
  50. {
  51. m_ticksTotal = 0;
  52. }
  53. uint64 m_ticksTotal;
  54. };
  55. class CV_EXPORTS NodeData
  56. {
  57. public:
  58. NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN);
  59. NodeData(NodeData &ref);
  60. ~NodeData();
  61. NodeData& operator=(const NodeData&);
  62. cv::String m_funName;
  63. cv::instr::TYPE m_instrType;
  64. cv::instr::IMPL m_implType;
  65. const char* m_fileName;
  66. int m_lineNum;
  67. void* m_retAddress;
  68. bool m_alwaysExpand;
  69. bool m_funError;
  70. volatile int m_counter;
  71. volatile uint64 m_ticksTotal;
  72. TLSDataAccumulator<NodeDataTls> m_tls;
  73. int m_threads;
  74. // No synchronization
  75. double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; }
  76. double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; }
  77. };
  78. bool operator==(const NodeData& lhs, const NodeData& rhs);
  79. typedef Node<NodeData> InstrNode;
  80. CV_EXPORTS InstrNode* getTrace();
  81. #endif // !defined OPENCV_ABI_CHECK
  82. CV_EXPORTS bool useInstrumentation();
  83. CV_EXPORTS void setUseInstrumentation(bool flag);
  84. CV_EXPORTS void resetTrace();
  85. enum FLAGS
  86. {
  87. FLAGS_NONE = 0,
  88. FLAGS_MAPPING = 0x01,
  89. FLAGS_EXPAND_SAME_NAMES = 0x02,
  90. };
  91. CV_EXPORTS void setFlags(FLAGS modeFlags);
  92. static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); }
  93. CV_EXPORTS FLAGS getFlags();
  94. } // namespace instr
  95. //! @}
  96. } // namespace
  97. #endif // OPENCV_UTILS_TLS_HPP