1 /*
2  *  Copyright (c) 2015 Dmitry Kazakov <dimula73@gmail.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __KIS_MEMORY_STATISTICS_SERVER_H
20 #define __KIS_MEMORY_STATISTICS_SERVER_H
21 
22 #include <QtGlobal>
23 #include <QObject>
24 #include <QScopedPointer>
25 
26 #include "kritaimage_export.h"
27 #include "kis_types.h"
28 
29 
30 class KRITAIMAGE_EXPORT KisMemoryStatisticsServer : public QObject
31 {
32     Q_OBJECT
33 public:
34     struct Statistics
35     {
StatisticsStatistics36         Statistics()
37             : imageSize(0),
38               layersSize(0),
39               projectionsSize(0),
40               lodSize(0),
41 
42               totalMemorySize(0),
43               realMemorySize(0),
44               historicalMemorySize(0),
45               poolSize(0),
46 
47               swapSize(0),
48 
49               totalMemoryLimit(0),
50               tilesHardLimit(0),
51               tilesSoftLimit(0),
52               tilesPoolLimit(0)
53         {
54         }
55 
56         qint64 imageSize;
57         qint64 layersSize;
58         qint64 projectionsSize;
59         qint64 lodSize;
60 
61         qint64 totalMemorySize;
62         qint64 realMemorySize;
63         qint64 historicalMemorySize;
64         qint64 poolSize;
65 
66         qint64 swapSize;
67 
68         qint64 totalMemoryLimit;
69         qint64 tilesHardLimit;
70         qint64 tilesSoftLimit;
71         qint64 tilesPoolLimit;
72     };
73 
74 
75 
76 public:
77     KisMemoryStatisticsServer();
78     ~KisMemoryStatisticsServer() override;
79     static KisMemoryStatisticsServer* instance();
80 
81     Statistics fetchMemoryStatistics(KisImageSP image) const;
82 
83 public Q_SLOTS:
84     void notifyImageChanged();
85     void tryForceUpdateMemoryStatisticsWhileIdle();
86 
87 Q_SIGNALS:
88     void sigUpdateMemoryStatistics();
89 
90 
91 private:
92     struct Private;
93     const QScopedPointer<Private> m_d;
94 };
95 
96 #endif /* __KIS_MEMORY_STATISTICS_SERVER_H */
97