Krita Source Code Documentation
Loading...
Searching...
No Matches
KisScopedPerformanceLogger.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-3.0-or-later
3 */
4#ifndef __KISSCOPEDPERFORMANCELOGGER_H_
5#define __KISSCOPEDPERFORMANCELOGGER_H_
6
7#include <QElapsedTimer>
8#include <QString>
9
10#include "kis_debug.h"
11#include "kritaglobal_export.h"
12
13class KRITAGLOBAL_EXPORT KisScopedPerformanceLogger
14{
15 Q_DISABLE_COPY_MOVE(KisScopedPerformanceLogger)
16public:
17 explicit KisScopedPerformanceLogger(const QString &title)
18 : m_title(title)
19 {
21 m_timer.start();
22 }
23 }
24
26 {
27 if (m_timer.isValid()) {
28 // We'll format this as fractional milliseconds so that both short
29 // and long durations are reasonably comprehensible without having
30 // to decipher excessively long numbers.
31 qint64 nsecs = m_timer.nsecsElapsed();
32 dbgPerformance.noquote() << QStringLiteral("%1: %2.%3 ms")
33 .arg(m_title)
34 .arg(nsecs / 1000000LL)
35 .arg(nsecs % 1000000LL, 6, 10, QChar('0'));
36 }
37 }
38
39private:
40 QString m_title;
41 QElapsedTimer m_timer;
42};
43
44#endif
KisScopedPerformanceLogger(const QString &title)
#define dbgPerformance
Definition kis_debug.h:67
#define dbgPerformanceIsEnabled()
Definition kis_debug.h:44