diff --git a/common/include/common/scopybenchmark.h b/common/include/common/scopybenchmark.h new file mode 100644 index 0000000000..308e47e5f9 --- /dev/null +++ b/common/include/common/scopybenchmark.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Analog Devices Inc. + * + * This file is part of Scopy + * (see https://www.github.com/analogdevicesinc/scopy). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef SCOPYBENCHMARK_H +#define SCOPYBENCHMARK_H + +#include +#include +#include "scopy-common_export.h" + +#define CONSOLE_LOG(logger, msg) logger.log(msg, __PRETTY_FUNCTION__, __FILE__, __LINE__) +#define FILE_LOG(logger, msg, path) logger.log(path, msg, __PRETTY_FUNCTION__, __FILE__, __LINE__) + +namespace scopy { +class SCOPY_COMMON_EXPORT ScopyBenchmark +{ +public: + ScopyBenchmark(); + ~ScopyBenchmark(); + + void startTimer(); + void restartTimer(); + + void log(const QString &msg, const char *function, const char *file, int line); + void log(const QString &filePath, const QString &msg, const char *function, const char *file, int line); + +private: + QElapsedTimer m_timer; +}; + +} // namespace scopy + +#endif // SCOPYBENCHMARK_H diff --git a/common/src/scopybenchmark.cpp b/common/src/scopybenchmark.cpp new file mode 100644 index 0000000000..dc43126bff --- /dev/null +++ b/common/src/scopybenchmark.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 Analog Devices Inc. + * + * This file is part of Scopy + * (see https://www.github.com/analogdevicesinc/scopy). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "scopybenchmark.h" +#include +#include +#include + +Q_LOGGING_CATEGORY(CAT_BENCHMARK, "Benchmark") +using namespace scopy; + +ScopyBenchmark::ScopyBenchmark() {} + +ScopyBenchmark::~ScopyBenchmark() {} + +void ScopyBenchmark::startTimer() { m_timer.start(); } + +void ScopyBenchmark::restartTimer() { m_timer.restart(); } + +void ScopyBenchmark::log(const QString &msg, const char *function, const char *file, int line) +{ + QMessageLogger(file, line, function).info(CAT_BENCHMARK) << function << msg << m_timer.elapsed() << "ms"; +} + +void ScopyBenchmark::log(const QString &filePath, const QString &msg, const char *function, const char *file, int line) +{ + QFile f(filePath); + if(f.open(QIODevice::WriteOnly | QIODevice::Append)) { + QTextStream stream(&f); + stream << QDateTime::currentDateTime().toString("dd:MM:yyyy hh:mm:ss.zzz") << "\t" << file << ":" + << line << "\t" << function << "\t" << msg << "\t" << m_timer.elapsed() << "\t" + << "ms" + << "\n"; + } +}