The compilation of KsModels.cpp and KsSearchFSM.cpp is re-enabled and all functionalities are made compatible with the new version of the C API of libkshark (KernelShark 2.0). The two source files are updated in a single patch because of their interdependence. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- src/CMakeLists.txt | 12 ++--- src/KsModels.cpp | 112 +++++++++++++++++++++++++++++++++++++------- src/KsModels.hpp | 28 +++++++---- src/KsSearchFSM.cpp | 12 ++++- 4 files changed, 132 insertions(+), 32 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c9fe17..21d5b85 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,10 +66,10 @@ endif (OPENGL_FOUND) if (Qt5Widgets_FOUND AND Qt5Network_FOUND) message(STATUS "libkshark-gui") - set (ks-guiLib_hdr KsUtils.hpp) -# KsModels.hpp + set (ks-guiLib_hdr KsUtils.hpp + KsModels.hpp # KsGLWidget.hpp -# KsSearchFSM.hpp + KsSearchFSM.hpp) # KsDualMarker.hpp # KsWidgetsLib.hpp # KsTraceGraph.hpp @@ -81,11 +81,11 @@ if (Qt5Widgets_FOUND AND Qt5Network_FOUND) QT5_WRAP_CPP(ks-guiLib_hdr_moc ${ks-guiLib_hdr}) - add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp) -# KsModels.cpp + add_library(kshark-gui SHARED ${ks-guiLib_hdr_moc} KsUtils.cpp + KsModels.cpp # KsSession.cpp # KsGLWidget.cpp -# KsSearchFSM.cpp + KsSearchFSM.cpp) # KsDualMarker.cpp # KsWidgetsLib.cpp # KsTraceGraph.cpp diff --git a/src/KsModels.cpp b/src/KsModels.cpp index 51a7b79..df8373e 100644 --- a/src/KsModels.cpp +++ b/src/KsModels.cpp @@ -227,16 +227,54 @@ QList<int> KsFilterProxyModel::searchThread(int column, return matchList; } +int KsFilterProxyModel::mapRowFromSource(int r) const +{ + /* + * This works because the row number is shown in column + * TRACE_VIEW_COL_INDEX (or TRACE_VIEW_COL_INDEX - 1 in the case when + * the Stream Id column is hidden). + */ + int column = KsViewModel::TRACE_VIEW_COL_INDEX; + + if(_source->singleStream()) + column--; + + return this->data(this->index(r, column)).toInt(); +} + /** Create default (empty) KsViewModel object. */ KsViewModel::KsViewModel(QObject *parent) : QAbstractTableModel(parent), _data(nullptr), _nRows(0), - _header({"#", "CPU", "Time Stamp", "Task", "PID", - "Latency", "Event", "Info"}), _markA(KS_NO_ROW_SELECTED), - _markB(KS_NO_ROW_SELECTED) -{} + _markB(KS_NO_ROW_SELECTED), + _singleStream(true) +{ + _updateHeader(); +} + +/** Update the list of table headers. */ +void KsViewModel::_updateHeader() +{ + beginRemoveColumns(QModelIndex(), 0, _header.count()); + endRemoveColumns(); + + _header.clear(); + + if (KsUtils::getNStreams() > 1) { + _header << " >> "; + _singleStream = false; + } else { + _singleStream = true; + } + + _header << "#" << "CPU" << "Time Stamp" << "Task" << "PID" + << "Latency" << "Event" << "Info"; + + beginInsertColumns(QModelIndex(), 0, _header.count() - 1); + endInsertColumns(); +} /** * Get the data stored under the given role for the item referred to by @@ -246,10 +284,10 @@ KsViewModel::KsViewModel(QObject *parent) QVariant KsViewModel::data(const QModelIndex &index, int role) const { if (role == Qt::ForegroundRole) { - if (index.row() == _markA) + if (index.row() == _markA && index.column() != 0) return QVariant::fromValue(QColor(Qt::white)); - if (index.row() == _markB) + if (index.row() == _markB && index.column() != 0) return QVariant::fromValue(QColor(Qt::white)); } @@ -259,6 +297,15 @@ QVariant KsViewModel::data(const QModelIndex &index, int role) const if (index.row() == _markB) return QVariant::fromValue(QColor(_colorMarkB)); + + if (index.column() == TRACE_VIEW_COL_STREAM && + !_singleStream) { + int sd = _data[index.row()]->stream_id; + QColor col; + col << KsPlot::getColor(&_streamColors, sd); + + return QVariant::fromValue(col); + } } if (role == Qt::DisplayRole) @@ -270,9 +317,26 @@ QVariant KsViewModel::data(const QModelIndex &index, int role) const /** Get the string data stored in a given cell of the table. */ QString KsViewModel::getValueStr(int column, int row) const { + char *buffer; int pid; + /* + * If only one Data stream (file) is loaded, the first column + * (TRACE_VIEW_COL_STREAM) is not shown. + */ + if(_singleStream) + column++; + + auto lanMakeString = [&buffer] () { + QString str(buffer); + free(buffer); + return str; + }; + switch (column) { + case TRACE_VIEW_COL_STREAM : + return QString("%1").arg(_data[row]->stream_id); + case TRACE_VIEW_COL_INDEX : return QString("%1").arg(row); @@ -283,20 +347,24 @@ QString KsViewModel::getValueStr(int column, int row) const return KsUtils::Ts2String(_data[row]->ts, 6); case TRACE_VIEW_COL_COMM: - return kshark_get_task_easy(_data[row]); + buffer = kshark_get_task(_data[row]); + return lanMakeString(); case TRACE_VIEW_COL_PID: - pid = kshark_get_pid_easy(_data[row]); + pid = kshark_get_pid(_data[row]); return QString("%1").arg(pid); - case TRACE_VIEW_COL_LAT: - return kshark_get_latency_easy(_data[row]); + case TRACE_VIEW_COL_AUX: + buffer = kshark_get_aux_info(_data[row]); + return lanMakeString(); case TRACE_VIEW_COL_EVENT: - return kshark_get_event_name_easy(_data[row]); + buffer = kshark_get_event_name(_data[row]); + return lanMakeString(); case TRACE_VIEW_COL_INFO : - return kshark_get_info_easy(_data[row]); + buffer = kshark_get_info(_data[row]); + return lanMakeString(); default: return {}; @@ -333,8 +401,10 @@ void KsViewModel::fill(KsDataStore *data) _data = data->rows(); _nRows = data->size(); + _streamColors = KsPlot::streamColorTable(); endInsertRows(); + _updateHeader(); } /** @brief Select a row in the table. @@ -375,6 +445,14 @@ void KsViewModel::update(KsDataStore *data) fill(data); } +/** Update the color scheme used by the model. */ +void KsViewModel::loadColors() +{ + beginResetModel(); + _streamColors = KsPlot::streamColorTable(); + endResetModel(); +} + /** @brief Search the content of the table for a data satisfying an abstract * condition. * @@ -420,12 +498,12 @@ KsGraphModel::~KsGraphModel() /** * @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) +void KsGraphModel::fill(KsDataStore *data) { + kshark_entry **entries = data->rows(); + size_t n = data->size(); + if (n == 0) return; @@ -435,7 +513,7 @@ void KsGraphModel::fill(kshark_entry **entries, size_t n) ksmodel_set_bining(&_histo, KS_DEFAULT_NBUNS, entries[0]->ts, - entries[n-1]->ts); + entries[n - 1]->ts); ksmodel_fill(&_histo, entries, n); diff --git a/src/KsModels.hpp b/src/KsModels.hpp index d360ad6..3a6d3f1 100644 --- a/src/KsModels.hpp +++ b/src/KsModels.hpp @@ -26,6 +26,7 @@ // KernelShark #include "libkshark.h" #include "libkshark-model.h" +#include "KsPlotTools.hpp" #include "KsSearchFSM.hpp" /** A negative row index, to be used for deselecting the Passive Marker. */ @@ -45,7 +46,7 @@ public: explicit KsViewModel(QObject *parent = nullptr); /** Set the colors of the two markers. */ - void setColors(const QColor &colA, const QColor &colB) { + void setMarkerColors(const QColor &colA, const QColor &colB) { _colorMarkA = colA; _colorMarkB = colB; }; @@ -91,8 +92,16 @@ public: search_condition_func cond, QList<size_t> *matchList); + void loadColors(); + + /** Returns True is only one Data stream is open. */ + bool singleStream() const {return _singleStream;} + /** Table columns Identifiers. */ enum { + /** Identifier of the Data stream. */ + TRACE_VIEW_COL_STREAM, + /** Identifier of the Index column. */ TRACE_VIEW_COL_INDEX, @@ -109,7 +118,7 @@ public: TRACE_VIEW_COL_PID, /** Identifier of the Latency Id column. */ - TRACE_VIEW_COL_LAT, + TRACE_VIEW_COL_AUX, /** Identifier of the Event name Id column. */ TRACE_VIEW_COL_EVENT, @@ -122,6 +131,8 @@ public: }; private: + void _updateHeader(); + /** Trace data array. */ kshark_entry **_data; @@ -142,6 +153,11 @@ private: /** The color of the row selected by marker B. */ QColor _colorMarkB; + + /** True if only one Data stream is open. */ + bool _singleStream; + + KsPlot::ColorTable _streamColors; }; /** @@ -192,11 +208,7 @@ public: * Use the "row" index in the Proxy model to retrieve the "row" index * in the source model. */ - int mapRowFromSource(int r) const - { - /*This works because the row number is shown in column "0". */ - return this->data(this->index(r, 0)).toInt(); - } + int mapRowFromSource(int r) const; /** Get the source model. */ KsViewModel *source() {return _source;} @@ -272,7 +284,7 @@ public: /** Get the kshark_trace_histo object. */ kshark_trace_histo *histo() {return &_histo;} - void fill(kshark_entry **entries, size_t n); + void fill(KsDataStore *data); void shiftForward(size_t n); diff --git a/src/KsSearchFSM.cpp b/src/KsSearchFSM.cpp index 6a93ca7..a5f3682 100644 --- a/src/KsSearchFSM.cpp +++ b/src/KsSearchFSM.cpp @@ -136,6 +136,16 @@ void KsSearchFSM ::_lockSearchPanel(bool lock) /** Act according to the provided input. */ void NotDone::handleInput(KsSearchFSM* sm, sm_input_t input) { + int column = sm->column(); + if (sm->_columnComboBox.findText(">>", Qt::MatchContains) < 0) { + /* + * If only one Data stream (file) is loaded, the ">>" column + * (TRACE_VIEW_COL_STREAM) is not shown. The column index has + * to be corrected. + */ + ++column; + } + switch(input) { case sm_input_t::Start: sm->_lastRowSearched = -1; @@ -166,7 +176,7 @@ void Paused::handleInput(KsSearchFSM* sm, sm_input_t input) sm->searchRestartVisible(false); if (sm->column() != KsViewModel::TRACE_VIEW_COL_INFO && - sm->column() != KsViewModel::TRACE_VIEW_COL_LAT) + sm->column() != KsViewModel::TRACE_VIEW_COL_AUX) sm->_searchCountLabel.setText(""); sm->changeState(std::shared_ptr<InProgress>(new InProgress)); -- 2.25.1