Debian Codegraph @

src/imports/PerformanceMetrics/PerformanceOverlay.qml

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
17 import QtQuick 2.4
18 import Lomiri.PerformanceMetrics 1.0 as PerformanceMetrics
19
20 /*!
21 \qmltype PerformanceOverlay
22 \inqmlmodule Lomiri.PerformanceMetrics 0.1
23 \ingroup lomiri-performance-metrics
24 \brief Overlay displaying performance related metrics (rendering time, CPU usage, etc.)
25
26 PerformanceOverlay displays various performance related indicators to help
27 developers detect issues in their application.
28
29 Examples:
30 \qml
31 PerformanceOverlay {
32 active: true
33 }
34 \endqml
35
36 \deprecated Use the QML Lomiri.Metrics module or the C++ libLomiriMetrics instead.
37 */
38 Item {
39 id: overlay
40
41 anchors.fill: parent
42
43 Component {
44 id: overlayContent
45
46 Item {
47 MouseArea {
48 anchors.fill: content
49 drag.target: content
50 onClicked: overlay.active = false
51 }
52
53 Item {
54 id: content
55 x: parent.width - width - units.gu(2)
56 y: units.gu(10)
57 width: units.gu(38)
58 height: childrenRect.height
59
60 PerformanceMetrics.RenderingTimes {
61 id: renderingTimes
62 period: 2000
63 samples: renderingTimeGraph.width
64 timerType: PerformanceMetrics.RenderingTimes.Trivial
65 }
66
67 PerformanceMetrics.CpuUsage {
68 id: cpuUsage
69 period: 5000
70 samplingInterval: 200
71 }
72
73 Column {
74 anchors.left: parent.left
75 anchors.right: parent.right
76 spacing: units.gu(1)
77
78 BarGraph {
79 id: renderingTimeGraph
80 anchors.left: parent.left
81 anchors.right: parent.right
82 model: renderingTimes.graphModel
83 maximumValue: 20
84 threshold: 16
85 labels: [{"color": "darkorange", "value": 10, "label": "10 ms"},
86 {"color": "red", "value": 16, "label": "16 ms"}]
87 labelFormat: "%1 ms"
88 }
89
90 BarGraph {
91 id: cpuUsageGraph
92 anchors.left: parent.left
93 anchors.right: parent.right
94 model: cpuUsage.graphModel
95 maximumValue: 100
96 threshold: 75
97 labels: [{"color": "green", "value": 25, "label": "25%"},
98 {"color": "darkorange", "value": 50, "label": "50%"},
99 {"color": "red", "value": 75, "label": "75%"}]
100 labelFormat: "%1 %"
101 }
102 }
103 }
104
105 }
106 }
107
108 /*!
109 Whether or not the PerformanceOverlay is displayed.
110 */
111 property bool active: true
112
113 MouseArea {
114 property var timeLastPress
115 property int delayBetweenPresses: 500
116 property int pressCount: 0
117 property int pressCountToActivate: 4
118
119 anchors.fill: parent
120 enabled: performanceOverlayEnabled
121
122 onPressed: {
123 mouse.accepted = false;
124 var timePress = new Date().getTime();
125
126 if (timeLastPress && timePress - timeLastPress > delayBetweenPresses) {
127 pressCount = 0;
128 }
129
130 pressCount += 1;
131
132 if (pressCount >= pressCountToActivate) {
133 overlay.active = true;
134 pressCount = 0;
135 }
136
137 timeLastPress = timePress;
138 }
139 }
140
141 Loader {
142 id: loader
143 anchors.fill: parent
144 active: overlay.active
145 asynchronous: true
146 sourceComponent: overlayContent
147 }
148 }