Debian Codegraph @

src/imports/PerformanceMetrics/plugin/upmcpuusage.h

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Florian Boucault <[email protected]>
17 */
18
19 #ifndef UPMCPUUSAGE_H
20 #define UPMCPUUSAGE_H
21
22 #include <sys/times.h>
23
24 #include <QtCore/QObject>
25 #include <QtCore/QTimer>
26 #include <QtQuick/QQuickItem>
27 #include <QtQuick/QQuickWindow>
28
29 #include "upmgraphmodel.h"
30
31 class UPMCpuUsage : public QQuickItem
32 {
33 Q_OBJECT
34
35 Q_PROPERTY(UPMGraphModel* graphModel READ graphModel NOTIFY graphModelChanged)
36 Q_PROPERTY(int period READ period WRITE setPeriod NOTIFY periodChanged)
37 Q_PROPERTY(int samplingInterval READ samplingInterval WRITE setSamplingInterval NOTIFY samplingIntervalChanged)
38
39 public:
40 explicit UPMCpuUsage(QQuickItem* parent = 0);
41
42 // getters
43 UPMGraphModel* graphModel() const;
44 int period() const;
45 int samplingInterval() const;
46
47 // setters
48 void setPeriod(int period);
49 void setSamplingInterval(int samplingInterval);
50
51 Q_SIGNALS:
52 void graphModelChanged();
53 void periodChanged();
54 void samplingIntervalChanged();
55
56 protected:
57 void itemChange(ItemChange change, const ItemChangeData & value) override;
58
59 private Q_SLOTS:
60 void connectToWindow(QQuickWindow* window);
61 void onFrameRendered();
62 void appendCpuTime();
63
64 private:
65 QQuickWindow* m_window;
66 UPMGraphModel* m_graphModel;
67 int m_period;
68 int m_samplingInterval;
69 QTimer m_timer;
70 float m_timingFactor;
71 struct tms m_previousTimes;
72 clock_t m_previousClock;
73 int m_timeAtLastFrame;
74 };
75
76 #endif // UPMCPUUSAGE_H