Akonadi

storagedebugger.h
1 /*
2  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #ifndef STORAGEDEBUGGER_H
9 #define STORAGEDEBUGGER_H
10 
11 #include <QObject>
12 #include <QMutex>
13 #include <QMap>
14 #include <QVariant>
15 #include <QFile>
16 #include <QVector>
17 
18 #include <atomic>
19 #include <memory>
20 
21 class QSqlQuery;
22 class QDBusArgument;
23 
24 struct DbConnection {
25  qint64 id;
26  QString name;
27  qint64 start;
28  QString trxName;
29  qint64 transactionStart;
30 };
31 
32 QDBusArgument &operator<<(QDBusArgument &arg, const DbConnection &con);
33 QDBusArgument &operator>>(QDBusArgument &arg, DbConnection &con);
34 
35 namespace Akonadi
36 {
37 namespace Server
38 {
39 
40 class StorageDebugger : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45  static StorageDebugger *instance();
46 
47  ~StorageDebugger() override;
48 
49  void addConnection(qint64 id, const QString &name);
50  void removeConnection(qint64 id);
51  void changeConnection(qint64 id, const QString &name);
52  void addTransaction(qint64 connectionId, const QString &name, uint duration, const QString &error);
53  void removeTransaction(qint64 connectionId, bool commit, uint duration, const QString &error);
54 
55  void enableSQLDebugging(bool enable);
56  inline bool isSQLDebuggingEnabled() const
57  {
58  return mEnabled;
59  }
60 
61  void queryExecuted(qint64 connectionId, const QSqlQuery &query, int duration);
62 
63  inline void incSequence()
64  {
65  ++mSequence;
66  }
67 
68  void writeToFile(const QString &file);
69 
70  Q_SCRIPTABLE QVector<DbConnection> connections() const;
71 
72 Q_SIGNALS:
73  void connectionOpened(qint64 id, qint64 timestamp, const QString &name);
74  void connectionChanged(qint64 id, const QString &name);
75  void connectionClosed(qint64 id, qint64 timestamp);
76 
77  void transactionStarted(qint64 connectionId, const QString &name, qint64 timestamp,
78  uint duration, const QString &error);
79  void transactionFinished(qint64 connectionId, bool commit, qint64 timestamp, uint duration,
80  const QString &error);
81 
82  void queryExecuted(double sequence, qint64 connectionId, qint64 timestamp,
83  uint duration, const QString &query, const QMap<QString, QVariant> &values,
84  int resultsCount, const QList<QList<QVariant> > &result,
85  const QString &error);
86 
87 private:
88  StorageDebugger();
89 
90  static StorageDebugger *mSelf;
91  static QMutex mMutex;
92 
93  std::unique_ptr<QFile> mFile;
94 
95  std::atomic_bool mEnabled = {false};
96  std::atomic_int64_t mSequence = {0};
97  QVector<DbConnection> mConnections;
98 
99 };
100 
101 } // namespace Server
102 } // namespace Akonadi
103 
104 #endif // STORAGEDEBUGGER_H
QString name(const QVariant &location)
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
NETWORKMANAGERQT_EXPORT QDBusPendingReply< QDBusObjectPath > addConnection(const NMVariantMapMap &settings)
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.