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 | |
5 | #ifndef OPENCV_UTILS_INSTR_HPP |
6 | #define OPENCV_UTILS_INSTR_HPP |
7 | |
8 | #include <opencv2/core/utility.hpp> |
9 | #include <opencv2/core/utils/tls.hpp> |
10 | |
11 | namespace cv { |
12 | |
13 | //! @addtogroup core_utils |
14 | //! @{ |
15 | |
16 | #ifdef CV_COLLECT_IMPL_DATA |
17 | CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays |
18 | CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays |
19 | // Get stored implementation flags and functions names arrays |
20 | // Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function |
21 | CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName); |
22 | |
23 | CV_EXPORTS bool useCollection(); // return implementation collection state |
24 | CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state |
25 | |
26 | #define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation |
27 | #define CV_IMPL_OCL 0x02 // OpenCL implementation |
28 | #define CV_IMPL_IPP 0x04 // IPP implementation |
29 | #define CV_IMPL_MT 0x10 // multithreaded implementation |
30 | |
31 | #undef CV_IMPL_ADD |
32 | #define CV_IMPL_ADD(impl) \ |
33 | if(cv::useCollection()) \ |
34 | { \ |
35 | cv::addImpl(impl, CV_Func); \ |
36 | } |
37 | #endif |
38 | |
39 | // Instrumentation external interface |
40 | namespace instr |
41 | { |
42 | |
43 | #if !defined OPENCV_ABI_CHECK |
44 | |
45 | enum TYPE |
46 | { |
47 | TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function |
48 | TYPE_MARKER, // Information marker |
49 | TYPE_WRAPPER, // Wrapper function for implementation |
50 | TYPE_FUN, // Simple function call |
51 | }; |
52 | |
53 | enum IMPL |
54 | { |
55 | IMPL_PLAIN = 0, |
56 | IMPL_IPP, |
57 | IMPL_OPENCL, |
58 | }; |
59 | |
60 | struct NodeDataTls |
61 | { |
62 | NodeDataTls() |
63 | { |
64 | m_ticksTotal = 0; |
65 | } |
66 | uint64 m_ticksTotal; |
67 | }; |
68 | |
69 | class CV_EXPORTS NodeData |
70 | { |
71 | public: |
72 | 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); |
73 | NodeData(NodeData &ref); |
74 | ~NodeData(); |
75 | NodeData& operator=(const NodeData&); |
76 | |
77 | cv::String m_funName; |
78 | cv::instr::TYPE m_instrType; |
79 | cv::instr::IMPL m_implType; |
80 | const char* m_fileName; |
81 | int m_lineNum; |
82 | void* m_retAddress; |
83 | bool m_alwaysExpand; |
84 | bool m_funError; |
85 | |
86 | volatile int m_counter; |
87 | volatile uint64 m_ticksTotal; |
88 | TLSDataAccumulator<NodeDataTls> m_tls; |
89 | int m_threads; |
90 | |
91 | // No synchronization |
92 | double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } |
93 | double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } |
94 | }; |
95 | bool operator==(const NodeData& lhs, const NodeData& rhs); |
96 | |
97 | typedef Node<NodeData> InstrNode; |
98 | |
99 | CV_EXPORTS InstrNode* getTrace(); |
100 | |
101 | #endif // !defined OPENCV_ABI_CHECK |
102 | |
103 | |
104 | CV_EXPORTS bool useInstrumentation(); |
105 | CV_EXPORTS void setUseInstrumentation(bool flag); |
106 | CV_EXPORTS void resetTrace(); |
107 | |
108 | enum FLAGS |
109 | { |
110 | FLAGS_NONE = 0, |
111 | FLAGS_MAPPING = 0x01, |
112 | FLAGS_EXPAND_SAME_NAMES = 0x02, |
113 | }; |
114 | |
115 | CV_EXPORTS void setFlags(FLAGS modeFlags); |
116 | static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } |
117 | CV_EXPORTS FLAGS getFlags(); |
118 | |
119 | } // namespace instr |
120 | |
121 | //! @} |
122 | |
123 | } // namespace |
124 | |
125 | #endif // OPENCV_UTILS_TLS_HPP |
126 | |