File indexing completed on 2024-12-08 12:44:37

0001 /*
0002     SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KASYNC_DEBUG_H
0008 #define KASYNC_DEBUG_H
0009 
0010 //krazy:excludeall=dpointer
0011 
0012 #include "kasync_export.h"
0013 
0014 #include <QLoggingCategory>
0015 #include <QStringBuilder>
0016 
0017 #ifndef QT_NO_DEBUG
0018 #include <typeinfo>
0019 #endif
0020 
0021 namespace KAsync
0022 {
0023 
0024 Q_DECLARE_LOGGING_CATEGORY(Debug)
0025 Q_DECLARE_LOGGING_CATEGORY(Trace)
0026 
0027 KASYNC_EXPORT QString demangleName(const char *name);
0028 
0029 namespace Private
0030 {
0031 struct Execution;
0032 }
0033 
0034 class KASYNC_EXPORT Tracer
0035 {
0036 public:
0037     explicit Tracer(Private::Execution *execution);
0038     ~Tracer();
0039 
0040 private:
0041     enum MsgType {
0042         Start,
0043         End
0044     };
0045     void msg(MsgType);
0046 
0047     int mId;
0048     Private::Execution *mExecution;
0049 
0050     static int lastId;
0051 };
0052 
0053 }
0054 
0055 #ifndef QT_NO_DEBUG
0056     template<typename T>
0057     QString storeExecutorNameExpanded() {
0058         return KAsync::demangleName(typeid(T).name());
0059     }
0060 
0061     template<typename T, typename ... Tail>
0062     auto storeExecutorNameExpanded() -> std::enable_if_t<sizeof ... (Tail) != 0, QString>
0063     {
0064         return storeExecutorNameExpanded<T>() % QStringLiteral(", ") % storeExecutorNameExpanded<Tail ...>();
0065     }
0066 
0067     #define STORE_EXECUTOR_NAME(name, ...) \
0068         ExecutorBase::mExecutorName = QStringLiteral(name "<") % storeExecutorNameExpanded<__VA_ARGS__>() % QStringLiteral(">")
0069 #else
0070     #define STORE_EXECUTOR_NAME(...)
0071 #endif
0072 
0073 #endif // KASYNC_DEBUG_H