]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - src/debug.h
Remove debug printf
[hercules2020/kcf.git] / src / debug.h
index 1d6a5ac86e9312e131d43ad385b54426ae64966f..cce8327201b44732d131ff4f080a01bed7813180 100644 (file)
@@ -6,6 +6,14 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <opencv2/opencv.hpp>
+#include "dynmem.hpp"
+#include "complexmat.hpp"
+
+#ifdef CUFFT
+#include <cufft.h>
+#include "nvToolsExt.h"
+#endif
+
 
 class IOSave
 {
@@ -34,6 +42,7 @@ class DbgTracer {
 
   public:
     bool debug = false;
+    static constexpr int precision = 2;
 
     std::string indent() { return std::string(indentLvl * 4, ' '); }
 
@@ -44,6 +53,9 @@ class DbgTracer {
       public:
         FTrace(DbgTracer &dt, const char *fn, const char *format, ...) : t(dt), funcName(fn)
         {
+#ifdef CUFFT
+            nvtxRangePushA(fn);
+#endif
             if (!t.debug) return;
             char *arg;
             va_list vl;
@@ -57,6 +69,9 @@ class DbgTracer {
         }
         ~FTrace()
         {
+#ifdef CUFFT
+            nvtxRangePop();
+#endif
             if (!t.debug) return;
             t.indentLvl--;
             std::cerr << t.indent() << "}" << std::endl;
@@ -64,11 +79,14 @@ class DbgTracer {
     };
 
     template <typename T>
-    void traceVal(const char *name, const T& obj, int line)
+    void traceVal(const char *name, const T& obj, int line, bool always = false)
     {
         (void)line;
-        if (debug)
+        if (debug || always) {
+            IOSave s(std::cerr);
+            std::cerr << std::setprecision(precision);
             std::cerr << indent() << name /*<< " @" << line */ << " " << print(obj) << std::endl;
+        }
     }
 
     template <typename T> struct Printer {
@@ -88,8 +106,9 @@ std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<T> &p)
     os << p.obj;
     return os;
 }
-#if CV_VERSION_MAJOR < 3 || CV_VERSION_MINOR < 3
-std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
+
+#if CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION < 3
+static inline std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
 {
     int i, dims = msize.p[-1];
     for (i = 0; i < dims; i++) {
@@ -100,42 +119,25 @@ std::ostream &operator<<(std::ostream &out, const cv::MatSize &msize)
     return out;
 }
 #endif
-std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p)
-{
-    IOSave s(os);
-    os << std::setprecision(3);
-    os << p.obj.size << " " << p.obj.channels() << "ch ";// << static_cast<const void *>(p.obj.data);
-    os << " = [ ";
-    constexpr size_t num = 100;
-    for (size_t i = 0; i < std::min(num, p.obj.total()); ++i)
-        os << p.obj.ptr<float>()[i] << ", ";
-    os << (num < p.obj.total() ? "... ]" : "]");
-    return os;
-}
+
+std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<cv::Mat> &p);
+
 #if defined(CUFFT)
-std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
+static inline std::ostream &operator<<(std::ostream &os, const cufftComplex &p)
 {
     (void)p; // TODO
     return os;
 }
 #endif
-template <>
-std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p)
-{
-    IOSave s(os);
-    os << std::setprecision(3);
-    os << "<cplx> " << p.obj.size() << " " << p.obj.channels() << "ch "; // << p.obj.get_p_data();
-    os << " = [ ";
-    constexpr int num = 100;
-    for (int i = 0; i < std::min(num, p.obj.size().area()); ++i)
-        os << p.obj.get_p_data()[i] << ", ";
-    os << (num < p.obj.size().area() ? "... ]" : "]");
-    return os;
-}
+
+std::ostream &operator<<(std::ostream &os, const DbgTracer::Printer<ComplexMat> &p);
+
+extern DbgTracer __dbgTracer;
 
 #define TRACE(...) const DbgTracer::FTrace __tracer(__dbgTracer, __PRETTY_FUNCTION__, ##__VA_ARGS__)
 
 #define DEBUG_PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__)
 #define DEBUG_PRINTM(obj) DEBUG_PRINT(obj)
+#define PRINT(obj) __dbgTracer.traceVal(#obj, (obj), __LINE__, true)
 
 #endif // DEBUG_H