All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 07/24] kernel-shark: Update KsModels and KsSearchFSM
Date: Mon,  1 Feb 2021 19:23:41 +0200	[thread overview]
Message-ID: <20210201172358.175407-8-y.karadz@gmail.com> (raw)
In-Reply-To: <20210201172358.175407-1-y.karadz@gmail.com>

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@gmail.com>
---
 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


  parent reply	other threads:[~2021-02-01 17:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01 17:23 [PATCH 00/24] Complete the KernelShark v2 transformation Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 01/24] kernel-shark: Add get_stream_object() Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 02/24] kernel-shark: Do proper reset in kshark_close_all() Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 03/24] kernel-shark: Restore the counting of event handlers Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 04/24] kernel-shark: Fix a misleading comment Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 05/24] kernel-shark: Count the number of readout interfaces Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 06/24] kernel-shark: Update KsUtils Yordan Karadzhov (VMware)
2021-02-01 17:23 ` Yordan Karadzhov (VMware) [this message]
2021-02-01 17:23 ` [PATCH 08/24] kernel-shark: Add trace data files for CI testing Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 09/24] kernel-shark: Add plugin tests Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 10/24] kernel-shark: Add model tests Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 11/24] kernel-shark: Update KsWidgetsLib Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 12/24] kernel-shark: Add combo point to Mark Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 13/24] kernel-shark: Add new methods to KsPlot::Mark Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 14/24] kernel-shark: Update the plotting example Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 15/24] kernel-shark: Update KsDualMarker and KsGLWidget Yordan Karadzhov (VMware)
2021-02-05 10:49   ` Tzvetomir Stoyanov
2021-02-08 10:36     ` Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 16/24] kernel-shark: Update KsTraceGraph and KsQuickContextMenu Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 17/24] kernel-shark: Update KsTraceViewer Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 18/24] kernel-shark: Update KsAdvFilteringDialog Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 19/24] kernel-shark: Update KsCaptureDialog Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 20/24] kernel-shark: Update KsSession Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 21/24] kernel-shark: Update MissedEvents plugin Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 22/24] kernel-shark: Update KsMainWindow and kernelshark.cpp Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 23/24] kernel-shark: Clickable sched_event plugin shapes Yordan Karadzhov (VMware)
2021-02-01 17:23 ` [PATCH 24/24] kernel-shark: Show Task plots from command lime Yordan Karadzhov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210201172358.175407-8-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.