1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef QMLPROFILERAPPLICATION_H
30#define QMLPROFILERAPPLICATION_H
31
32#include "qmlprofilerclient.h"
33#include "qmlprofilerdata.h"
34
35#include <private/qqmldebugconnection_p.h>
36
37#include <QtCore/qcoreapplication.h>
38#include <QtCore/qprocess.h>
39#include <QtCore/qtimer.h>
40#include <QtNetwork/qabstractsocket.h>
41
42enum PendingRequest {
43 REQUEST_QUIT,
44 REQUEST_FLUSH_FILE,
45 REQUEST_FLUSH,
46 REQUEST_OUTPUT_FILE,
47 REQUEST_TOGGLE_RECORDING,
48 REQUEST_NONE
49};
50
51class QmlProfilerApplication : public QCoreApplication
52{
53 Q_OBJECT
54public:
55 QmlProfilerApplication(int &argc, char **argv);
56 ~QmlProfilerApplication();
57
58 void parseArguments();
59 int exec();
60 bool isInteractive() const;
61 void userCommand(const QString &command);
62 void notifyTraceStarted();
63 void outputData();
64
65signals:
66 void readyForCommand();
67
68private:
69 void run();
70 void tryToConnect();
71 void connected();
72 void disconnected();
73 void processHasOutput();
74 void processFinished();
75
76 void traceClientEnabledChanged(bool enabled);
77 void traceFinished();
78
79 void prompt(const QString &line = QString(), bool ready = true);
80 void logError(const QString &error);
81 void logStatus(const QString &status);
82
83 quint64 parseFeatures(const QStringList &featureList, const QString &values, bool exclude);
84 bool checkOutputFile(PendingRequest pending);
85 void flush();
86 void output();
87
88 enum ApplicationMode {
89 LaunchMode,
90 AttachMode
91 } m_runMode;
92
93 // LaunchMode
94 QString m_executablePath;
95 QStringList m_arguments;
96 QProcess *m_process;
97
98 QString m_socketFile;
99 QString m_hostName;
100 quint16 m_port;
101 QString m_outputFile;
102 QString m_interactiveOutputFile;
103
104 PendingRequest m_pendingRequest;
105 bool m_verbose;
106 bool m_recording;
107 bool m_interactive;
108
109 QScopedPointer<QQmlDebugConnection> m_connection;
110 QScopedPointer<QmlProfilerClient> m_qmlProfilerClient;
111 QScopedPointer<QmlProfilerData> m_profilerData;
112 QTimer m_connectTimer;
113 uint m_connectionAttempts;
114};
115
116#endif // QMLPROFILERAPPLICATION_H
117

source code of qtdeclarative/tools/qmlprofiler/qmlprofilerapplication.h