8 #include <opencv2/opencv.hpp>
10 #include "complexmat.hpp"
14 #include "nvToolsExt.h"
21 std::ios::fmtflags flags;
22 std::streamsize precision;
25 IOSave( std::ios& userStream )
26 : stream( userStream )
27 , flags( userStream.flags() )
28 , precision( userStream.precision() )
29 , fill( userStream.fill() )
34 stream.flags( flags );
35 stream.precision( precision );
45 static constexpr int precision = 2;
47 std::string indent() { return std::string(indentLvl * 4, ' '); }
54 FTrace(DbgTracer &dt, const char *fn, const char *format, ...) : t(dt), funcName(fn)
63 if (-1 == vasprintf(&arg, format, vl))
64 throw std::runtime_error("vasprintf error");
67 std::cerr << t.indent() << funcName << "(" << arg << ") {" << std::endl;
77 std::cerr << t.indent() << "}" << std::endl;
82 void traceVal(const char *name, const T& obj, int line, bool always = false)
85 if (debug || always) {
87 CudaSafeCall(cudaStreamSynchronize(cudaStreamPerThread));
90 std::cerr << std::setprecision(precision);
91 std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
95 template <typename T> struct Printer {
97 Printer(const T &_obj) : obj(_obj) {}
100 template <typename T> Printer<T> print(const T& obj) { return Printer<T>(obj); }
101 Printer<cv::Mat> print(const MatScales& obj) { return Printer<cv::Mat>(obj); }
102 Printer<cv::Mat> print(const MatFeats& obj) { return Printer<cv::Mat>(obj); }
103 Printer<cv::Mat> print(const MatScaleFeats& obj) { return Printer<cv::Mat>(obj); }
106 template <typename T>
107 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p)
113 #if CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION < 3
114 static inline std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
116 int i, dims = msize.p[-1];
117 for (i = 0; i < dims; i++) {
126 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p);
129 static inline std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
136 std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p);
138 extern DbgTracer __dbgTracer;
140 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
142 #define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
143 #define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)
144 #define PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__, true)