#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
{
public:
bool debug = false;
+ static constexpr int precision = 2;
std::string indent() { return std::string(indentLvl * 4, ' '); }
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;
}
~FTrace()
{
+#ifdef CUFFT
+ nvtxRangePop();
+#endif
if (!t.debug) return;
t.indentLvl--;
std::cerr << t.indent() << "}" << std::endl;
};
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 {
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++) {
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