Add Qt-based GUI for KernelShark
v2 cover Add Qt-based GUI for KernelShark
In this series of patches the major components of the Qt-based KernelShark GUI are introduced one by one in a sequence which follows there internal dependence. The series ends with the fully functional KernelShark GUI application.
Yordan Karadzhov (5):
kernel-shark-qt: Fix a simple bug in KsDataStore::_freeData()
kernel-shark-qt: Add "File exists" dialog.
kernel-shark-qt: Fix the glitches in the preemption time visualization
kernel-shark-qt: Add PolicyKit Configuration for kshark-record
kernel-shark-qt: Add Record dialog to KS GUI.
Yordan Karadzhov (VMware) (18):
kernel-shark-qt: Add Dual Marker for KernelShark GUI.
kernel-shark-qt: Add model for showing trace data in a text format.
kernel-shark-qt: Add Trace Viewer widget.
kernel-shark-qt: Add visualization (graph) model
kernel-shark-qt: Add widget for OpenGL rendering
kernel-shark-qt: Add Trace Graph widget.
kernel-shark-qt: Add dialog for Advanced filtering.
kernel-shark-qt: Add a manager class for GUI sessions.
kernel-shark-qt: Add Main Window widget for the KernelShark GUI.
kernel-shark-qt: Add KernelShark GUI executable.
kernel-shark-qt: Add dialog for of trace data recording
kernel-shark-qt: Add kshark-record executable
kernel-shark-qt: Instruct CMake to search for "pkexec"
kernel-shark-qt: Add KernelShark icon
kernel-shark-qt: Add kernelshark.desktop file
kernel-shark-qt: Add make install
kernel-shark-qt: Workaround for running as Root on Wayland
kernel-shark-qt: Version 0.9.0
kernel-shark-qt/CMakeLists.txt | 15 +- kernel-shark-qt/bin/kshark-su-record | 8 + kernel-shark-qt/build/cmake_clean.sh | 1 + kernel-shark-qt/build/cmake_uninstall.sh | 17 + kernel-shark-qt/build/deff.h.cmake | 3 + kernel-shark-qt/build/ks.desktop.cmake | 9 + kernel-shark-qt/icons/ksharkicon.png | Bin 0 -> 80474 bytes .../org.freedesktop.kshark-record.policy | 18 + kernel-shark-qt/src/CMakeLists.txt | 44 +- kernel-shark-qt/src/KsAdvFilteringDialog.cpp | 440 +++++++ kernel-shark-qt/src/KsAdvFilteringDialog.hpp | 91 ++ kernel-shark-qt/src/KsCaptureDialog.cpp | 562 +++++++++ kernel-shark-qt/src/KsCaptureDialog.hpp | 185 +++ kernel-shark-qt/src/KsDualMarker.cpp | 336 ++++++ kernel-shark-qt/src/KsDualMarker.hpp | 190 +++ kernel-shark-qt/src/KsGLWidget.cpp | 913 +++++++++++++++ kernel-shark-qt/src/KsGLWidget.hpp | 220 ++++ kernel-shark-qt/src/KsMainWindow.cpp | 1029 +++++++++++++++++ kernel-shark-qt/src/KsMainWindow.hpp | 213 ++++ kernel-shark-qt/src/KsModels.cpp | 485 ++++++++ kernel-shark-qt/src/KsModels.hpp | 289 +++++ kernel-shark-qt/src/KsSession.cpp | 574 +++++++++ kernel-shark-qt/src/KsSession.hpp | 100 ++ kernel-shark-qt/src/KsTraceGraph.cpp | 690 +++++++++++ kernel-shark-qt/src/KsTraceGraph.hpp | 137 +++ kernel-shark-qt/src/KsTraceViewer.cpp | 657 +++++++++++ kernel-shark-qt/src/KsTraceViewer.hpp | 149 +++ kernel-shark-qt/src/KsUtils.cpp | 2 + kernel-shark-qt/src/KsWidgetsLib.cpp | 29 + kernel-shark-qt/src/KsWidgetsLib.hpp | 7 + kernel-shark-qt/src/kernelshark.cpp | 93 ++ kernel-shark-qt/src/kshark-record.cpp | 29 + kernel-shark-qt/src/plugins/CMakeLists.txt | 3 + kernel-shark-qt/src/plugins/SchedEvents.cpp | 126 +- kernel-shark-qt/src/plugins/sched_events.c | 13 +- 35 files changed, 7628 insertions(+), 49 deletions(-) create mode 100755 kernel-shark-qt/bin/kshark-su-record create mode 100755 kernel-shark-qt/build/cmake_uninstall.sh create mode 100644 kernel-shark-qt/build/ks.desktop.cmake create mode 100644 kernel-shark-qt/icons/ksharkicon.png create mode 100644 kernel-shark-qt/org.freedesktop.kshark-record.policy create mode 100644 kernel-shark-qt/src/KsAdvFilteringDialog.cpp create mode 100644 kernel-shark-qt/src/KsAdvFilteringDialog.hpp create mode 100644 kernel-shark-qt/src/KsCaptureDialog.cpp create mode 100644 kernel-shark-qt/src/KsCaptureDialog.hpp create mode 100644 kernel-shark-qt/src/KsDualMarker.cpp create mode 100644 kernel-shark-qt/src/KsDualMarker.hpp create mode 100644 kernel-shark-qt/src/KsGLWidget.cpp create mode 100644 kernel-shark-qt/src/KsGLWidget.hpp create mode 100644 kernel-shark-qt/src/KsMainWindow.cpp create mode 100644 kernel-shark-qt/src/KsMainWindow.hpp create mode 100644 kernel-shark-qt/src/KsModels.cpp create mode 100644 kernel-shark-qt/src/KsModels.hpp create mode 100644 kernel-shark-qt/src/KsSession.cpp create mode 100644 kernel-shark-qt/src/KsSession.hpp create mode 100644 kernel-shark-qt/src/KsTraceGraph.cpp create mode 100644 kernel-shark-qt/src/KsTraceGraph.hpp create mode 100644 kernel-shark-qt/src/KsTraceViewer.cpp create mode 100644 kernel-shark-qt/src/KsTraceViewer.hpp create mode 100644 kernel-shark-qt/src/kernelshark.cpp create mode 100644 kernel-shark-qt/src/kshark-record.cpp
Signature · 1 line
2.17.1
PATCH v2 1/23 kernel-shark-qt: Fix a simple bug in KsDataStore::_freeData()
After freeing the memory used to store the tracing data, this function has to set the _dataSize field to zero.
--- kernel-shark-qt/src/KsUtils.cpp | 2 ++ 1 file changed, 2 insertions(+)
kernel-shark-qt/src/KsUtils.cpp +2 -0
@@ -144,6 +144,8 @@ void KsDataStore::_freeData() free(_rows); _rows = nullptr; } + + _dataSize = 0; } /** Reload the trace data. */
Signature · 1 line
2.17.1
PATCH v2 2/23 kernel-shark-qt: Add Dual Marker for KernelShark GUI.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch implements the Dual Marker used by the KernelShark GUI. The Dual Marker uses a simple State Machine having only two states (A and B). In the following patches the State Machine will connect to the Table and Graph widgets (not introduced yet) and will allow the user's actions in one of these widgets to have effect in the other one.
--- kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsDualMarker.cpp | 332 +++++++++++++++++++++++++++ kernel-shark-qt/src/KsDualMarker.hpp | 188 +++++++++++++++ 3 files changed, 522 insertions(+) create mode 100644 kernel-shark-qt/src/KsDualMarker.cpp create mode 100644 kernel-shark-qt/src/KsDualMarker.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -32,11 +32,13 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) message(STATUS "libkshark-gui") set (ks-guiLib_hdr KsUtils.hpp + KsDualMarker.hpp KsWidgetsLib.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr}) add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp + KsDualMarker.cpp KsWidgetsLib.cpp) target_link_libraries(kshark-gui kshark-plot
kernel-shark-qt/src/KsDualMarker.cpp new file +332 -0
332 lines not on this page · raw message
kernel-shark-qt/src/KsDualMarker.hpp new file +188 -0
188 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 02/23] kernel-shark-qt: Add Dual Marker for KernelShark GUI.
Quoted 12 lines · On Tue, 16 Oct 2018 15:52:58 +0000 Yordan Karadzhov <[email protected]>…
kernel-shark-qt/src/KsDualMarker.cpp new file +12
-0+ +/** @brief Create a Dual Marker State Machine. */ +KsDualMarkerSM::KsDualMarkerSM(QWidget *parent) +: QWidget(parent), + _buttonA("Marker A", this), + _buttonB("Marker B", this), + _labelDeltaDescr(" A,B Delta: ", this), + _markA(DualMarkerState::A, Qt::darkGreen), + _markB(DualMarkerState::B, Qt::darkCyan), + _scCtrlA(this), + _scCtrlB(this) +{
kernel-shark-qt/src/KsDualMarker.cpp line 135
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ QString styleSheetA, styleSheetB; + + _buttonA.setFixedWidth(STRING_WIDTH(" Marker A ")); + _buttonB.setFixedWidth(STRING_WIDTH(" Marker B ")); + + for (auto const &l: {&_labelMA, &_labelMB, &_labelDelta}) { + l->setFrameStyle(QFrame::Panel | QFrame::Sunken); + l->setStyleSheet("QLabel {background-color : white;}"); + l->setTextInteractionFlags(Qt::TextSelectableByMouse); + l->setFixedWidth(FONT_WIDTH * 16);
As a general rule, no "magic numbers". Why 16?
Quoted 5 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +5
-0+ } + + styleSheetA = "background : " + + _markA._color.name() + + "; color : white";
kernel-shark-qt/src/KsDualMarker.cpp line 150
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ + _stateA = new QState; + _stateA->setObjectName("A"); + _stateA->assignProperty(&_buttonA, + "styleSheet", + styleSheetA); + + _stateA->assignProperty(&_buttonB, + "styleSheet", + "color : rgb(70, 70, 70)");
Same for the 70s.
kernel-shark-qt/src/KsDualMarker.cpp line 160
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ + styleSheetB = "background : " + + _markB._color.name() + + "; color : white"; + + _stateB = new QState; + _stateB->setObjectName("B"); + _stateB->assignProperty(&_buttonA, + "styleSheet", + "color : rgb(70, 70, 70)");
Here too.
Quoted 44 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +41
-0+ + _stateB->assignProperty(&_buttonB, + "styleSheet", + styleSheetB); + + /* Define transitions from State A to State B. */ + _stateA->addTransition(this, &KsDualMarkerSM::machineToB, _stateB); + + _scCtrlA.setKey(Qt::CTRL + Qt::Key_A); + _stateA->addTransition(&_scCtrlB, &QShortcut::activated, _stateB); + + connect(&_scCtrlA, &QShortcut::activated, + this, &KsDualMarkerSM::_doStateA); + + _stateA->addTransition(&_buttonB, &QPushButton::clicked, _stateB); + + connect(&_buttonB, &QPushButton::clicked, + this, &KsDualMarkerSM::_doStateB); + + /* Define transitions from State B to State A. */ + _stateB->addTransition(this, &KsDualMarkerSM::machineToA, _stateA); + + _scCtrlB.setKey(Qt::CTRL + Qt::Key_B); + _stateB->addTransition(&_scCtrlA, &QShortcut::activated, _stateA); + + connect(&_scCtrlB, &QShortcut::activated, + this, &KsDualMarkerSM::_doStateB); + + _stateB->addTransition(&_buttonA, &QPushButton::clicked, _stateA); + + connect(&_buttonA, &QPushButton::clicked, + this, &KsDualMarkerSM::_doStateA); + + _machine.addState(_stateA); + _machine.addState(_stateB); + _machine.setInitialState(_stateA); + _markState = DualMarkerState::A; + _machine.start(); +} + +/**
kernel-shark-qt/src/KsDualMarker.cpp
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ * @brief Use this function to update the labels when the state of the model + * has changed. + */ +void KsDualMarkerSM::updateLabels() +{ + QString mark, delta; + + // Marker A + if (_markA._isSet) { + mark = KsUtils::Ts2String(_markA._ts, 7);
Same for these 7s.
Quoted 11 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +11
-0+ _labelMA.setText(mark); + } else { + _labelMA.setText(""); + } + + // Marker B + if (_markB._isSet) { + mark = KsUtils::Ts2String(_markB._ts, 7); + _labelMB.setText(mark); + } else { + _labelMB.setText("");
kernel-shark-qt/src/KsDualMarker.cpp line 332
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ } + + // Delta + if (_markA._isSet && _markB._isSet) { + delta = KsUtils::Ts2String(_markB._ts - _markA._ts, 7); + _labelDelta.setText(delta); + } else { + _labelDelta.setText(""); + } +}
Don't resend this patch (I'm going to just take it). Send a patch on top that just replaces the hard coded numbers with meaningful macros.
Thanks!
-- Steve
Re: [PATCH v2 02/23] kernel-shark-qt: Add Dual Marker for KernelShark GUI.
Quoted 30 lines · Steven Rostedt
Quoted 12 lines · On Tue, 16 Oct 2018 15:52:58 +0000 Yordan Karadzhov <[email protected]>…
kernel-shark-qt/src/KsDualMarker.cpp new file +12
-0+ +/** @brief Create a Dual Marker State Machine. */ +KsDualMarkerSM::KsDualMarkerSM(QWidget *parent) +: QWidget(parent), + _buttonA("Marker A", this), + _buttonB("Marker B", this), + _labelDeltaDescr(" A,B Delta: ", this), + _markA(DualMarkerState::A, Qt::darkGreen), + _markB(DualMarkerState::B, Qt::darkCyan), + _scCtrlA(this), + _scCtrlB(this) +{kernel-shark-qt/src/KsDualMarker.cpp line 135
Quoted 10 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +10
-0+ QString styleSheetA, styleSheetB; + + _buttonA.setFixedWidth(STRING_WIDTH(" Marker A ")); + _buttonB.setFixedWidth(STRING_WIDTH(" Marker B ")); + + for (auto const &l: {&_labelMA, &_labelMB, &_labelDelta}) { + l->setFrameStyle(QFrame::Panel | QFrame::Sunken); + l->setStyleSheet("QLabel {background-color : white;}"); + l->setTextInteractionFlags(Qt::TextSelectableByMouse); + l->setFixedWidth(FONT_WIDTH * 16);As a general rule, no "magic numbers". Why 16?
Quoted 3 lines
Don't resend this patch (I'm going to just take it). Send a patch on top that just replaces the hard coded numbers with meaningful macros.
Hi Steven,
This is one of these cases when I disagree with you. I don't see anything wrong with the line
l->setFixedWidth(FONT_WIDTH * 16);
or the many other lines in the code which are similar to this one.
It sets the width of the label to be 16 times the width of a typical character shown by Qt at the particular resolution of your screen.
The line is perfectly self-explanatory. And there is nothing magic in the number 16. It is just a normal number that everyone can understand end modify if this is necessary. Why 16? Because I tried different sizes and I found that this particular one looks nicer to me. If you find this size ugly, it is absolutist trivial to change it.
Now let's look in the alternative that you suggest (if I understand correctly):
l->setFixedWidth(DUAL_MARKER_TOOLBAR_LABEL_WIDTH);
This line is a magic word, because it tells you absolutist nothing about the actual size of this label. And if we apply this rule everywhere, we will need a ton of macros, with very long and in the same time very similar names. This will also make the geometry of the GUI completely hard-coded and will eliminate any possibility of making these sizes configurable via the Json I/O.
I do not believe in "general rules". Each rule has a field of applicability. When you program GUIs you need to apply fine tuning. I don't think we can avoid this. Thanks!
Yordan
Quoted 4 lines
Thanks!
-- Steve
Re: [PATCH v2 02/23] kernel-shark-qt: Add Dual Marker for KernelShark GUI.
In reply to Yordan KaradzhovReview
Quoted 2 lines · On Tue, 16 Oct 2018 15:52:58 +0000 Yordan Karadzhov <[email protected]>…
(quoted diff) +2
-0+ +/** Get the Graph marker associated with a given state. */
Also be careful about extre whitespace. There's a extra space at the end of the above line.
(I removed it in the commit).
-- Steve
Quoted 7 lines
kernel-shark-qt/src/KsDualMarker.cpp new file +7
-0+KsGraphMark &KsDualMarkerSM::getMarker(DualMarkerState s) +{ + if (s == DualMarkerState::A) + return _markA; + + return _markB; +}
PATCH v2 3/23 kernel-shark-qt: Add model for showing trace data in a text format.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines the model used by the Trace Viewer widget used to display trace data in a table-like form.
--- kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsModels.cpp | 332 +++++++++++++++++++++++++++++ kernel-shark-qt/src/KsModels.hpp | 223 +++++++++++++++++++ 3 files changed, 557 insertions(+) create mode 100644 kernel-shark-qt/src/KsModels.cpp create mode 100644 kernel-shark-qt/src/KsModels.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -32,12 +32,14 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) message(STATUS "libkshark-gui") set (ks-guiLib_hdr KsUtils.hpp + KsModels.hpp KsDualMarker.hpp KsWidgetsLib.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr}) add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp + KsModels.cpp KsDualMarker.cpp KsWidgetsLib.cpp)
kernel-shark-qt/src/KsModels.cpp new file +332 -0
332 lines not on this page · raw message
kernel-shark-qt/src/KsModels.hpp new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 4/23 kernel-shark-qt: Add Trace Viewer widget.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines widget for browsing in the trace data shown in a text form. The provides a search panel and a Table view area. The panel and the table are integrated with the Dual Marker.
--- kernel-shark-qt/src/CMakeLists.txt | 6 +- kernel-shark-qt/src/KsTraceViewer.cpp | 657 ++++++++++++++++++++++++++ kernel-shark-qt/src/KsTraceViewer.hpp | 149 ++++++ 3 files changed, 810 insertions(+), 2 deletions(-) create mode 100644 kernel-shark-qt/src/KsTraceViewer.cpp create mode 100644 kernel-shark-qt/src/KsTraceViewer.hpp
kernel-shark-qt/src/CMakeLists.txt +4 -2
@@ -34,14 +34,16 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) set (ks-guiLib_hdr KsUtils.hpp KsModels.hpp KsDualMarker.hpp - KsWidgetsLib.hpp) + KsWidgetsLib.hpp + KsTraceViewer.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr}) add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp KsModels.cpp KsDualMarker.cpp - KsWidgetsLib.cpp) + KsWidgetsLib.cpp + KsTraceViewer.cpp) target_link_libraries(kshark-gui kshark-plot ${CMAKE_DL_LIBS}
kernel-shark-qt/src/KsTraceViewer.cpp new file +657 -0
657 lines not on this page · raw message
kernel-shark-qt/src/KsTraceViewer.hpp new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 04/23] kernel-shark-qt: Add Trace Viewer widget.
Quoted 6 lines · On Tue, 16 Oct 2018 15:53:01 +0000 Yordan Karadzhov <[email protected]>…
From: Yordan Karadzhov (VMware) <[email protected]>
This patch defines widget for browsing in the trace data shown in a text form. The provides a search panel and a Table view area. The panel and the table are integrated with the Dual Marker.
BTW, for the subject, leave off the period at the end.
Thanks!
-- Steve
Re: [PATCH v2 04/23] kernel-shark-qt: Add Trace Viewer widget.
In reply to Yordan Karadzhovkernel-shark-qt/src/KsTraceViewer.cpp line 510
Quoted 7 lines · On Tue, 16 Oct 2018 15:53:01 +0000 Yordan Karadzhov <[email protected]>…
kernel-shark-qt/src/KsTraceViewer.cpp new file +7
-0+ if ((freeSpace = viewSize - tableSize) > 0) { + _view.setColumnWidth(nColumns - 1, _view.columnWidth(nColumns - 1) + + freeSpace - + 2); /* Just a little bit less space. + * This will allow the scroll bar + * to disappear when the widget + * is extended to maximum. */
The above is rather ugly. Again, just have another patch on top that converts this to:
if ((freeSpace = viewSize - tableSize) > 0) {
_view.setColumnWidth(nColumns - 1, _view.columnWidth(nColumns - 1) +
freeSpace - 2);
/* Just a little bit less space.
* This will allow the scroll bar
* to disappear when the widget
* is extended to maximum. */
}-- Steve
PATCH v2 5/23 kernel-shark-qt: Add visualization (graph) model
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines the class KsGraphModel which provides a model for visualization of trace data. This class is a wrapper of kshark_trace_histo and is needed only because we want to use the signals defined in QAbstractTableModel (a class inherited by KsGraphModel).
--- kernel-shark-qt/src/KsModels.cpp | 153 +++++++++++++++++++++++++++++++ kernel-shark-qt/src/KsModels.hpp | 66 +++++++++++++ 2 files changed, 219 insertions(+)
kernel-shark-qt/src/KsModels.cpp +153 -0
@@ -330,3 +330,156 @@ size_t KsViewModel::search(int column, return matchList->count(); } + +/** Create a default (empty) KsFilterProxyModel object. */ +KsGraphModel::KsGraphModel(QObject *parent) +: QAbstractTableModel(parent) +{ + ksmodel_init(&_histo); +} + +/** Destroy KsFilterProxyModel object. */ +KsGraphModel::~KsGraphModel() +{ + ksmodel_clear(&_histo); +} + +/** + * @brief Provide the Visualization model with data. Calculate the current + * state of the model. + * + * @param entries: Input location for the trace data. + * @param n: Number of bins. + */ +void KsGraphModel::fill(kshark_entry **entries, size_t n) +{ + if (n == 0) + return; + + beginResetModel(); + + if (_histo.n_bins == 0) + ksmodel_set_bining(&_histo, + KS_DEFAULT_NBUNS, + entries[0]->ts, + entries[n-1]->ts); + + ksmodel_fill(&_histo, entries, n); + + endResetModel(); +} + +/** + * @brief Shift the time-window of the model forward. Recalculate the current + * state of the model. + * + * @param n: Number of bins to shift. + */ +void KsGraphModel::shiftForward(size_t n) +{ + beginResetModel(); + ksmodel_shift_forward(&_histo, n); + endResetModel(); +} + +/** + * @brief Shift the time-window of the model backward. Recalculate the current + * state of the model. + * + * @param n: Number of bins to shift. + */ +void KsGraphModel::shiftBackward(size_t n) +{ + beginResetModel(); + ksmodel_shift_backward(&_histo, n); + endResetModel(); +} + +/** + * @brief Move the time-window of the model to a given location. Recalculate + * the current state of the model. + * + * @param ts: position in time to be visualized. + */ +void KsGraphModel::jumpTo(size_t ts) +{ + beginResetModel(); + ksmodel_jump_to(&_histo, ts); + endResetModel(); +} + +/** + * @brief Extend the time-window of the model. Recalculate the current state + * of the model. + * + * @param r: Scale factor of the zoom-out. + * @param mark: Focus point of the zoom-out. + */ +void KsGraphModel::zoomOut(double r, int mark) +{ + beginResetModel(); + ksmodel_zoom_out(&_histo, r, mark); + endResetModel(); +} + +/** + * @brief Shrink the time-window of the model. Recalculate the current state + * of the model. + * + * @param r: Scale factor of the zoom-in. + * @param mark: Focus point of the zoom-in. + */ +void KsGraphModel::zoomIn(double r, int mark) +{ + beginResetModel(); + ksmodel_zoom_in(&_histo, r, mark); + endResetModel(); +} + +/** Quick zoom out. The entire data-set will be visualized. */ +void KsGraphModel::quickZoomOut() +{ + beginResetModel(); + + ksmodel_set_bining(&_histo, + _histo.n_bins, + _histo.data[0]->ts, + _histo.data[_histo.data_size - 1]->ts); + + ksmodel_fill(&_histo, _histo.data, _histo.data_size); + + endResetModel(); +} + +/** + * @brief Quick zoom in to a state of the Visualization model which has the + * given bin size. The actual value of the bin size may en up being slightly + * different because of the fine tuning performed by the model. + * + * @param binSize: an approximate value for the new size of the bins. + */ +void KsGraphModel::quickZoomIn(uint64_t binSize) +{ + double range, r; + + range = _histo.max - _histo.min; + r = 1 - (binSize * _histo.n_bins) / range; + zoomIn(r); +} + +/** Reset the model. */ +void KsGraphModel::reset() +{ + beginResetModel(); + ksmodel_clear(&_histo); + endResetModel(); +} + +/** Update the model. Use this function if the data has changed. */ +void KsGraphModel::update(KsDataStore *data) +{ + beginResetModel(); + if (data) + ksmodel_fill(&_histo, data->rows(), data->size()); + endResetModel(); +}
kernel-shark-qt/src/KsModels.hpp +66 -0
70 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 6/23 kernel-shark-qt: Add widget for OpenGL rendering
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines the widget for rendering OpenGL graphics used to plot trace graphs.
--- kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsDualMarker.cpp | 12 +- kernel-shark-qt/src/KsDualMarker.hpp | 4 +- kernel-shark-qt/src/KsGLWidget.cpp | 913 +++++++++++++++++++++++++++ kernel-shark-qt/src/KsGLWidget.hpp | 220 +++++++ 5 files changed, 1146 insertions(+), 5 deletions(-) create mode 100644 kernel-shark-qt/src/KsGLWidget.cpp create mode 100644 kernel-shark-qt/src/KsGLWidget.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -33,6 +33,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) message(STATUS "libkshark-gui") set (ks-guiLib_hdr KsUtils.hpp KsModels.hpp + KsGLWidget.hpp KsDualMarker.hpp KsWidgetsLib.hpp KsTraceViewer.hpp)
@@ -41,6 +42,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp KsModels.cpp + KsGLWidget.cpp KsDualMarker.cpp KsWidgetsLib.cpp KsTraceViewer.cpp)
kernel-shark-qt/src/KsDualMarker.cpp +8 -4
@@ -10,6 +10,7 @@ */ #include "KsDualMarker.hpp" +#include "KsGLWidget.hpp" /** * @brief Create KsGraphMark object.
@@ -287,13 +288,16 @@ void KsDualMarkerSM::setState(DualMarkerState st) { * model has changed. * * @param data: Input location for the Data Store object. - * @param histo: Input location for the model descriptor. + * @param glw: Input location for the OpenGL widget object. */ void KsDualMarkerSM::updateMarkers(const KsDataStore &data, - kshark_trace_histo *histo) + KsGLWidget *glw) { - _markA.update(data, histo); - _markB.update(data, histo); + if(_markA.update(data, glw->model()->histo())) + glw->setMark(&_markA); + + if(_markB.update(data, glw->model()->histo())) + glw->setMark(&_markB); updateLabels(); }
kernel-shark-qt/src/KsDualMarker.hpp +3 -1
@@ -19,6 +19,8 @@ #include "KsUtils.hpp" #include "KsPlotTools.hpp" +class KsGLWidget; + /** The KsGraphMark represents a marker for KernelShark GUI. */ class KsGraphMark : public QObject {
@@ -124,7 +126,7 @@ public: QState *stateBPtr() {return _stateB;} void updateMarkers(const KsDataStore &data, - kshark_trace_histo *histo); + KsGLWidget *glw); void updateLabels();
kernel-shark-qt/src/KsGLWidget.cpp new file +913 -0
913 lines not on this page · raw message
kernel-shark-qt/src/KsGLWidget.hpp new file +220 -0
220 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 06/23] kernel-shark-qt: Add widget for OpenGL rendering
Quoted 88 lines · On Tue, 16 Oct 2018 15:53:03 +0000 Yordan Karadzhov <[email protected]>…
kernel-shark-qt/src/KsGLWidget.cpp new file +82
-0@@ -0,0 +1,913 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* + * Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> + */ + + /** + * @file KsGLWidget.cpp + * @brief OpenGL widget for plotting trace graphs. + */ + +// OpenGL +#include <GL/glut.h> +#include <GL/gl.h> + +// KernelShark +#include "KsGLWidget.hpp" +#include "KsUtils.hpp" +#include "KsPlugins.hpp" +#include "KsDualMarker.hpp" + +/** Create a default (empty) OpenGL widget. */ +KsGLWidget::KsGLWidget(QWidget *parent) +: QOpenGLWidget(parent), + _hMargin(20), + _vMargin(30), + _vSpacing(20), + _mState(nullptr), + _data(nullptr), + _rubberBand(QRubberBand::Rectangle, this), + _rubberBandOrigin(0, 0), + _dpr(1) +{ + setMouseTracking(true); + + /* + * Using the old Signal-Slot syntax because QWidget::update has + * overloads. + */ + connect(&_model, SIGNAL(modelReset()), this, SLOT(update())); +} + +/** Reimplemented function used to set up all required OpenGL resources. */ +void KsGLWidget::initializeGL() +{ + _dpr = QApplication::desktop()->devicePixelRatio(); + ksplot_init_opengl(_dpr); +} + +/** + * Reimplemented function used to reprocess all graphs whene the widget has + * been resized. + */ +void KsGLWidget::resizeGL(int w, int h) +{ + ksplot_resize_opengl(w, h); + if(!_data) + return; + + /* + * From the size of the widget, calculate the number of bins. + * One bin will correspond to one pixel. + */ + int nBins = width() - _hMargin * 2; + + /* + * Reload the data. The range of the histogram is the same + * but the number of bins changes. + */ + ksmodel_set_bining(_model.histo(), + nBins, + _model.histo()->min, + _model.histo()->max); + + _model.fill(_data->rows(), _data->size()); +} + +/** Reimplemented function used to plot trace graphs. */ +void KsGLWidget::paintGL() +{ + glClear(GL_COLOR_BUFFER_BIT); +
kernel-shark-qt/src/KsGLWidget.cpp line 92
Quoted 10 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +10
-0+ loadColors(); + + /* Draw the time axis. */ + if(_data) + _drawAxisX(); + + /* Process and draw all graphs by using the built-in logic. */ + _makeGraphs(_cpuList, _taskList); + for (auto const &g: _graphs) + g->draw(1.5 * _dpr);
Again, let's get rid of the 1.5 and replace it with a meaningful macro or variable (that perhaps can be changed later?
Quoted 93 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +93
-0+ + /* Process and draw all plugin-specific shapes. */ + _makePluginShapes(_cpuList, _taskList); + while (!_shapes.empty()) { + auto s = _shapes.front(); + s->draw(); + delete s; + _shapes.pop_front(); + } + + /* + * Update and draw the markers. Make sure that the active marker + * is drawn on top. + */ + _mState->updateMarkers(*_data, this); + _mState->passiveMarker().draw(); + _mState->activeMarker().draw(); +} + +/** Reimplemented event handler used to receive mouse press events. */ +void KsGLWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + _posMousePress = _posInRange(event->pos().x()); + _rangeBoundInit(_posMousePress); + } else if (event->button() == Qt::RightButton) { + emit deselect(); + _mState->activeMarker().remove(); + _mState->updateLabels(); + _model.update(); + } +} + +int KsGLWidget::_getLastTask(struct kshark_trace_histo *histo, + int bin, int cpu) +{ + kshark_context *kshark_ctx(nullptr); + kshark_entry_collection *col; + int pid; + + if (!kshark_instance(&kshark_ctx)) + return KS_EMPTY_BIN; + + col = kshark_find_data_collection(kshark_ctx->collections, + KsUtils::matchCPUVisible, + cpu); + + for (int b = bin; b >= 0; --b) { + pid = ksmodel_get_pid_back(histo, b, cpu, false, col, nullptr); + if (pid >= 0) + return pid; + } + + return ksmodel_get_pid_back(histo, LOWER_OVERFLOW_BIN, + cpu, + false, + col, + nullptr); +} + +int KsGLWidget::_getLastCPU(struct kshark_trace_histo *histo, + int bin, int pid) +{ + kshark_context *kshark_ctx(nullptr); + kshark_entry_collection *col; + int cpu; + + if (!kshark_instance(&kshark_ctx)) + return KS_EMPTY_BIN; + + col = kshark_find_data_collection(kshark_ctx->collections, + kshark_match_pid, + pid); + + for (int b = bin; b >= 0; --b) { + cpu = ksmodel_get_cpu_back(histo, b, pid, false, col, nullptr); + if (cpu >= 0) + return cpu; + } + + return ksmodel_get_cpu_back(histo, LOWER_OVERFLOW_BIN, + pid, + false, + col, + nullptr); + +} + +/** Reimplemented event handler used to receive mouse move events. */ +void KsGLWidget::mouseMoveEvent(QMouseEvent *event) +{ + int bin, cpu, pid; + size_t row;
kernel-shark-qt/src/KsGLWidget.cpp line 195
Quoted 10 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +10
-0+ bool ret; + + if (_rubberBand.isVisible()) + _rangeBoundStretched(_posInRange(event->pos().x())); + + bin = event->pos().x() - _hMargin; + cpu = _getCPU(event->pos().y()); + pid = _getPid(event->pos().y()); + + ret = _find(bin, cpu, pid, 5, false, &row);
Why 5?
Quoted 52 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +52
-0+ if (ret) { + emit found(row); + } else { + if (cpu >= 0) { + pid = _getLastTask(_model.histo(), bin, cpu); + } + + if (pid > 0) { + cpu = _getLastCPU(_model.histo(), bin, pid); + } + + emit notFound(ksmodel_bin_ts(_model.histo(), bin), cpu, pid); + } +} + +/** Reimplemented event handler used to receive mouse release events. */ +void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + size_t posMouseRel = _posInRange(event->pos().x()); + int min, max; + if (_posMousePress < posMouseRel) { + min = _posMousePress - _hMargin; + max = posMouseRel - _hMargin; + } else { + max = _posMousePress - _hMargin; + min = posMouseRel - _hMargin; + } + + _rangeChanged(min, max); + } +} + +/** Reimplemented event handler used to receive mouse double click events. */ +void KsGLWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + _findAndSelect(event); +} + +/** Reimplemented event handler used to receive mouse wheel events. */ +void KsGLWidget::wheelEvent(QWheelEvent * event) +{ + int zoomFocus; + + if (_mState->activeMarker()._isSet && + _mState->activeMarker().isVisible()) { + /* + * Use the position of the marker as a focus point for the + * zoom. + */ + zoomFocus = _mState->activeMarker()._bin;
kernel-shark-qt/src/KsGLWidget.cpp line 257
Quoted 10 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +10
-0+ } else { + /* + * Use the position of the mouse as a focus point for the + * zoom. + */ + zoomFocus = event->pos().x() - _hMargin; + } + + if (event->delta() > 0) { + _model.zoomIn(.05, zoomFocus);
Same for the .05s
Quoted 311 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +311
-0+ } else { + _model.zoomOut(.05, zoomFocus); + } + + _mState->updateMarkers(*_data, this); +} + +/** Reimplemented event handler used to receive key press events. */ +void KsGLWidget::keyPressEvent(QKeyEvent *event) +{ + if (event->isAutoRepeat()) + return; + + switch (event->key()) { + case Qt::Key_Plus: + emit zoomIn(); + return; + + case Qt::Key_Minus: + emit zoomOut(); + return; + + case Qt::Key_Left: + emit scrollLeft(); + return; + + case Qt::Key_Right: + emit scrollRight(); + return; + + default: + QOpenGLWidget::keyPressEvent(event); + return; + } +} + +/** Reimplemented event handler used to receive key release events. */ +void KsGLWidget::keyReleaseEvent(QKeyEvent *event) +{ + if (event->isAutoRepeat()) + return; + + if(event->key() == Qt::Key_Plus || + event->key() == Qt::Key_Minus || + event->key() == Qt::Key_Left || + event->key() == Qt::Key_Right) { + emit stopUpdating(); + return; + } + + QOpenGLWidget::keyPressEvent(event); + return; +} + +/** + * @brief Load and show trace data. + * + * @param data: Input location for the KsDataStore object. + * KsDataStore::loadDataFile() must be called first. + */ +void KsGLWidget::loadData(KsDataStore *data) +{ + uint64_t tMin, tMax; + int nCPUs, nBins; + + _data = data; + + /* + * From the size of the widget, calculate the number of bins. + * One bin will correspond to one pixel. + */ + nBins = width() - _hMargin * 2; + nCPUs = tep_get_cpus(_data->tep()); + + _model.reset(); + + /* Now load the entire set of trace data. */ + tMin = _data->rows()[0]->ts; + tMax = _data->rows()[_data->size() - 1]->ts; + ksmodel_set_bining(_model.histo(), nBins, tMin, tMax); + _model.fill(_data->rows(), _data->size()); + + /* Make a default CPU list. All CPUs will be plotted. */ + _cpuList = {}; + for (int i = 0; i < nCPUs; ++i) + _cpuList.append(i); + + /* Make a default task list. No tasks will be plotted. */ + _taskList = {}; + + loadColors(); + _makeGraphs(_cpuList, _taskList); +} + +/** + * Create a Hash table of Rainbow colors. The sorted Pid values are mapped to + * the palette of Rainbow colors. + */ +void KsGLWidget::loadColors() +{ + _pidColors.clear(); + _pidColors = KsPlot::getColorTable(); +} + +/** + * Position the graphical elements of the marker according to the current + * position of the graphs inside the GL widget. + */ +void KsGLWidget::setMark(KsGraphMark *mark) +{ + mark->_mark.setDPR(_dpr); + mark->_mark.setX(mark->_bin + _hMargin); + mark->_mark.setY(_vMargin / 2 + 2, height() - _vMargin); + + if (mark->_cpu >= 0) { + mark->_mark.setCPUY(_graphs[mark->_cpu]->getBase()); + mark->_mark.setCPUVisible(true); + } else { + mark->_mark.setCPUVisible(false); + } + + if (mark->_task >= 0) { + mark->_mark.setTaskY(_graphs[mark->_task]->getBase()); + mark->_mark.setTaskVisible(true); + } else { + mark->_mark.setTaskVisible(false); + } +} + +/** + * @brief Check if a given KernelShark entry is ploted. + * + * @param e: Input location for the KernelShark entry. + * @param graphCPU: Output location for index of the CPU graph to which this + * entry belongs. If such a graph does not exist the outputted + * value is "-1". + * @param graphTask: Output location for index of the Task graph to which this + * entry belongs. If such a graph does not exist the + * outputted value is "-1". + */ +void KsGLWidget::findGraphIds(const kshark_entry &e, + int *graphCPU, + int *graphTask) +{ + int graph(0); + bool cpuFound(false), taskFound(false); + + /* + * Loop over all CPU graphs and try to find the one that + * contains the entry. + */ + for (auto const &c: _cpuList) { + if (c == e.cpu) { + cpuFound = true; + break; + } + ++graph; + } + + if (cpuFound) + *graphCPU = graph; + else + *graphCPU = -1; + + /* + * Loop over all Task graphs and try to find the one that + * contains the entry. + */ + graph = _cpuList.count(); + for (auto const &p: _taskList) { + if (p == e.pid) { + taskFound = true; + break; + } + ++graph; + } + + if (taskFound) + *graphTask = graph; + else + *graphTask = -1; +} + +void KsGLWidget::_drawAxisX() +{ + KsPlot::Point a0(_hMargin, _vMargin / 4), a1(_hMargin, _vMargin / 2); + KsPlot::Point b0(width()/2, _vMargin / 4), b1(width() / 2, _vMargin / 2); + KsPlot::Point c0(width() - _hMargin, _vMargin / 4), + c1(width() - _hMargin, _vMargin / 2); + int lineSize = 2 * _dpr; + + a0._size = c0._size = _dpr; + + a0.draw(); + c0.draw(); + KsPlot::drawLine(a0, a1, {}, lineSize); + KsPlot::drawLine(b0, b1, {}, lineSize); + KsPlot::drawLine(c0, c1, {}, lineSize); + KsPlot::drawLine(a0, c0, {}, lineSize); +} + +void KsGLWidget::_makeGraphs(QVector<int> cpuList, QVector<int> taskList) +{ + /* The very first thing to do is to clean up. */ + for (auto &g: _graphs) + delete g; + _graphs.resize(0); + + if (!_data || !_data->size()) + return; + + auto lamAddGraph = [&](KsPlot::Graph *graph) { + /* + * Calculate the base level of the CPU graph inside the widget. + * Remember that the "Y" coordinate is inverted. + */ + if (!graph) + return; + + int base = _vMargin + + _vSpacing * _graphs.count() + + KS_GRAPH_HEIGHT * (_graphs.count() + 1); + + graph->setBase(base); + _graphs.append(graph); + }; + + /* Create CPU graphs according to the cpuList. */ + for (auto const &cpu: cpuList) + lamAddGraph(_newCPUGraph(cpu)); + + /* Create Task graphs taskList to the taskList. */ + for (auto const &pid: taskList) + lamAddGraph(_newTaskGraph(pid)); +} + +void KsGLWidget::_makePluginShapes(QVector<int> cpuList, QVector<int> taskList) +{ + kshark_context *kshark_ctx(nullptr); + kshark_event_handler *evt_handlers; + KsCppArgV cppArgv; + + if (!kshark_instance(&kshark_ctx)) + return; + + cppArgv._histo = _model.histo(); + cppArgv._shapes = &_shapes; + + for (int g = 0; g < cpuList.count(); ++g) { + cppArgv._graph = _graphs[g]; + evt_handlers = kshark_ctx->event_handlers; + while (evt_handlers) { + evt_handlers->draw_func(cppArgv.toC(), + cpuList[g], + KSHARK_PLUGIN_CPU_DRAW); + + evt_handlers = evt_handlers->next; + } + } + + for (int g = 0; g < taskList.count(); ++g) { + cppArgv._graph = _graphs[cpuList.count() + g]; + evt_handlers = kshark_ctx->event_handlers; + while (evt_handlers) { + evt_handlers->draw_func(cppArgv.toC(), + taskList[g], + KSHARK_PLUGIN_TASK_DRAW); + + evt_handlers = evt_handlers->next; + } + } +} + +KsPlot::Graph *KsGLWidget::_newCPUGraph(int cpu) +{ + KsPlot::Graph *graph = new KsPlot::Graph(_model.histo(), + &_pidColors); + kshark_context *kshark_ctx(nullptr); + kshark_entry_collection *col; + + if (!kshark_instance(&kshark_ctx)) + return nullptr; + + graph->setHMargin(_hMargin); + graph->setHeight(KS_GRAPH_HEIGHT); + + col = kshark_find_data_collection(kshark_ctx->collections, + KsUtils::matchCPUVisible, + cpu); + + graph->setDataCollectionPtr(col); + graph->fillCPUGraph(cpu); + + return graph; +} + +KsPlot::Graph *KsGLWidget::_newTaskGraph(int pid) +{ + KsPlot::Graph *graph = new KsPlot::Graph(_model.histo(), + &_pidColors); + kshark_context *kshark_ctx(nullptr); + kshark_entry_collection *col; + + if (!kshark_instance(&kshark_ctx)) + return nullptr; + + graph->setHMargin(_hMargin); + graph->setHeight(KS_GRAPH_HEIGHT); + + col = kshark_find_data_collection(kshark_ctx->collections, + kshark_match_pid, pid);
kernel-shark-qt/src/KsGLWidget.cpp line 578
Quoted 10 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +10
-0+ if (!col) { + /* + * If a data collection for this task does not exist, + * register a new one. + */ + col = kshark_register_data_collection(kshark_ctx, + _data->rows(), + _data->size(), + kshark_match_pid, pid, + 25);
25?
kernel-shark-qt/src/KsGLWidget.cpp line 589
Quoted 11 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +11
-0+ } + + /* + * Data collections are efficient only when used on graphs, having a + * lot of empty bins. + * TODO: Determine the optimal criteria to decide whether to use or + * not use data collection for this graph. + */ + if (_data->size() < 1e6 && + col && col->size && + _data->size() / col->size < 100) {
Perhaps make the 1e6 and 100 in macros or variables.
-- Steve
Quoted 16 lines
kernel-shark-qt/src/KsGLWidget.cpp new file +16
-0+ /* + * No need to use collection in this case. Free the collection + * data, but keep the collection registered. This will prevent + * from recalculating the same collection next time when this + * task is ploted. + */ + kshark_reset_data_collection(col); + } + + graph->setDataCollectionPtr(col); + graph->fillTaskGraph(pid); + + return graph; +} + +
PATCH v2 7/23 kernel-shark-qt: Add Trace Graph widget.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines widget for interactive visualization of trace data shown as time-series. The provides an info panel and a graph plotting area (KsGLWidget). The panel and the plotting area are integrated with the Dual Marker.
--- kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsTraceGraph.cpp | 690 +++++++++++++++++++++++++++ kernel-shark-qt/src/KsTraceGraph.hpp | 137 ++++++ 3 files changed, 829 insertions(+) create mode 100644 kernel-shark-qt/src/KsTraceGraph.cpp create mode 100644 kernel-shark-qt/src/KsTraceGraph.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -36,6 +36,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsGLWidget.hpp KsDualMarker.hpp KsWidgetsLib.hpp + KsTraceGraph.hpp KsTraceViewer.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr})
@@ -45,6 +46,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsGLWidget.cpp KsDualMarker.cpp KsWidgetsLib.cpp + KsTraceGraph.cpp KsTraceViewer.cpp) target_link_libraries(kshark-gui kshark-plot
kernel-shark-qt/src/KsTraceGraph.cpp new file +690 -0
690 lines not on this page · raw message
kernel-shark-qt/src/KsTraceGraph.hpp new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v2 07/23] kernel-shark-qt: Add Trace Graph widget.
Quoted 52 lines · On Tue, 16 Oct 2018 15:53:05 +0000 Yordan Karadzhov <[email protected]>…
F
kernel-shark-qt/src/KsTraceGraph.cpp new file +45
-0@@ -0,0 +1,690 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* + * Copyright (C) 2017 VMware Inc, Yordan Karadzhov <[email protected]> + */ + +/** + * @file KsTraceGraph.cpp + * @brief KernelShark Trace Graph widget. + */ + +// KernelShark +#include "KsUtils.hpp" +#include "KsDualMarker.hpp" +#include "KsTraceGraph.hpp" + +/** Create a default (empty) Trace graph widget. */ +KsTraceGraph::KsTraceGraph(QWidget *parent) +: QWidget(parent), + _pointerBar(this), + _navigationBar(this), + _zoomInButton("+", this), + _quickZoomInButton("++", this), + _zoomOutButton("-", this), + _quickZoomOutButton("- -", this), + _scrollLeftButton("<", this), + _scrollRightButton(">", this), + _labelP1("Pointer: ", this), + _labelP2("", this), + _labelI1("", this), + _labelI2("", this), + _labelI3("", this), + _labelI4("", this), + _labelI5("", this), + _scrollArea(this), + _drawWindow(&_scrollArea), + _legendWindow(&_drawWindow), + _legendAxisX(&_drawWindow), + _labelXMin("", &_legendAxisX), + _labelXMid("", &_legendAxisX), + _labelXMax("", &_legendAxisX), + _glWindow(&_drawWindow), + _mState(nullptr), + _data(nullptr), + _keyPressed(false)
kernel-shark-qt/src/KsTraceGraph.cpp line 55
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+{ + auto lamMakeNavButton = [&](QPushButton *b) { + b->setMaximumWidth(FONT_WIDTH * 5); + + connect(b, &QPushButton::released, + this, &KsTraceGraph::_stopUpdating); + _navigationBar.addWidget(b); + }; + + _pointerBar.setMaximumHeight(FONT_HEIGHT * 1.75);
Why the 1.75?
kernel-shark-qt/src/KsTraceGraph.cpp line 59
Quoted 4 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +4
-0+ _pointerBar.setOrientation(Qt::Horizontal); + + _navigationBar.setMaximumHeight(FONT_HEIGHT * 1.75); + _navigationBar.setMinimumWidth(FONT_WIDTH * 90);
Why the 90?
kernel-shark-qt/src/KsTraceGraph.cpp line 66
Quoted 7 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +7
-0+ _navigationBar.setOrientation(Qt::Horizontal); + + _pointerBar.addWidget(&_labelP1); + _labelP2.setFrameStyle(QFrame::Panel | QFrame::Sunken); + _labelP2.setStyleSheet("QLabel { background-color : white;}"); + _labelP2.setTextInteractionFlags(Qt::TextSelectableByMouse); + _labelP2.setFixedWidth(FONT_WIDTH * 16);
Why 16?
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ _pointerBar.addWidget(&_labelP2); + _pointerBar.addSeparator(); + + _labelI1.setStyleSheet("QLabel {color : blue;}"); + _labelI2.setStyleSheet("QLabel {color : green;}"); + _labelI3.setStyleSheet("QLabel {color : red;}"); + _labelI4.setStyleSheet("QLabel {color : blue;}"); + _labelI5.setStyleSheet("QLabel {color : green;}"); + + _pointerBar.addWidget(&_labelI1);
kernel-shark-qt/src/KsTraceGraph.cpp line 86
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ _pointerBar.addSeparator(); + _pointerBar.addWidget(&_labelI2); + _pointerBar.addSeparator(); + _pointerBar.addWidget(&_labelI3); + _pointerBar.addSeparator(); + _pointerBar.addWidget(&_labelI4); + _pointerBar.addSeparator(); + _pointerBar.addWidget(&_labelI5); + + _legendAxisX.setFixedHeight(FONT_HEIGHT * 1.5);
1.5?
kernel-shark-qt/src/KsTraceGraph.cpp line 98
Quoted 12 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +12
-0+ _legendAxisX.setLayout(new QHBoxLayout); + _legendAxisX.layout()->setSpacing(0); + _legendAxisX.layout()->setContentsMargins(0, 0, FONT_WIDTH, 0); + + _labelXMin.setAlignment(Qt::AlignLeft); + _labelXMid.setAlignment(Qt::AlignHCenter); + _labelXMax.setAlignment(Qt::AlignRight); + + _legendAxisX.layout()->addWidget(&_labelXMin); + _legendAxisX.layout()->addWidget(&_labelXMid); + _legendAxisX.layout()->addWidget(&_labelXMax); + _drawWindow.setMinimumSize(100, 100);
The 100s should probably be MACROS
Quoted 219 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +219
-0+ _drawWindow.setStyleSheet("QWidget {background-color : white;}"); + + _drawLayout.setContentsMargins(0, 0, 0, 0); + _drawLayout.setSpacing(0); + _drawLayout.addWidget(&_legendAxisX, 0, 1); + _drawLayout.addWidget(&_legendWindow, 1, 0); + _drawLayout.addWidget(&_glWindow, 1, 1); + _drawWindow.setLayout(&_drawLayout); + + _drawWindow.installEventFilter(this); + + connect(&_glWindow, &KsGLWidget::select, + this, &KsTraceGraph::markEntry); + + connect(&_glWindow, &KsGLWidget::found, + this, &KsTraceGraph::_setPointerInfo); + + connect(&_glWindow, &KsGLWidget::notFound, + this, &KsTraceGraph::_resetPointer); + + connect(&_glWindow, &KsGLWidget::zoomIn, + this, &KsTraceGraph::_zoomIn); + + connect(&_glWindow, &KsGLWidget::zoomOut, + this, &KsTraceGraph::_zoomOut); + + connect(&_glWindow, &KsGLWidget::scrollLeft, + this, &KsTraceGraph::_scrollLeft); + + connect(&_glWindow, &KsGLWidget::scrollRight, + this, &KsTraceGraph::_scrollRight); + + connect(&_glWindow, &KsGLWidget::stopUpdating, + this, &KsTraceGraph::_stopUpdating); + + connect(_glWindow.model(), &KsGraphModel::modelReset, + this, &KsTraceGraph::_updateTimeLegends); + + _scrollArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + _scrollArea.setWidget(&_drawWindow); + + lamMakeNavButton(&_scrollLeftButton); + connect(&_scrollLeftButton, &QPushButton::pressed, + this, &KsTraceGraph::_scrollLeft); + + lamMakeNavButton(&_zoomInButton); + connect(&_zoomInButton, &QPushButton::pressed, + this, &KsTraceGraph::_zoomIn); + + lamMakeNavButton(&_zoomOutButton); + connect(&_zoomOutButton, &QPushButton::pressed, + this, &KsTraceGraph::_zoomOut); + + lamMakeNavButton(&_scrollRightButton); + connect(&_scrollRightButton, &QPushButton::pressed, + this, &KsTraceGraph::_scrollRight); + + _navigationBar.addSeparator(); + + lamMakeNavButton(&_quickZoomInButton); + connect(&_quickZoomInButton, &QPushButton::pressed, + this, &KsTraceGraph::_quickZoomIn); + + lamMakeNavButton(&_quickZoomOutButton); + connect(&_quickZoomOutButton, &QPushButton::pressed, + this, &KsTraceGraph::_quickZoomOut); + + _layout.addWidget(&_pointerBar); + _layout.addWidget(&_navigationBar); + _layout.addWidget(&_scrollArea); + this->setLayout(&_layout); + updateGeom(); +} + +/** + * @brief Load and show trace data. + * + * @param data: Input location for the KsDataStore object. + * KsDataStore::loadDataFile() must be called first. + */ +void KsTraceGraph::loadData(KsDataStore *data) +{ + _data = data; + _glWindow.loadData(data); + _updateGraphLegends(); + updateGeom(); +} + +/** Connect the KsGLWidget widget and the State machine of the Dual marker. */ +void KsTraceGraph::setMarkerSM(KsDualMarkerSM *m) +{ + _mState = m; + _navigationBar.addSeparator(); + _mState->placeInToolBar(&_navigationBar); + _glWindow.setMarkerSM(m); +} + +/** Reset (empty) the widget. */ +void KsTraceGraph::reset() +{ + /* Clear the all graph lists and update. */ + _glWindow._cpuList = {}; + _glWindow._taskList = {}; + + _labelP2.setText(""); + for (auto l1: {&_labelI1, &_labelI2, &_labelI3, &_labelI4, &_labelI5}) + l1->setText(""); + + _glWindow.model()->reset(); + _selfUpdate(); + for (auto l2: {&_labelXMin, &_labelXMid, &_labelXMax}) + l2->setText(""); +} + +void KsTraceGraph::_selfUpdate() +{ + _updateGraphLegends(); + _updateTimeLegends(); + _markerReDraw(); + updateGeom(); +} + +void KsTraceGraph::_zoomIn() +{ + _updateGraphs(GraphActions::ZoomIn); +} + +void KsTraceGraph::_zoomOut() +{ + _updateGraphs(GraphActions::ZoomOut); +} + +void KsTraceGraph::_quickZoomIn() +{ + /* Bin size will be 100 ns. */ + _glWindow.model()->quickZoomIn(100); + if (_mState->activeMarker()._isSet && + _mState->activeMarker().isVisible()) { + /* + * Use the position of the active marker as + * a focus point of the zoom. + */ + uint64_t ts = _mState->activeMarker()._ts; + _glWindow.model()->jumpTo(ts); + } +} + +void KsTraceGraph::_quickZoomOut() +{ + _glWindow.model()->quickZoomOut(); +} + +void KsTraceGraph::_scrollLeft() +{ + _updateGraphs(GraphActions::ScrollLeft); +} + +void KsTraceGraph::_scrollRight() +{ + _updateGraphs(GraphActions::ScrollRight); +} + +void KsTraceGraph::_stopUpdating() +{ + /* + * The user is no longer pressing the action button. Reset the + * "Key Pressed" flag. This will stop the ongoing user action. + */ + _keyPressed = false; +} + +void KsTraceGraph::_resetPointer(uint64_t ts, int cpu, int pid) +{ + uint64_t sec, usec; + QString pointer; + + kshark_convert_nano(ts, &sec, &usec); + pointer.sprintf("%lu.%lu", sec, usec); + _labelP2.setText(pointer); + + if (pid > 0 && cpu >= 0) { + struct kshark_context *kshark_ctx(NULL); + + if (!kshark_instance(&kshark_ctx)) + return; + + QString comm(tep_data_comm_from_pid(kshark_ctx->pevent, pid)); + comm.append("-"); + comm.append(QString("%1").arg(pid)); + _labelI1.setText(comm); + _labelI2.setText(QString("CPU %1").arg(cpu)); + } else { + _labelI1.setText(""); + _labelI2.setText(""); + } + + for (auto const &l: {&_labelI3, &_labelI4, &_labelI5}) { + l->setText(""); + } +} + +void KsTraceGraph::_setPointerInfo(size_t i) +{ + kshark_entry *e = _data->rows()[i]; + QString event(kshark_get_event_name_easy(e)); + QString lat(kshark_get_latency_easy(e)); + QString info(kshark_get_info_easy(e)); + QString comm(kshark_get_task_easy(e)); + QString pointer, elidedText; + int labelWidth, width; + uint64_t sec, usec; + + kshark_convert_nano(e->ts, &sec, &usec); + pointer.sprintf("%lu.%lu", sec, usec); + _labelP2.setText(pointer); + + comm.append("-"); + comm.append(QString("%1").arg(kshark_get_pid_easy(e))); +
kernel-shark-qt/src/KsTraceGraph.cpp line 327
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ _labelI1.setText(comm); + _labelI2.setText(QString("CPU %1").arg(e->cpu)); + _labelI3.setText(lat); + _labelI4.setText(event); + _labelI5.setText(info); + QCoreApplication::processEvents(); + + labelWidth = + _pointerBar.geometry().right() - _labelI4.geometry().right(); + if (labelWidth > STRING_WIDTH(info) + FONT_WIDTH * 5)
Why 5?
kernel-shark-qt/src/KsTraceGraph.cpp line 335
Quoted 8 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +8
-0+ return; + + /* + * The Info string is too long and cannot be displayed on the toolbar. + * Try to fit the text in the available space. + */ + QFontMetrics metrix(_labelI5.font()); + width = labelWidth - FONT_WIDTH * 3;
Why 3?
kernel-shark-qt/src/KsTraceGraph.cpp line 339
Quoted 4 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +4
-0+ elidedText = metrix.elidedText(info, Qt::ElideRight, width); + + while(labelWidth < STRING_WIDTH(elidedText) + FONT_WIDTH * 5) { + width -= FONT_WIDTH * 3;
Why 5 and 3?
Quoted 25 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +25
-0+ elidedText = metrix.elidedText(info, Qt::ElideRight, width); + } + + _labelI5.setText(elidedText); + _labelI5.setVisible(true); + QCoreApplication::processEvents(); +} + +/** + * @brief Use the active marker to select particular entry. + * + * @param row: The index of the entry to be selected by the marker. + */ +void KsTraceGraph::markEntry(size_t row) +{ + int graph, cpuGrId, taskGrId; + + _glWindow.findGraphIds(*_data->rows()[row], &cpuGrId, &taskGrId); + + /* + * If a Task graph has been found, this Task graph will be + * visible. If no Task graph has been found, make visible + * the corresponding CPU graph. + */ + if (taskGrId >= 0)
kernel-shark-qt/src/KsTraceGraph.cpp line 374
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ graph = taskGrId; + else + graph = cpuGrId; + + _scrollArea.ensureVisible(0, + _legendAxisX.height() + + _glWindow.vMargin() + + KS_GRAPH_HEIGHT / 2 + + graph*(KS_GRAPH_HEIGHT + _glWindow.vSpacing()), + 50,
Why 50?
Quoted 113 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +113
-0+ KS_GRAPH_HEIGHT / 2 + _glWindow.vSpacing() / 2); + + _glWindow.model()->jumpTo(_data->rows()[row]->ts); + _mState->activeMarker().set(*_data, + _glWindow.model()->histo(), + row, cpuGrId, taskGrId); + + _mState->updateMarkers(*_data, &_glWindow); +} + +void KsTraceGraph::_markerReDraw() +{ + int cpuGrId, taskGrId; + size_t row; + + if (_mState->markerA()._isSet) { + row = _mState->markerA()._pos; + _glWindow.findGraphIds(*_data->rows()[row], &cpuGrId, &taskGrId); + _mState->markerA().set(*_data, + _glWindow.model()->histo(), + row, cpuGrId, taskGrId); + } + + if (_mState->markerB()._isSet) { + row = _mState->markerB()._pos; + _glWindow.findGraphIds(*_data->rows()[row], &cpuGrId, &taskGrId); + _mState->markerB().set(*_data, + _glWindow.model()->histo(), + row, cpuGrId, taskGrId); + } +} + +/** + * @brief Redreaw all CPU graphs. + * + * @param v: CPU ids to be plotted. + */ +void KsTraceGraph::cpuReDraw(QVector<int> v) +{ + _glWindow._cpuList = v; + _selfUpdate(); +} + +/** + * @brief Redreaw all Task graphs. + * + * @param v: Process ids of the tasks to be plotted. + */ +void KsTraceGraph::taskReDraw(QVector<int> v) +{ + _glWindow._taskList = v; + _selfUpdate(); +} + +/** Add (and plot) a CPU graph to the existing list of CPU graphs. */ +void KsTraceGraph::addCPUPlot(int cpu) +{ + if (_glWindow._cpuList.contains(cpu)) + return; + + _glWindow._cpuList.append(cpu); + _selfUpdate(); +} + +/** Add (and plot) a Task graph to the existing list of Task graphs. */ +void KsTraceGraph::addTaskPlot(int pid) +{ + if (_glWindow._taskList.contains(pid)) + return; + + _glWindow._taskList.append(pid); + _selfUpdate(); +} + +/** Update the content of all graphs. */ +void KsTraceGraph::update(KsDataStore *data) +{ + _glWindow.model()->update(data); + _selfUpdate(); +} + +/** Update the geometry of the widget. */ +void KsTraceGraph::updateGeom() +{ + int saWidth, saHeight, dwWidth, hMin; + + /* Set the size of the Scroll Area. */ + saWidth = width() - _layout.contentsMargins().left() - + _layout.contentsMargins().right(); + + saHeight = height() - _pointerBar.height() - + _navigationBar.height() - + _layout.spacing() * 2 - + _layout.contentsMargins().top() - + _layout.contentsMargins().bottom(); + + _scrollArea.resize(saWidth, saHeight); + + /* + * Calculate the width of the Draw Window, taking into account the size + * of the scroll bar. + */ + dwWidth = _scrollArea.width(); + if (_glWindow.height() + _legendAxisX.height() > _scrollArea.height()) + dwWidth -= + qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent); + + /* + * Set the height of the Draw window according to the number of + * plotted graphs. + */ + _drawWindow.resize(dwWidth, + _glWindow.height() + _legendAxisX.height());
kernel-shark-qt/src/KsTraceGraph.cpp line 497
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ + /* Set the minimum height of the Graph widget. */ + hMin = _drawWindow.height() + + _pointerBar.height() + + _navigationBar.height() + + _layout.contentsMargins().top() + + _layout.contentsMargins().bottom(); + + if (hMin > KS_GRAPH_HEIGHT * 8) + hMin = KS_GRAPH_HEIGHT * 8;
Why 8?
(You are probably noticing a theme here ;-)
Quoted 7 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +7
-0+ + setMinimumHeight(hMin); + + /* + * Now use the height of the Draw Window to fix the maximum height + * of the Graph widget. + */
kernel-shark-qt/src/KsTraceGraph.cpp line 514
Quoted 10 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +10
-0+ setMaximumHeight(_drawWindow.height() + + _pointerBar.height() + + _navigationBar.height() + + _layout.spacing() * 2 + + _layout.contentsMargins().top() + + _layout.contentsMargins().bottom() + + 2); /* Just a little bit of extra space. This will + * allow the scroll bar to disappear when the + * widget is extended to maximum. + */
Ug, finish the 2); on the previous line, and keep the comment on its own line.
-- Steve
Quoted 54 lines
kernel-shark-qt/src/KsTraceGraph.cpp new file +54
-0+} + +void KsTraceGraph::_updateGraphLegends() +{ + QString graphLegends, graphName; + QVBoxLayout *layout; + int width = 0; + + if (_legendWindow.layout()) { + /* + * Remove and delete the existing layout of the legend window. + */ + QLayoutItem *child; + while ((child = _legendWindow.layout()->takeAt(0)) != 0) { + delete child->widget(); + delete child; + } + + delete _legendWindow.layout(); + } + + layout = new QVBoxLayout; + layout->setContentsMargins(FONT_WIDTH, 0, 0, 0); + layout->setSpacing(_glWindow.vSpacing()); + layout->setAlignment(Qt::AlignTop); + layout->addSpacing(_glWindow.vMargin()); + + auto lamMakeName = [&]() { + QLabel *name = new QLabel(graphName); + + if (width < STRING_WIDTH(graphName)) + width = STRING_WIDTH(graphName); + + name->setAlignment(Qt::AlignBottom); + name->setStyleSheet("QLabel {background-color : white;}"); + name->setFixedHeight(KS_GRAPH_HEIGHT); + layout->addWidget(name); + }; + + for (auto const &cpu: _glWindow._cpuList) { + graphName = QString("CPU %1").arg(cpu); + lamMakeName(); + } + + for (auto const &pid: _glWindow._taskList) { + graphName = QString(tep_data_comm_from_pid(_data->tep(), + pid)); + graphName.append(QString("-%1").arg(pid)); + lamMakeName(); + } + + _legendWindow.setLayout(layout); + _legendWindow.setMaximumWidth(width + FONT_WIDTH); +}
PATCH v2 8/23 kernel-shark-qt: Add dialog for Advanced filtering.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines a dialog for configuring and using Advanced filtering.
--- kernel-shark-qt/src/CMakeLists.txt | 6 +- kernel-shark-qt/src/KsAdvFilteringDialog.cpp | 440 +++++++++++++++++++ kernel-shark-qt/src/KsAdvFilteringDialog.hpp | 91 ++++ 3 files changed, 535 insertions(+), 2 deletions(-) create mode 100644 kernel-shark-qt/src/KsAdvFilteringDialog.cpp create mode 100644 kernel-shark-qt/src/KsAdvFilteringDialog.hpp
kernel-shark-qt/src/CMakeLists.txt +4 -2
@@ -37,7 +37,8 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsDualMarker.hpp KsWidgetsLib.hpp KsTraceGraph.hpp - KsTraceViewer.hpp) + KsTraceViewer.hpp + KsAdvFilteringDialog.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr})
@@ -47,7 +48,8 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsDualMarker.cpp KsWidgetsLib.cpp KsTraceGraph.cpp - KsTraceViewer.cpp) + KsTraceViewer.cpp + KsAdvFilteringDialog.cpp) target_link_libraries(kshark-gui kshark-plot ${CMAKE_DL_LIBS}
kernel-shark-qt/src/KsAdvFilteringDialog.cpp new file +440 -0
440 lines not on this page · raw message
kernel-shark-qt/src/KsAdvFilteringDialog.hpp new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 9/23 kernel-shark-qt: Add a manager class for GUI sessions.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
The KsSession class provides instruments for importing/exporting the state of the different components of the GUI from/to Json documents. These instruments are used to save/load user session in the GUI.
--- kernel-shark-qt/src/CMakeLists.txt | 1 + kernel-shark-qt/src/KsSession.cpp | 574 +++++++++++++++++++++++++++++ kernel-shark-qt/src/KsSession.hpp | 100 +++++ 3 files changed, 675 insertions(+) create mode 100644 kernel-shark-qt/src/KsSession.cpp create mode 100644 kernel-shark-qt/src/KsSession.hpp
kernel-shark-qt/src/CMakeLists.txt +1 -0
@@ -44,6 +44,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp KsModels.cpp + KsSession.cpp KsGLWidget.cpp KsDualMarker.cpp KsWidgetsLib.cpp
kernel-shark-qt/src/KsSession.cpp new file +574 -0
574 lines not on this page · raw message
kernel-shark-qt/src/KsSession.hpp new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 10/23 kernel-shark-qt: Add Main Window widget for the KernelShark GUI.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
The KsMainWindow class provides the Main window for the KernelShark GUI. It implements the frame used by the two trace data viewing areas (Graphs and Table) together withe the system of menus, used to perform different actions.
--- kernel-shark-qt/CMakeLists.txt | 5 + kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsMainWindow.cpp | 909 +++++++++++++++++++++++++++ kernel-shark-qt/src/KsMainWindow.hpp | 191 ++++++ 4 files changed, 1107 insertions(+) create mode 100644 kernel-shark-qt/src/KsMainWindow.cpp create mode 100644 kernel-shark-qt/src/KsMainWindow.hpp
kernel-shark-qt/CMakeLists.txt +5 -0
@@ -12,6 +12,11 @@ message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n") set(KS_DIR ${CMAKE_SOURCE_DIR}) +# Make a directory to hold configuration files. To change this do: +# cmake .. -DKS_CONF_DIR=/your/preferred/path +set(KS_CONF_DIR "${KS_DIR}/.ksconf" CACHE STRING "Directory for configuration files.") +file(MAKE_DIRECTORY ${KS_CONF_DIR}) + include(${KS_DIR}/build/FindTraceCmd.cmake) include(${KS_DIR}/build/FindJSONC.cmake)
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -38,6 +38,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsWidgetsLib.hpp KsTraceGraph.hpp KsTraceViewer.hpp + KsMainWindow.hpp KsAdvFilteringDialog.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr})
@@ -50,6 +51,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsWidgetsLib.cpp KsTraceGraph.cpp KsTraceViewer.cpp + KsMainWindow.cpp KsAdvFilteringDialog.cpp) target_link_libraries(kshark-gui kshark-plot
kernel-shark-qt/src/KsMainWindow.cpp new file +909 -0
909 lines not on this page · raw message
kernel-shark-qt/src/KsMainWindow.hpp new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 11/23 kernel-shark-qt: Add KernelShark GUI executable.
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch adds the main executable of the KernelShark GUI.
--- kernel-shark-qt/src/CMakeLists.txt | 4 ++ kernel-shark-qt/src/kernelshark.cpp | 93 +++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 kernel-shark-qt/src/kernelshark.cpp
kernel-shark-qt/src/CMakeLists.txt +4 -0
@@ -63,6 +63,10 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) set_target_properties(kshark-gui PROPERTIES SUFFIX ".so.${KS_VERSION_STRING}") + message(STATUS "kernelshark") + add_executable(kernelshark kernelshark.cpp) + target_link_libraries(kernelshark kshark-gui) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)
kernel-shark-qt/src/kernelshark.cpp new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 12/23 kernel-shark-qt: Add "File exists" dialog.
In reply to Yordan KaradzhovA helper function for launching a "File exists" dialog is added to KsWidgetsLib. This function asks the user, before overwriting an existing file. The "File exists" dialog function is used by the KsMainWindow widget when saving the configuration of the filters and sessions.
--- kernel-shark-qt/src/KsMainWindow.cpp | 22 +++++++-------------- kernel-shark-qt/src/KsWidgetsLib.cpp | 29 ++++++++++++++++++++++++++++ kernel-shark-qt/src/KsWidgetsLib.hpp | 7 +++++++ 3 files changed, 43 insertions(+), 15 deletions(-)
kernel-shark-qt/src/KsMainWindow.cpp +7 -15
@@ -397,20 +397,7 @@ void KsMainWindow::_exportSession() if (!fileName.endsWith(".json")) { fileName += ".json"; if (QFileInfo(fileName).exists()) { - QString msg("A file "); - QMessageBox msgBox; - - msg += fileName; - msg += " already exists."; - msgBox.setText(msg); - msgBox.setInformativeText("Do you want to replace it?"); - - msgBox.setStandardButtons(QMessageBox::Save | - QMessageBox::Cancel); - - msgBox.setDefaultButton(QMessageBox::Cancel); - - if (msgBox.exec() == QMessageBox::Cancel) + if (!KsWidgetsLib::fileExistsDialog(fileName)) return; } }
@@ -461,8 +448,13 @@ void KsMainWindow::_exportFilter() if (fileName.isEmpty()) return; - if (!fileName.endsWith(".json")) + if (!fileName.endsWith(".json")) { fileName += ".json"; + if (QFileInfo(fileName).exists()) { + if (!KsWidgetsLib::fileExistsDialog(fileName)) + return; + } + } kshark_export_all_event_filters(kshark_ctx, &conf); kshark_save_config_file(fileName.toStdString().c_str(), conf);
kernel-shark-qt/src/KsWidgetsLib.cpp +29 -0
@@ -76,6 +76,35 @@ KsMessageDialog::KsMessageDialog(QString message, QWidget *parent) this->setLayout(&_layout); } +namespace KsWidgetsLib +{ + +/** + * @brief Launch a File exists dialog. Use this function to ask the user + * before overwriting an existing file. + * + * @param fileName: the name of the file. + * + * @returns True if the user wants to overwrite the file. Otherwise + */ +bool fileExistsDialog(QString fileName) +{ + QString msg("A file "); + QMessageBox msgBox; + + msg += fileName; + msg += " already exists."; + msgBox.setText(msg); + msgBox.setInformativeText("Do you want to replace it?"); + + msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + + return (msgBox.exec() == QMessageBox::Save); +} + +}; // KsWidgetsLib + /** * @brief Create KsCheckBoxWidget. *
kernel-shark-qt/src/KsWidgetsLib.hpp +7 -0
@@ -66,6 +66,13 @@ public: /** The width of the KsMessageDialog widget. */ #define KS_MSG_DIALOG_WIDTH (SCREEN_WIDTH / 10) +namespace KsWidgetsLib +{ + +bool fileExistsDialog(QString fileName); + +}; // KsWidgetsLib + /** * The KsCheckBoxWidget class is the base class of all CheckBox widget used * by KernelShark.
Signature · 1 line
2.17.1
PATCH v2 13/23 kernel-shark-qt: Fix the glitches in the preemption time visualization
In reply to Yordan KaradzhovThis problem was reported by Steven Rostedt. The reason for having the problem was my wrong assumption that for a given task the sched_switch event is always the last record before the task is preempted.
The patch changes two things:
It modifies the "match" functions used to search for sched events, making these functions to trigger only on sched_switch/_wakeup events. This eliminates the flakiness due to the fact that sometimes the sched_switch can happend to be in the same bin with some of the trailing events from the same task. This also has the side effect of simplifying the code.
It introduces a second pass over the data, which is task-specific and gets executed only the first time the task is plotted. This second pass edits the "pid" field of the last trailing event making it equal to the "next pid" field of the sched_switch event.
--- kernel-shark-qt/src/plugins/SchedEvents.cpp | 126 ++++++++++++++------ kernel-shark-qt/src/plugins/sched_events.c | 13 +- 2 files changed, 94 insertions(+), 45 deletions(-)
kernel-shark-qt/src/plugins/SchedEvents.cpp +91 -35
@@ -16,6 +16,7 @@ // C++ 11 #include<functional> +#include<unordered_set> // KernelShark #include "libkshark.h"
@@ -29,25 +30,12 @@ #define PLUGIN_MAX_ENTRIES_PER_BIN 500 +#define KS_TASK_COLLECTION_MARGIN 25 + //! @endcond extern struct plugin_sched_context *plugin_sched_context_handler; -static int plugin_get_wakeup_pid(kshark_context *kshark_ctx, - plugin_sched_context *plugin_ctx, - const struct kshark_entry *e) -{ - struct tep_record *record; - unsigned long long val; - - record = kshark_read_at(kshark_ctx, e->offset); - tep_read_number_field(plugin_ctx->sched_wakeup_pid_field, - record->data, &val); - free_record(record); - - return val; -} - /** Sched Event identifier. */ enum class SchedEvent { /** Sched Switch Event. */
@@ -139,23 +127,16 @@ static void pluginDraw(plugin_sched_context *plugin_ctx, ksmodel_get_entry_back(histo, bin, false, plugin_wakeup_match_pid, pid, col, nullptr); - int wakeup_pid; - - if (entryB && - plugin_ctx->sched_wakeup_event && - entryB->event_id == plugin_ctx->sched_wakeup_event->id) { - wakeup_pid = - plugin_get_wakeup_pid(kshark_ctx, plugin_ctx, entryB); - if (wakeup_pid == pid) { - /* - * entryB is a sched_wakeup_event. Open a - * green box here. - */ - openBox(graph->getBin(bin)._base); - /* Green */ - rec->_color = KsPlot::Color(0, 255, 0); - } + if (entryB) { + /* + * entryB is a sched_wakeup_event. Open a + * green box here. + */ + openBox(graph->getBin(bin)._base); + + /* Green */ + rec->_color = KsPlot::Color(0, 255, 0); } };
@@ -171,10 +152,7 @@ static void pluginDraw(plugin_sched_context *plugin_ctx, plugin_switch_match_pid, pid, col, nullptr); - if (entryB && - entryB->pid != pid && - plugin_ctx->sched_switch_event && - entryB->event_id == plugin_ctx->sched_switch_event->id) { + if (entryB && entryB->pid != pid) { /* * entryB is a sched_switch_event. Open a * red box here.
@@ -215,6 +193,67 @@ static void pluginDraw(plugin_sched_context *plugin_ctx, return; } +static std::unordered_set<int> secondPassDone; + +/* + * Ideally, the sched_switch has to be the last trace event recorded before the + * task is preempted. Because of this, when the data is loaded (the first pass), + * the "pid" field of the sched_switch entries gets edited by this plugin to be + * equal to the "next pid" of the sched_switch event. However, in reality the + * sched_switch event may be followed by some trailing events from the same task + * (printk events for example). This has the effect of extending the graph of + * the task outside of the actual duration of the task. The "second pass" over + * the data is used to fix this problem. It takes advantage of the "next" field + * of the entry (this field is set during the first pass) to search for trailing + * events after the "sched_switch". + */ +static void secondPass(kshark_entry **data, + kshark_entry_collection *col, + int pid) +{ + const kshark_entry *e; + kshark_entry *last; + int first, n; + ssize_t index; + + /* Loop over the intervals of the data collection. */ + for (size_t i = 0; i < col->size; ++i) { + first = col->break_points[i]; + n = first - col->resume_points[i]; + + kshark_entry_request *req = + kshark_entry_request_alloc(first, n, + plugin_switch_match_pid, pid, + false, + KS_GRAPH_VIEW_FILTER_MASK); + + e = kshark_get_entry_back(req, data, &index); + free(req); + + if (!e || index < 0) { + /* No sched_switch event in this interval. */ + continue; + } + + /* Find the very last trailing event. */ + for (last = data[index]; last->next; last = last->next) { + if (last->next->pid != pid) { + /* + * This is the last trailing event. Change the + * "pid" to be equal to the "next pid" of the + * sched_switch event and leave a sign that you + * edited this entry. + */ + last->pid = data[index]->pid; + last->visible &= ~KS_PLUGIN_UNTOUCHED_MASK; + break; + } + } + } + + secondPassDone.insert(pid); +} + /** * @brief Plugin's draw function. *
@@ -246,8 +285,25 @@ void plugin_draw(kshark_cpp_argv *argv_c, int pid, int draw_action) */ col = kshark_find_data_collection(kshark_ctx->collections, kshark_match_pid, pid); + if (!col) { + /* + * If a data collection for this task does not exist, + * register a new one. + */ + kshark_entry **data = argvCpp->_histo->data; + int size = argvCpp->_histo->data_size; + col = kshark_register_data_collection(kshark_ctx, + data, size, + kshark_match_pid, pid, + KS_TASK_COLLECTION_MARGIN); + } try { + if (secondPassDone.find(pid) == secondPassDone.end()) { + /* The second pass for this task is not done yet. */ + secondPass(argvCpp->_histo->data, col, pid); + } + pluginDraw(plugin_ctx, kshark_ctx, argvCpp->_histo, col, SchedEvent::Switch, pid,
kernel-shark-qt/src/plugins/sched_events.c +3 -10
@@ -167,9 +167,6 @@ bool plugin_wakeup_match_pid(struct kshark_context *kshark_ctx,unsigned long long val;int wakeup_pid =-1 ; -if (e->pid == pid) -return true; - plugin_ctx = plugin_sched_context_handler;if (!plugin_ctx)return false;
@@ -221,23 +218,19 @@ bool plugin_switch_match_pid(struct kshark_context *kshark_ctx, int pid) {struct plugin_sched_context *plugin_ctx; -struct tep_record *record =NULL ;int switch_pid =-1 ; -if (e->pid == pid) -return true; - plugin_ctx = plugin_sched_context_handler;if (plugin_ctx->sched_switch_event && e->event_id == plugin_ctx->sched_switch_event->id) { - record =kshark_read_at (kshark_ctx, e->offset); +struct tep_record *record; + record =kshark_read_at (kshark_ctx, e->offset); switch_pid =tep_data_pid (plugin_ctx->pevent, record); +free_record (record); } -free_record (record); -if (switch_pid >=0 && switch_pid == pid)return true;
Signature · 1 line
2.17.1
PATCH v2 14/23 kernel-shark-qt: Add dialog for of trace data recording
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
This patch defines a dialog to be used for trace data recording. The dialog has two main areas: a Control panel and a terminal-like widget for monitoring the recording process.
--- kernel-shark-qt/src/CMakeLists.txt | 2 + kernel-shark-qt/src/KsCaptureDialog.cpp | 562 ++++++++++++++++++++++++ kernel-shark-qt/src/KsCaptureDialog.hpp | 185 ++++++++ 3 files changed, 749 insertions(+) create mode 100644 kernel-shark-qt/src/KsCaptureDialog.cpp create mode 100644 kernel-shark-qt/src/KsCaptureDialog.hpp
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -39,6 +39,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsTraceGraph.hpp KsTraceViewer.hpp KsMainWindow.hpp + KsCaptureDialog.hpp KsAdvFilteringDialog.hpp) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr})
@@ -52,6 +53,7 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) KsTraceGraph.cpp KsTraceViewer.cpp KsMainWindow.cpp + KsCaptureDialog.cpp KsAdvFilteringDialog.cpp) target_link_libraries(kshark-gui kshark-plot
kernel-shark-qt/src/KsCaptureDialog.cpp new file +562 -0
562 lines not on this page · raw message
kernel-shark-qt/src/KsCaptureDialog.hpp new file +185 -0
185 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 15/23 kernel-shark-qt: Add kshark-record executable
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
kshark-record provides a simple GUI (dialog) used to generate command line arguments for trace-cmd and to record trace data.
--- kernel-shark-qt/src/CMakeLists.txt | 4 ++++ kernel-shark-qt/src/kshark-record.cpp | 29 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 kernel-shark-qt/src/kshark-record.cpp
kernel-shark-qt/src/CMakeLists.txt +4 -0
@@ -69,6 +69,10 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_executable(kernelshark kernelshark.cpp) target_link_libraries(kernelshark kshark-gui) + message(STATUS "kshark-record") + add_executable(kshark-record kshark-record.cpp) + target_link_libraries(kshark-record kshark-gui) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)
kernel-shark-qt/src/kshark-record.cpp new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (C) 2018 VMware Inc, Yordan Karadzhov <[email protected]> + */ + +// C +#include <unistd.h> + +// KernelShark +#include "KsCaptureDialog.hpp" + +int main(int argc, char **argv) +{ + QApplication a(argc, argv); + KsCaptureDialog cd; + + int c; + while ((c = getopt(argc, argv, "o:")) != -1) { + switch(c) { + case 'o': + cd.setOutputFileName(QString(optarg)); + break; + } + } + + cd.show(); + return a.exec(); +}
Signature · 1 line
2.17.1
PATCH v2 16/23 kernel-shark-qt: Instruct CMake to search for "pkexec"
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
CMake will search for "pkexec" and if it is found will add a line
to the CMake-generated header file.
--- kernel-shark-qt/build/deff.h.cmake | 3 +++ kernel-shark-qt/src/CMakeLists.txt | 2 ++ 2 files changed, 5 insertions(+)
kernel-shark-qt/build/deff.h.cmake +3 -0
@@ -20,6 +20,9 @@ /** Location of the trace-cmd executable. */ #cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@" +/** "pkexec" executable. */ +#cmakedefine DO_AS_ROOT "@DO_AS_ROOT@" + #ifdef __cplusplus #include <QString>
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -77,5 +77,7 @@ endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins) +find_program(DO_AS_ROOT pkexec) + configure_file( ${KS_DIR}/build/deff.h.cmake ${KS_DIR}/src/KsCmakeDef.hpp)
Signature · 1 line
2.17.1
PATCH v2 17/23 kernel-shark-qt: Add PolicyKit Configuration for kshark-record
In reply to Yordan KaradzhovThe PolicyKit Policy Configuration will allow the kshark-record executable to be started as Root via pkexec.
--- .../org.freedesktop.kshark-record.policy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 kernel-shark-qt/org.freedesktop.kshark-record.policy
kernel-shark-qt/org.freedesktop.kshark-record.policy new file +18 -0
@@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE policyconfig PUBLIC + "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" + "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> +<policyconfig> + + <action id="org.freedesktop.pkexec.kshark-record"> + <message gettext-domain="gparted">Authentication is required to run KernelShark Record</message> + <defaults> + <allow_any>auth_admin</allow_any> + <allow_inactive>auth_admin</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + <annotate key="org.freedesktop.policykit.exec.path">/usr/local/bin/kshark-record</annotate> + <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate> + </action> + +</policyconfig>
Signature · 1 line
2.17.1
PATCH v2 19/23 kernel-shark-qt: Add kernelshark.desktop file
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
Instruct CMake to generate kernelshark.desktop. This file is used to add the KernelShark application in the desktop menus.
--- kernel-shark-qt/CMakeLists.txt | 3 +++ kernel-shark-qt/build/cmake_clean.sh | 1 + kernel-shark-qt/build/ks.desktop.cmake | 9 +++++++++ 3 files changed, 13 insertions(+) create mode 100644 kernel-shark-qt/build/ks.desktop.cmake
kernel-shark-qt/CMakeLists.txt +3 -0
@@ -75,4 +75,7 @@ if (_DOXYGEN_DOC AND DOXYGEN_FOUND) endif () +configure_file( ${KS_DIR}/build/ks.desktop.cmake + ${KS_DIR}/kernelshark.desktop) + message("")
kernel-shark-qt/build/cmake_clean.sh +1 -0
@@ -6,6 +6,7 @@ rm -rf CMakeFiles/ rm -rf src/ rm -rf examples/ rm -f ../lib/* +rm ../kernelshark.desktop rm -f ../src/KsCmakeDef.hpp rm -f CMakeDoxyfile.in rm -f CMakeDoxygenDefaults.cmake
kernel-shark-qt/build/ks.desktop.cmake new file +9 -0
@@ -0,0 +1,9 @@ +[Desktop Entry] +Version=@KS_VERSION_STRING@ +Type=Application +Name=Kernel Shark +GenericName=Kernel Shark +Comment= +Exec=/usr/local/bin/kernelshark +Icon=@KS_DIR@/icons/ksharkicon.png +Terminal=false
Signature · 1 line
2.17.1
PATCH v2 20/23 kernel-shark-qt: Add make install
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
Define CMake installation rules for kernel-shark-qt project. Add a script for uninstalling.
--- kernel-shark-qt/CMakeLists.txt | 3 +++ kernel-shark-qt/build/cmake_uninstall.sh | 17 +++++++++++++++++ kernel-shark-qt/src/CMakeLists.txt | 10 ++++++++++ kernel-shark-qt/src/plugins/CMakeLists.txt | 3 +++ 4 files changed, 33 insertions(+) create mode 100755 kernel-shark-qt/build/cmake_uninstall.sh
kernel-shark-qt/CMakeLists.txt +3 -0
@@ -46,6 +46,9 @@ if (NOT _DEBUG) endif (NOT _DEBUG) +SET(CMAKE_INSTALL_RPATH "/usr/local/lib/kshark/") +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + include_directories(${KS_DIR}/src/ ${KS_DIR}/build/src/ ${JSONC_INCLUDE_DIR}
kernel-shark-qt/build/cmake_uninstall.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/bash + +CYAN='\033[0;36m' +PURPLE='\033[0;35m' +NC='\033[0m' # No Color + +if [[ $EUID -ne 0 ]]; then + echo -e "${PURPLE}Permission denied${NC}" 1>&2 + exit 100 +fi + +if [ -e install_manifest.txt ] +then + echo -e "${CYAN}Uninstall the project...${NC}" + xargs rm -v < install_manifest.txt + rm -f install_manifest.txt +fi
kernel-shark-qt/src/CMakeLists.txt +10 -0
@@ -73,6 +73,16 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_executable(kshark-record kshark-record.cpp) target_link_libraries(kshark-record kshark-gui) + install(TARGETS kernelshark kshark-record kshark kshark-plot kshark-gui + RUNTIME DESTINATION /usr/local/bin/ + LIBRARY DESTINATION /usr/local/lib/kshark/) + + install(FILES "${KS_DIR}/kernelshark.desktop" + DESTINATION /usr/share/applications/) + + install(FILES "${KS_DIR}/org.freedesktop.kshark-record.policy" + DESTINATION /usr/share/polkit-1/actions/) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)
kernel-shark-qt/src/plugins/CMakeLists.txt +3 -0
@@ -24,4 +24,7 @@ BUILD_PLUGIN(NAME sched_events list(APPEND PLUGIN_LIST "sched_events default") # This plugin will be loaded by default # list(APPEND PLUGIN_LIST "sched_events") # This plugin isn't loaded by default +install(TARGETS sched_events + LIBRARY DESTINATION /usr/local/lib/kshark/) + set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
Signature · 1 line
2.17.1
Re: [PATCH v2 20/23] kernel-shark-qt: Add make install
kernel-shark-qt/build/cmake_uninstall.sh line 5
Quoted 11 lines · On Tue, 16 Oct 2018 15:53:21 +0000 Yordan Karadzhov <[email protected]>…
kernel-shark-qt/build/cmake_uninstall.sh new file +5
-0@@ -0,0 +1,17 @@ +#!/bin/bash + +CYAN='\033[0;36m' +PURPLE='\033[0;35m' +NC='\033[0m' # No Color
BTW, this also works:
CYAN='\e[36m'
PURPLE='\e[35m'
NC='\e[0m' # No Color
Which is a little cleaner.
If you agree, can you resend just this patch with the update (as v2)?
Thanks!
-- Steve
Quoted 45 lines
kernel-shark-qt/build/cmake_uninstall.sh new file +12
-0+ +if [[ $EUID -ne 0 ]]; then + echo -e "${PURPLE}Permission denied${NC}" 1>&2 + exit 100 +fi + +if [ -e install_manifest.txt ] +then + echo -e "${CYAN}Uninstall the project...${NC}" + xargs rm -v < install_manifest.txt + rm -f install_manifest.txt +fikernel-shark-qt/src/CMakeLists.txt +10
-0@@ -73,6 +73,16 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_executable(kshark-record kshark-record.cpp) target_link_libraries(kshark-record kshark-gui) + install(TARGETS kernelshark kshark-record kshark kshark-plot kshark-gui + RUNTIME DESTINATION /usr/local/bin/ + LIBRARY DESTINATION /usr/local/lib/kshark/) + + install(FILES "${KS_DIR}/kernelshark.desktop" + DESTINATION /usr/share/applications/) + + install(FILES "${KS_DIR}/org.freedesktop.kshark-record.policy" + DESTINATION /usr/share/polkit-1/actions/) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)kernel-shark-qt/src/plugins/CMakeLists.txt +3
-0@@ -24,4 +24,7 @@ BUILD_PLUGIN(NAME sched_events list(APPEND PLUGIN_LIST "sched_events default") # This plugin will be loaded by default # list(APPEND PLUGIN_LIST "sched_events") # This plugin isn't loaded by default +install(TARGETS sched_events + LIBRARY DESTINATION /usr/local/lib/kshark/) + set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
PATCH v3 1/1 kernel-shark-qt: Add make install
From: Yordan Karadzhov (VMware) <[email protected]>
Define CMake installation rules for kernel-shark-qt project. Add a script for uninstalling.
--- kernel-shark-qt/CMakeLists.txt | 3 +++ kernel-shark-qt/build/cmake_uninstall.sh | 17 +++++++++++++++++ kernel-shark-qt/src/CMakeLists.txt | 10 ++++++++++ kernel-shark-qt/src/plugins/CMakeLists.txt | 3 +++ 4 files changed, 33 insertions(+) create mode 100755 kernel-shark-qt/build/cmake_uninstall.sh
kernel-shark-qt/CMakeLists.txt +3 -0
@@ -46,6 +46,9 @@ if (NOT _DEBUG) endif (NOT _DEBUG) +SET(CMAKE_INSTALL_RPATH "/usr/local/lib/kshark/") +SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + include_directories(${KS_DIR}/src/ ${KS_DIR}/build/src/ ${JSONC_INCLUDE_DIR}
kernel-shark-qt/build/cmake_uninstall.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/bash + +CYAN='\e[36m' +PURPLE='\e[35m' +NC='\e[0m' # No Color + +if [[ $EUID -ne 0 ]]; then + echo -e "${PURPLE}Permission denied${NC}" 1>&2 + exit 100 +fi + +if [ -e install_manifest.txt ] +then + echo -e "${CYAN}Uninstall the project...${NC}" + xargs rm -v < install_manifest.txt + rm -f install_manifest.txt +fi
kernel-shark-qt/src/CMakeLists.txt +10 -0
@@ -73,6 +73,16 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_executable(kshark-record kshark-record.cpp) target_link_libraries(kshark-record kshark-gui) + install(TARGETS kernelshark kshark-record kshark kshark-plot kshark-gui + RUNTIME DESTINATION /usr/local/bin/ + LIBRARY DESTINATION /usr/local/lib/kshark/) + + install(FILES "${KS_DIR}/kernelshark.desktop" + DESTINATION /usr/share/applications/) + + install(FILES "${KS_DIR}/org.freedesktop.kshark-record.policy" + DESTINATION /usr/share/polkit-1/actions/) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)
kernel-shark-qt/src/plugins/CMakeLists.txt +3 -0
@@ -24,4 +24,7 @@ BUILD_PLUGIN(NAME sched_events list(APPEND PLUGIN_LIST "sched_events default") # This plugin will be loaded by default # list(APPEND PLUGIN_LIST "sched_events") # This plugin isn't loaded by default +install(TARGETS sched_events + LIBRARY DESTINATION /usr/local/lib/kshark/) + set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
Signature · 1 line
2.17.1
PATCH v2 21/23 kernel-shark-qt: Add Record dialog to KS GUI.
In reply to Yordan KaradzhovA Record dialog is added to the Tools menu of the KernelShark GUI. The Record dialog can be used only after installing the project (sudo make install).
--- kernel-shark-qt/src/KsMainWindow.cpp | 128 +++++++++++++++++++++++++++ kernel-shark-qt/src/KsMainWindow.hpp | 22 +++++ 2 files changed, 150 insertions(+)
kernel-shark-qt/src/KsMainWindow.cpp +128 -0
@@ -28,6 +28,7 @@ #include "libkshark.h" #include "KsCmakeDef.hpp" #include "KsMainWindow.hpp" +#include "KsCaptureDialog.hpp" #include "KsAdvFilteringDialog.hpp" /** Create KernelShark Main window. */
@@ -39,6 +40,8 @@ KsMainWindow::KsMainWindow(QWidget *parent) _graph(this), _mState(this), _plugins(this), + _capture(this), + _captureLocalServer(this), _openAction("Open", this), _restorSessionAction("Restor Last Session", this), _importSessionAction("Import Session", this),
@@ -56,6 +59,7 @@ KsMainWindow::KsMainWindow(QWidget *parent) _cpuSelectAction("CPUs", this), _taskSelectAction("Tasks", this), _pluginsAction("Plugins", this), + _captureAction("Record", this), _colorAction(this), _colSlider(this), _colorPhaseSlider(Qt::Horizontal, this),
@@ -67,6 +71,7 @@ KsMainWindow::KsMainWindow(QWidget *parent) setWindowTitle("Kernel Shark"); _createActions(); _createMenus(); + _initCapture(); _splitter.addWidget(&_graph); _splitter.addWidget(&_view);
@@ -215,6 +220,13 @@ void KsMainWindow::_createActions() connect(&_pluginsAction, &QAction::triggered, this, &KsMainWindow::_pluginSelect); + _captureAction.setIcon(QIcon::fromTheme("media-record")); + _captureAction.setShortcut(tr("Ctrl+R")); + _captureAction.setStatusTip("Capture trace data"); + + connect(&_captureAction, &QAction::triggered, + this, &KsMainWindow::_record); + _colorPhaseSlider.setMinimum(20); _colorPhaseSlider.setMaximum(180); _colorPhaseSlider.setValue(KsPlot::Color::getRainbowFrequency() * 100);
@@ -321,6 +333,7 @@ void KsMainWindow::_createMenus() /* Tools menu */ tools = menuBar()->addMenu("Tools"); tools->addAction(&_pluginsAction); + tools->addAction(&_captureAction); tools->addSeparator(); tools->addAction(&_colorAction); tools->addAction(&_fullScreenModeAction);
@@ -690,6 +703,29 @@ void KsMainWindow::_pluginSelect() dialog->show(); } +void KsMainWindow::_record() +{ +#ifndef DO_AS_ROOT + + QErrorMessage *em = new QErrorMessage(this); + QString message; + + message = "Record is currently not supported."; + message += " Install \"pkexec\" and then do:<br>"; + message += " cd build <br> sudo ./cmake_uninstall.sh <br>"; + message += " ./cmake_clean.sh <br> cmake .. <br> make <br>"; + message += " sudo make install"; + + em->showMessage(message); + qCritical() << "ERROR: " << message; + + return; + +#endif + + _capture.start(); +} + void KsMainWindow::_setColorPhase(int f) { KsPlot::Color::setRainbowFrequency(f / 100.);
@@ -895,6 +931,98 @@ void KsMainWindow::loadSession(const QString &fileName) _colorPhaseSlider.setValue(_session.getColorScheme() * 100); } +void KsMainWindow::_initCapture() +{ +#ifdef DO_AS_ROOT + + _capture.setProgram("kshark-su-record"); + + connect(&_capture, &QProcess::started, + this, &KsMainWindow::_captureStarted); + + /* + * Using the old Signal-Slot syntax because QProcess::finished has + * overloads. + */ + connect(&_capture, SIGNAL(finished(int, QProcess::ExitStatus)), + this, SLOT(_captureFinished(int, QProcess::ExitStatus))); + + connect(&_capture, &QProcess::errorOccurred, + this, &KsMainWindow::_captureError); + + connect(&_captureLocalServer, &QLocalServer::newConnection, + this, &KsMainWindow::_readSocket); + +#endif +} + +void KsMainWindow::_captureStarted() +{ + _captureLocalServer.listen("KSCapture"); +} + +void KsMainWindow::_captureFinished(int exit, QProcess::ExitStatus st) +{ + QProcess *capture = (QProcess *)sender(); + + _captureLocalServer.close(); + + if (exit != 0 || st != QProcess::NormalExit) { + QString message = "Capture process failed:<br>"; + + message += capture->errorString(); + message += "<br>Try doing:<br> sudo make install"; + + _error(message, "captureFinishedErr", false, false); + } +} + +void KsMainWindow::_captureError(QProcess::ProcessError error) +{ + QProcess *capture = (QProcess *)sender(); + QString message = "Capture process failed:<br>"; + + message += capture->errorString(); + message += "<br>Try doing:<br> sudo make install"; + + _error(message, "captureFinishedErr", false, false); +} + +void KsMainWindow::_readSocket() +{ + QLocalSocket *socket; + quint32 blockSize; + QString fileName; + + auto lamSocketError = [&](QString message) + { + message = "ERROR from Local Server: " + message; + _error(message, "readSocketErr", false, false); + }; + + socket = _captureLocalServer.nextPendingConnection(); + if (!socket) { + lamSocketError("Pending connectio not found!"); + return; + } + + QDataStream in(socket); + socket->waitForReadyRead(); + if (socket->bytesAvailable() < (int)sizeof(quint32)) { + lamSocketError("Message size is corrupted!"); + return; + }; + + in >> blockSize; + if (socket->bytesAvailable() < blockSize || in.atEnd()) { + lamSocketError("Message is corrupted!"); + return; + } + + in >> fileName; + loadDataFile(fileName); +} + void KsMainWindow::_splitterMoved(int pos, int index) { _session.saveSplitterSize(_splitter);
kernel-shark-qt/src/KsMainWindow.hpp +22 -0
@@ -14,6 +14,7 @@ // Qt #include <QMainWindow> +#include <QLocalServer> // KernelShark #include "KsTraceViewer.hpp"
@@ -81,6 +82,12 @@ private: /** Plugin manager. */ KsPluginManager _plugins; + /** The process used to record trace data. */ + QProcess _capture; + + /** Local Server used for comunucation with the Capture process. */ + QLocalServer _captureLocalServer; + // File menu. QAction _openAction;
@@ -119,6 +126,8 @@ private: // Tools menu. QAction _pluginsAction; + QAction _captureAction; + QWidgetAction _colorAction; QWidget _colSlider;
@@ -166,6 +175,8 @@ private: void _pluginSelect(); + void _record(); + void _setColorPhase(int); void _fullScreenMode();
@@ -174,18 +185,29 @@ private: void _contents(); + void _captureStarted(); + + void _captureError(QProcess::ProcessError error); + + void _readSocket(); + void _splitterMoved(int pos, int index); void _createActions(); void _createMenus(); + void _initCapture(); + void _updateSession(); inline void _resizeEmpty() {resize(SCREEN_WIDTH * .5, FONT_HEIGHT * 3);} void _error(const QString &text, const QString &errCode, bool resize, bool unloadPlugins); + +private slots: + void _captureFinished(int, QProcess::ExitStatus); }; #endif // _KS_MAINWINDOW_H
Signature · 1 line
2.17.1
PATCH v2 22/23 kernel-shark-qt: Workaround for running as Root on Wayland
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
The Record dialog requires Root privileges in order to be able to collect tracing data. However graphical applications cannot be run as root on Wayland. The problem is worked around by wrapping the kshark-record executable in a shell script which checks the XDG_SESSION_TYPE and in the case of Wayland, allows the root user to access the running X server.
--- kernel-shark-qt/bin/kshark-su-record | 8 ++++++++ kernel-shark-qt/src/CMakeLists.txt | 3 +++ 2 files changed, 11 insertions(+) create mode 100755 kernel-shark-qt/bin/kshark-su-record
kernel-shark-qt/bin/kshark-su-record new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/bash + +if [ $XDG_SESSION_TYPE = "wayland" ] +then + xhost +si:localuser:root &>/dev/null +fi + +pkexec kshark-record -o ${PWD}/trace.dat
kernel-shark-qt/src/CMakeLists.txt +3 -0
@@ -83,6 +83,9 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) install(FILES "${KS_DIR}/org.freedesktop.kshark-record.policy" DESTINATION /usr/share/polkit-1/actions/) + install(PROGRAMS "${KS_DIR}/bin/kshark-su-record" + DESTINATION /usr/local/bin/) + endif (Qt5Widgets_FOUND AND Qt5Network_FOUND) add_subdirectory(plugins)
Signature · 1 line
2.17.1
PATCH v2 23/23 kernel-shark-qt: Version 0.9.0
In reply to Yordan KaradzhovFrom: Yordan Karadzhov (VMware) <[email protected]>
--- kernel-shark-qt/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark-qt/CMakeLists.txt +2 -2
@@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR) project(kernel-shark-qt) set(KS_VERSION_MAJOR 0) -set(KS_VERSION_MINOR 7) -set(KS_VERSION_PATCH 1) +set(KS_VERSION_MINOR 9) +set(KS_VERSION_PATCH 0) set(KS_VERSION_STRING ${KS_VERSION_MAJOR}.${KS_VERSION_MINOR}.${KS_VERSION_PATCH}) message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n")
Signature · 1 line
2.17.1