File indexing completed on 2025-01-05 04:47:01
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 * 0006 */ 0007 0008 #pragma once 0009 0010 #include <QFile> 0011 #include <QList> 0012 #include <QMap> 0013 #include <QMutex> 0014 #include <QObject> 0015 #include <QVariant> 0016 0017 #include <atomic> 0018 #include <memory> 0019 0020 class QSqlQuery; 0021 class QDBusArgument; 0022 0023 struct DbConnection { 0024 qint64 id; 0025 QString name; 0026 qint64 start; 0027 QString trxName; 0028 qint64 transactionStart; 0029 }; 0030 0031 QDBusArgument &operator<<(QDBusArgument &arg, const DbConnection &con); 0032 QDBusArgument &operator>>(QDBusArgument &arg, DbConnection &con); 0033 0034 namespace Akonadi 0035 { 0036 namespace Server 0037 { 0038 class StorageDebugger : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 static StorageDebugger *instance(); 0044 0045 ~StorageDebugger() override; 0046 0047 void addConnection(qint64 id, const QString &name); 0048 void removeConnection(qint64 id); 0049 void changeConnection(qint64 id, const QString &name); 0050 void addTransaction(qint64 connectionId, const QString &name, uint duration, const QString &error); 0051 void removeTransaction(qint64 connectionId, bool commit, uint duration, const QString &error); 0052 0053 void enableSQLDebugging(bool enable); 0054 inline bool isSQLDebuggingEnabled() const 0055 { 0056 return mEnabled; 0057 } 0058 0059 void queryExecuted(qint64 connectionId, const QSqlQuery &query, int duration); 0060 0061 inline void incSequence() 0062 { 0063 ++mSequence; 0064 } 0065 0066 void writeToFile(const QString &file); 0067 0068 Q_SCRIPTABLE QList<DbConnection> connections() const; 0069 0070 Q_SIGNALS: 0071 void connectionOpened(qint64 id, qint64 timestamp, const QString &name); 0072 void connectionChanged(qint64 id, const QString &name); 0073 void connectionClosed(qint64 id, qint64 timestamp); 0074 0075 void transactionStarted(qint64 connectionId, const QString &name, qint64 timestamp, uint duration, const QString &error); 0076 void transactionFinished(qint64 connectionId, bool commit, qint64 timestamp, uint duration, const QString &error); 0077 void queryExecuted(double sequence, 0078 qint64 connectionId, 0079 qint64 timestamp, 0080 uint duration, 0081 const QString &query, 0082 const QVariantList &values, 0083 int resultsCount, 0084 const QList<QList<QVariant>> &result, 0085 const QString &error); 0086 0087 private: 0088 StorageDebugger(); 0089 0090 static StorageDebugger *mSelf; 0091 static QMutex mMutex; 0092 0093 std::unique_ptr<QFile> mFile; 0094 0095 std::atomic_bool mEnabled = {false}; 0096 std::atomic_int64_t mSequence = {0}; 0097 QList<DbConnection> mConnections; 0098 }; 0099 0100 } // namespace Server 0101 } // namespace Akonadi