| 1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QT3DCORE_QSYSTEMINFORMATIONSERVICE_P_P_H |
| 5 | #define QT3DCORE_QSYSTEMINFORMATIONSERVICE_P_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/QThreadStorage> |
| 19 | #include <QtCore/QElapsedTimer> |
| 20 | #include <QtCore/QFile> |
| 21 | #include <QtCore/QMutex> |
| 22 | |
| 23 | #include <Qt3DCore/qt3dcore_global.h> |
| 24 | #include <Qt3DCore/private/qt3dcore_global_p.h> |
| 25 | #include <Qt3DCore/private/qabstractserviceprovider_p.h> |
| 26 | #include <Qt3DCore/private/qservicelocator_p.h> |
| 27 | #include <Qt3DCore/private/qsysteminformationservice_p.h> |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | namespace Qt3DCore { |
| 32 | |
| 33 | namespace Debug { |
| 34 | class AspectCommandDebugger; |
| 35 | } // Debug |
| 36 | |
| 37 | union Q_3DCORE_PRIVATE_EXPORT JobId |
| 38 | { |
| 39 | JobId() : id(0L) { } |
| 40 | JobId(quint32 t, quint32 i) { typeAndInstance[0] = t; typeAndInstance[1] = i; } |
| 41 | |
| 42 | quint32 typeAndInstance[2]; |
| 43 | quint64 id; |
| 44 | }; |
| 45 | |
| 46 | class Q_3DCORE_PRIVATE_EXPORT QSystemInformationServicePrivate : public QAbstractServiceProviderPrivate |
| 47 | { |
| 48 | public: |
| 49 | struct JobRunStats |
| 50 | { |
| 51 | JobRunStats() { jobId.id = 0; startTime = 0L; endTime = 0L; } |
| 52 | |
| 53 | qint64 startTime; |
| 54 | qint64 endTime; |
| 55 | JobId jobId; // QAspectJob subclasses should properly populate the jobId |
| 56 | quint64 threadId; |
| 57 | }; |
| 58 | |
| 59 | QSystemInformationServicePrivate(QAspectEngine *aspectEngine, const QString &description); |
| 60 | ~QSystemInformationServicePrivate(); |
| 61 | |
| 62 | static QSystemInformationServicePrivate *get(QSystemInformationService *q); |
| 63 | |
| 64 | // Aspects + Job threads |
| 65 | void addJobLogStatsEntry(JobRunStats &stats); |
| 66 | |
| 67 | // Submission thread |
| 68 | void addSubmissionLogStatsEntry(JobRunStats &stats); |
| 69 | |
| 70 | void writeFrameJobLogStats(); |
| 71 | void updateTracing(); |
| 72 | |
| 73 | QAspectEngine *m_aspectEngine; |
| 74 | bool m_traceEnabled; |
| 75 | bool m_graphicsTraceEnabled; |
| 76 | |
| 77 | QElapsedTimer m_jobsStatTimer; |
| 78 | QThreadStorage<QList<JobRunStats> *> m_jobStatsCached; |
| 79 | |
| 80 | QList<QList<JobRunStats> *> m_localStorages; |
| 81 | QList<JobRunStats> *m_submissionStorage; |
| 82 | |
| 83 | QMutex m_localStoragesMutex; |
| 84 | |
| 85 | QScopedPointer<QFile> m_traceFile; |
| 86 | quint32 m_frameId; |
| 87 | |
| 88 | Debug::AspectCommandDebugger *m_commandDebugger; |
| 89 | |
| 90 | Q_DECLARE_PUBLIC(QSystemInformationService) |
| 91 | }; |
| 92 | |
| 93 | class Q_3DCORE_PRIVATE_EXPORT QTaskLogger { |
| 94 | public: |
| 95 | enum Type { |
| 96 | AspectJob, |
| 97 | Submission |
| 98 | }; |
| 99 | |
| 100 | QTaskLogger(QSystemInformationService *service, const JobId &jobId, Type type); |
| 101 | QTaskLogger(QSystemInformationService *service, const quint32 jobType, const quint32 instance, Type type = Submission); |
| 102 | |
| 103 | ~QTaskLogger(); |
| 104 | |
| 105 | void end(qint64 t = 0L); |
| 106 | qint64 restart(); |
| 107 | |
| 108 | private: |
| 109 | QSystemInformationService *m_service; |
| 110 | QSystemInformationServicePrivate::JobRunStats m_stats; |
| 111 | Type m_type; |
| 112 | }; |
| 113 | |
| 114 | } |
| 115 | |
| 116 | QT_END_NAMESPACE |
| 117 | |
| 118 | #endif // QT3DCORE_QSYSTEMINFORMATIONSERVICE_P_P_H |
| 119 | |
| 120 |
