| 1 |
// Copyright © 2016 Canonical Ltd. |
| 2 |
// Author: Loïc Molinari <[email protected]> |
| 3 |
// |
| 4 |
// This file is part of Lomiri UI Toolkit. |
| 5 |
// |
| 6 |
// Lomiri UI Toolkit is free software: you can redistribute it and/or modify it |
| 7 |
// under the terms of the GNU Lesser General Public License as published by the |
| 8 |
// Free Software Foundation; version 3. |
| 9 |
// |
| 10 |
// Lomiri UI Toolkit is distributed in the hope that it will be useful, but |
| 11 |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 13 |
// for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with Lomiri UI Toolkit. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#ifndef EVENTS_H |
| 19 |
#define EVENTS_H |
| 20 |
|
| 21 |
#include <QtGlobal> |
| 22 |
|
| 23 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 24 |
#include <LomiriMetrics-Qt6/lomirimetricsglobal.h> |
| 25 |
#else |
| 26 |
#include <LomiriMetrics/lomirimetricsglobal.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
// FIXME(loicm) Using alignas() in that public header requires users to have a |
| 30 |
// C++11 compiler. That also makes the use of Q_NULLPTR and Q_OVERRIDE in |
| 31 |
// other public headers useless. |
| 32 |
|
| 33 |
struct LOMIRI_METRICS_EXPORT UMProcessEvent |
| 34 |
{ |
| 35 |
// Virtual size of the process in kilobytes. |
| 36 |
quint32 vszMemory; |
| 37 |
|
| 38 |
// Resident set size (RSS) of the process in kilobytes. |
| 39 |
quint32 rssMemory; |
| 40 |
|
| 41 |
// CPU usage of the process as a percentage. 100%, for instance, if all the |
| 42 |
// cores are at 100% usage, 50% if half of the cores are at 100%. |
| 43 |
quint16 cpuUsage; |
| 44 |
|
| 45 |
// Number of threads at buffer swap. |
| 46 |
quint16 threadCount; |
| 47 |
|
| 48 |
// The whole struct must take 112 bytes to allow future additions and best |
| 49 |
// memory alignment, don't forget to update when adding new metrics. |
| 50 |
quint8 __reserved[/*12 bytes taken,*/ 100 /*bytes free*/]; |
| 51 |
}; |
| 52 |
Q_STATIC_ASSERT(sizeof(UMProcessEvent) == 112); |
| 53 |
|
| 54 |
struct LOMIRI_METRICS_EXPORT UMWindowEvent |
| 55 |
{ |
| 56 |
enum State { Hidden = 0, Shown = 1, Resized = 2, StateCount = 3 }; |
| 57 |
|
| 58 |
// Window id. |
| 59 |
quint32 id; |
| 60 |
|
| 61 |
// Width of the window. |
| 62 |
quint16 width; |
| 63 |
|
| 64 |
// Height of the window. |
| 65 |
quint16 height; |
| 66 |
|
| 67 |
// State of the window. |
| 68 |
State state : 8; |
| 69 |
|
| 70 |
// The whole struct must take 112 bytes to allow future additions and best |
| 71 |
// memory alignment, don't forget to update when adding new metrics. |
| 72 |
quint8 __reserved[/*9 bytes taken,*/ 103 /*bytes free*/]; |
| 73 |
}; |
| 74 |
Q_STATIC_ASSERT(sizeof(UMWindowEvent) == 112); |
| 75 |
|
| 76 |
struct LOMIRI_METRICS_EXPORT UMFrameEvent |
| 77 |
{ |
| 78 |
// The id of the window on which the frame has been rendered. |
| 79 |
quint32 window; |
| 80 |
|
| 81 |
// The frame number. Corresponds to the number of frames rendered after |
| 82 |
// scene graph initialisation. |
| 83 |
quint32 number; |
| 84 |
|
| 85 |
// Time in nanoseconds since the last frame swap. |
| 86 |
quint64 deltaTime; |
| 87 |
|
| 88 |
// Time in nanoseconds taken by the QtQuick scene graph synchronization |
| 89 |
// pass. |
| 90 |
quint64 syncTime; |
| 91 |
|
| 92 |
// Time in nanoseconds taken by the QtQuick scene graph render pass. |
| 93 |
quint64 renderTime; |
| 94 |
|
| 95 |
// Time in nanoseconds taken by the GPU to execute the graphics commands |
| 96 |
// pushed during the QtQuick scene graph render pass. |
| 97 |
quint64 gpuTime; |
| 98 |
|
| 99 |
// Time in nanoseconds taken by the graphics subsystem's buffer swap call. |
| 100 |
quint64 swapTime; |
| 101 |
|
| 102 |
// The whole struct must take 112 bytes to allow future additions and best |
| 103 |
// memory alignment, don't forget to update when adding new metrics. |
| 104 |
quint8 __reserved[/*48 bytes taken,*/ 64 /*bytes free*/]; |
| 105 |
}; |
| 106 |
Q_STATIC_ASSERT(sizeof(UMFrameEvent) == 112); |
| 107 |
|
| 108 |
struct LOMIRI_METRICS_EXPORT UMGenericEvent |
| 109 |
{ |
| 110 |
static const quint32 maxStringSize = 64; |
| 111 |
|
| 112 |
// Id retrieved from UMApplicationMonitor::registerGenericEvent(). |
| 113 |
quint32 id; |
| 114 |
|
| 115 |
// Size of the string (including the null-terminating char). |
| 116 |
quint32 stringSize; |
| 117 |
|
| 118 |
// Null-terminated string describing the generic event. |
| 119 |
char string[maxStringSize]; |
| 120 |
|
| 121 |
// The whole struct must take 112 bytes to allow future additions and best |
| 122 |
// memory alignment, don't forget to update when adding new metrics. |
| 123 |
quint8 __reserved[/*72 bytes taken,*/ 40 /*bytes free*/]; |
| 124 |
}; |
| 125 |
Q_STATIC_ASSERT(sizeof(UMGenericEvent) == 112); |
| 126 |
|
| 127 |
struct LOMIRI_METRICS_EXPORT UMEvent |
| 128 |
{ |
| 129 |
enum Type { Process = 0, Window = 1, Frame = 2, Generic = 3, TypeCount = 4 }; |
| 130 |
|
| 131 |
// Event type. |
| 132 |
Type type; |
| 133 |
|
| 134 |
// Time stamp in nanoseconds. |
| 135 |
alignas(8) quint64 timeStamp; |
| 136 |
|
| 137 |
union { |
| 138 |
UMProcessEvent process; |
| 139 |
UMWindowEvent window; |
| 140 |
UMFrameEvent frame; |
| 141 |
UMGenericEvent generic; |
| 142 |
}; |
| 143 |
}; |
| 144 |
Q_STATIC_ASSERT(sizeof(UMEvent) == 128); |
| 145 |
|
| 146 |
class EventUtilsPrivate; |
| 147 |
|
| 148 |
// Utilities to manipulate events. |
| 149 |
class LOMIRI_METRICS_EXPORT UMEventUtils |
| 150 |
{ |
| 151 |
public: |
| 152 |
UMEventUtils(); |
| 153 |
~UMEventUtils(); |
| 154 |
|
| 155 |
// Fill the given event with updated process metrics. |
| 156 |
void updateProcessEvent(UMEvent* event); |
| 157 |
|
| 158 |
// Get a time stamp in nanoseconds. The timer is started at the first call, |
| 159 |
// returning 0. |
| 160 |
static quint64 timeStamp(); |
| 161 |
|
| 162 |
private: |
| 163 |
EventUtilsPrivate* const d_ptr; |
| 164 |
Q_DECLARE_PRIVATE(EventUtils) |
| 165 |
}; |
| 166 |
|
| 167 |
#endif // EVENTS_H |