aboutsummaryrefslogtreecommitdiffstats
path: root/kernel-shark/src/KsCaptureDialog.hpp
blob: b168a2bc2b4d5a7cd0c3daaaa1326bbead47906b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* SPDX-License-Identifier: LGPL-2.1 */

/*
 * Copyright (C) 2017 VMware Inc, Yordan Karadzhov <ykaradzhov@vmware.com>
 */

/**
 *  @file    KsCaptureDialog.hpp
 *  @brief   Dialog for trace data recording.
 */

#ifndef _KS_CAPTURE_H
#define _KS_CAPTURE_H

// Qt
#include <QtWidgets>

// KernelShark
#include "KsWidgetsLib.hpp"

/**
 * The KsCaptureControl class provides a control panel for the KernelShark
 * Capture dialog.
 */
class KsCaptureControl : public QWidget
{
	Q_OBJECT
public:
	explicit KsCaptureControl(QWidget *parent = 0);

	QStringList getArgs();

	/** Get the name of the tracing data output file. */
	QString outputFileName() const {return _outputLineEdit.text();}

	/** Set the name of the tracing data output file. */
	void setOutputFileName(const QString &f) {_outputLineEdit.setText(f);}

signals:
	/** This signal is emitted when the "Apply" button is pressed. */
	void argsReady(const QString &args);

private:
	tep_handle		*_localTEP;

	KsEventsCheckBoxWidget	_eventsWidget;

	QVBoxLayout	_topLayout;

	QGridLayout	_execLayout;

	QLabel		_pluginsLabel, _outputLabel, _commandLabel;

	QLineEdit	_outputLineEdit, _commandLineEdit;

	QToolBar	_settingsToolBar, _controlToolBar;

	QComboBox	_pluginsComboBox;

	QPushButton	_importSettingsButton, _exportSettingsButton;

	QPushButton	_outputBrowseButton;

	QString		_lastFilePath;

	QStringList _getPlugins();

	void _importSettings();

	void _exportSettings();

	void _browse();

	void _apply();

public:
	/**
	 * A Check box used to indicate if the output of the command needs to
	 * be shown by the KsCaptureMonitor widget.
	 */
	QCheckBox	_commandCheckBox;

	/** Capture button for the control panel. */
	QPushButton	_captureButton;

	/** Apply button for the control panel. */
	QPushButton	_applyButton;

	/** Close button for the control panel. */
	QPushButton	_closeButton;
};

/**
 * The KsCaptureMonitor class provides a terminal-like widget for monitoring
 * the tracing data recording process.
 */
class KsCaptureMonitor : public QWidget
{
	Q_OBJECT
public:
	explicit KsCaptureMonitor(QWidget *parent = 0);

	/** Get the text shown by the widget. */
	QString text() const {return _consolOutput.toPlainText();}

	/** Clear the text shown by the widget. */
	void clear() {_consolOutput.clear();}

	void print(const QString &message);

	void connectMe(QProcess *proc, KsCaptureControl *ctrl);

	/** A flag indicating if the stdout and stderr channels are _merged. */
	bool		_mergedChannels;

	/**
	 * A flag indicating, if the list of the command line arguments for trace-cmd
	 * has been edited by the user.
	 */
	bool		_argsModified;

	bool		_captureStatus;

private:
	QVBoxLayout	_layout;

	QToolBar	_panel;

	QLabel		_name, _space;

	QCheckBox	_readOnlyCB;

	QLineEdit	_maxLinNumEdit;

	QPlainTextEdit	_consolOutput;

	void _argsReady(const QString &test);

	void _maxLineNumber(const QString &test);

	void _readOnly(int);

	void _argVModified();

	void _captureStarted();

	void _printAllStandardError();

	void _printAllStandardOutput();

private slots:
	void _captureFinished(int, QProcess::ExitStatus);
};

/** Default number of lines shown by the KsCaptureMonitor widget. */
#define KS_CAP_MON_MAX_LINE_NUM 200

/**
 * The KsCaptureDialog class provides a dialog for recording of tracing data.
 */
class KsCaptureDialog : public QWidget
{
	Q_OBJECT
public:
	explicit KsCaptureDialog(QWidget *parent = 0);

	/** Set the name of the tracing data output file. */
	void setOutputFileName(const QString &f)
	{
		_captureCtrl.setOutputFileName(f);
	}

private:
	QHBoxLayout		_layout;

	KsCaptureControl	_captureCtrl;

	KsCaptureMonitor	_captureMon;

	QProcess		_captureProc;

	void _capture();

	void _setChannelMode(int state);

	void _sendOpenReq(const QString &fileName);
};

#endif // _KS_CAPTURE_H