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 #pragma once
9 
10 #include <QFile>
11 #include <QMap>
12 #include <QMutex>
13 #include <QObject>
14 #include <QVariant>
15 #include <QVector>
16 
17 #include <atomic>
18 #include <memory>
19 
20 class QSqlQuery;
21 class QDBusArgument;
22 
23 struct DbConnection {
24  qint64 id;
25  QString name;
26  qint64 start;
27  QString trxName;
28  qint64 transactionStart;
29 };
30 
31 QDBusArgument &operator<<(QDBusArgument &arg, const DbConnection &con);
32 QDBusArgument &operator>>(QDBusArgument &arg, DbConnection &con);
33 
34 namespace Akonadi
35 {
36 namespace Server
37 {
38 class StorageDebugger : public QObject
39 {
40  Q_OBJECT
41 
42 public:
43  static StorageDebugger *instance();
44 
45  ~StorageDebugger() override;
46 
47  void addConnection(qint64 id, const QString &name);
48  void removeConnection(qint64 id);
49  void changeConnection(qint64 id, const QString &name);
50  void addTransaction(qint64 connectionId, const QString &name, uint duration, const QString &error);
51  void removeTransaction(qint64 connectionId, bool commit, uint duration, const QString &error);
52 
53  void enableSQLDebugging(bool enable);
54  inline bool isSQLDebuggingEnabled() const
55  {
56  return mEnabled;
57  }
58 
59  void queryExecuted(qint64 connectionId, const QSqlQuery &query, int duration);
60 
61  inline void incSequence()
62  {
63  ++mSequence;
64  }
65 
66  void writeToFile(const QString &file);
67 
68  Q_SCRIPTABLE QVector<DbConnection> connections() const;
69 
70 Q_SIGNALS:
71  void connectionOpened(qint64 id, qint64 timestamp, const QString &name);
72  void connectionChanged(qint64 id, const QString &name);
73  void connectionClosed(qint64 id, qint64 timestamp);
74 
75  void transactionStarted(qint64 connectionId, const QString &name, qint64 timestamp, uint duration, const QString &error);
76  void transactionFinished(qint64 connectionId, bool commit, qint64 timestamp, uint duration, const QString &error);
77 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
78  void queryExecuted(double sequence,
79  qint64 connectionId,
80  qint64 timestamp,
81  uint duration,
82  const QString &query,
83  const QMap<QString, QVariant> &values,
84  int resultsCount,
85  const QList<QList<QVariant>> &result,
86  const QString &error);
87 #else
88  void queryExecuted(double sequence,
89  qint64 connectionId,
90  qint64 timestamp,
91  uint duration,
92  const QString &query,
93  const QVariantList &values,
94  int resultsCount,
95  const QList<QList<QVariant>> &result,
96  const QString &error);
97 
98 #endif
99 private:
100  StorageDebugger();
101 
102  static StorageDebugger *mSelf;
103  static QMutex mMutex;
104 
105  std::unique_ptr<QFile> mFile;
106 
107  std::atomic_bool mEnabled = {false};
108  std::atomic_int64_t mSequence = {0};
109  QVector<DbConnection> mConnections;
110 };
111 
112 } // namespace Server
113 } // namespace Akonadi
114 
Q_OBJECTQ_OBJECT
Q_SCRIPTABLE Q_NOREPLY void start()
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
NETWORKMANAGERQT_EXPORT QDBusPendingReply< QDBusObjectPath > addConnection(const NMVariantMapMap &settings)
Definition: item.h:32
Q_SIGNALSQ_SIGNALS
QString name(StandardShortcut id)
QDataStream & operator>>(QDataStream &in, KDateTime &dateTime)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:01:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.