| 1 | // Copyright (C) 2016 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 QMLPROFILERAPPLICATION_H |
| 5 | #define QMLPROFILERAPPLICATION_H |
| 6 | |
| 7 | #include "qmlprofilerclient.h" |
| 8 | #include "qmlprofilerdata.h" |
| 9 | |
| 10 | #include <private/qqmldebugconnection_p.h> |
| 11 | |
| 12 | #include <QtCore/qcoreapplication.h> |
| 13 | #include <QtCore/qprocess.h> |
| 14 | #include <QtCore/qtimer.h> |
| 15 | #include <QtNetwork/qabstractsocket.h> |
| 16 | |
| 17 | enum PendingRequest { |
| 18 | REQUEST_QUIT, |
| 19 | REQUEST_FLUSH_FILE, |
| 20 | REQUEST_FLUSH, |
| 21 | REQUEST_OUTPUT_FILE, |
| 22 | REQUEST_TOGGLE_RECORDING, |
| 23 | REQUEST_NONE |
| 24 | }; |
| 25 | |
| 26 | class QmlProfilerApplication : public QCoreApplication |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | public: |
| 30 | QmlProfilerApplication(int &argc, char **argv); |
| 31 | ~QmlProfilerApplication(); |
| 32 | |
| 33 | void parseArguments(); |
| 34 | int exec(); |
| 35 | bool isInteractive() const; |
| 36 | void userCommand(const QString &command); |
| 37 | void notifyTraceStarted(); |
| 38 | void outputData(); |
| 39 | |
| 40 | Q_SIGNALS: |
| 41 | void readyForCommand(); |
| 42 | |
| 43 | private: |
| 44 | void run(); |
| 45 | void tryToConnect(); |
| 46 | void connected(); |
| 47 | void disconnected(); |
| 48 | void processHasOutput(); |
| 49 | void processFinished(); |
| 50 | |
| 51 | void traceClientEnabledChanged(bool enabled); |
| 52 | void traceFinished(); |
| 53 | |
| 54 | void prompt(const QString &line = QString(), bool ready = true); |
| 55 | void logError(const QString &error); |
| 56 | void logWarning(const QString &warning); |
| 57 | void logStatus(const QString &status); |
| 58 | |
| 59 | quint64 parseFeatures(const QStringList &featureList, const QString &values, bool exclude); |
| 60 | bool checkOutputFile(PendingRequest pending); |
| 61 | void flush(); |
| 62 | void output(); |
| 63 | |
| 64 | enum ApplicationMode { |
| 65 | LaunchMode, |
| 66 | AttachMode |
| 67 | } m_runMode; |
| 68 | |
| 69 | // LaunchMode |
| 70 | QString m_executablePath; |
| 71 | QStringList m_arguments; |
| 72 | QProcess *m_process; |
| 73 | |
| 74 | QString m_socketFile; |
| 75 | QString m_hostName; |
| 76 | quint16 m_port; |
| 77 | QString m_outputFile; |
| 78 | QString m_interactiveOutputFile; |
| 79 | |
| 80 | PendingRequest m_pendingRequest; |
| 81 | bool m_verbose; |
| 82 | bool m_recording; |
| 83 | bool m_interactive; |
| 84 | |
| 85 | QScopedPointer<QQmlDebugConnection> m_connection; |
| 86 | QScopedPointer<QmlProfilerClient> m_qmlProfilerClient; |
| 87 | QScopedPointer<QmlProfilerData> m_profilerData; |
| 88 | QTimer m_connectTimer; |
| 89 | uint m_connectionAttempts; |
| 90 | }; |
| 91 | |
| 92 | #endif // QMLPROFILERAPPLICATION_H |
| 93 | |