1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef QQMLJSCOMPILERSTATS_P_H
5#define QQMLJSCOMPILERSTATS_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 purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include <qtqmlcompilerexports.h>
18
19#include <QHash>
20#include <QJsonDocument>
21
22#include <private/qqmljsdiagnosticmessage_p.h>
23#include <private/qqmljssourcelocation_p.h>
24
25#include <memory>
26
27QT_BEGIN_NAMESPACE
28
29namespace QQmlJS {
30
31struct Q_QMLCOMPILER_EXPORT AotStatsEntry
32{
33 std::chrono::microseconds codegenDuration;
34 QString functionName;
35 QString errorMessage;
36 int line = 0;
37 int column = 0;
38 bool codegenSuccessful = true;
39
40 bool operator<(const AotStatsEntry &) const;
41};
42
43class Q_QMLCOMPILER_EXPORT AotStats
44{
45 friend class QQmlJSAotCompilerStats;
46
47public:
48 const QHash<QString, QHash<QString, QList<AotStatsEntry>>> &entries() const
49 {
50 return m_entries;
51 }
52
53 void registerFile(const QString &moduleId, const QString &filepath);
54 void addEntry(const QString &moduleId, const QString &filepath, const AotStatsEntry &entry);
55 void insert(const AotStats &other);
56
57 static std::optional<QStringList> readAllLines(const QString &path);
58 bool saveToDisk(const QString &filepath) const;
59
60 static std::optional<AotStats> parseAotstatsFile(const QString &aotstatsPath);
61 static std::optional<AotStats> aggregateAotstatsList(const QString &aotstatsListPath);
62
63 static AotStats fromJsonDocument(const QJsonDocument &);
64 QJsonDocument toJsonDocument() const;
65
66private:
67 // module Id -> filename -> stats m_entries
68 QHash<QString, QHash<QString, QList<AotStatsEntry>>> m_entries;
69};
70
71class Q_QMLCOMPILER_EXPORT QQmlJSAotCompilerStats
72{
73public:
74 static AotStats *instance() { return s_instance.get(); }
75
76 static bool recordAotStats() { return s_recordAotStats; }
77 static void setRecordAotStats(bool recordAotStats) { s_recordAotStats = recordAotStats; }
78
79 static const QString &moduleId() { return s_moduleId; }
80 static void setModuleId(QString moduleId) { s_moduleId = moduleId; }
81
82 static void registerFile(const QString &filepath);
83 static void addEntry(const QString &filepath, const QQmlJS::AotStatsEntry &entry);
84
85private:
86 static std::unique_ptr<AotStats> s_instance;
87 static QString s_moduleId;
88 static bool s_recordAotStats;
89};
90
91} // namespace QQmlJS
92
93QT_END_NAMESPACE
94
95#endif // QQMLJSCOMPILERSTATS_P_H
96

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtdeclarative/src/qmlcompiler/qqmljscompilerstats_p.h