Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 0/3] 
@ 2020-05-08 15:22 Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 1/3] kernel-shark: Add methods for selecting the plots to be shown Yordan Karadzhov (VMware)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-05-08 15:22 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The patch-set implements new commandline options for KernelShark that
can be used to pre-select the CPU and Task plots to be shown, before
opening the GUI. The idea was suggested by Julia Lawall.

Changes is v2:
 - Fixing a bug in the parsing of the string representing the list of
   IDs, given to the command line options.

 - New Patch 3/3 that limits the number of CPU plots shown by default
   when KernelShark starts. 

Changes is v3:
 - Switching to using comma instead of space for separating the
   Ids (Pid or CPU) of the plots. This way we don't need to worry
   about quoting the arguments.

 - Adding to patch [2/3] logic to handle the case when the user uses
   the "--cpu" or "--pid" options multiple times.

Yordan Karadzhov (VMware) (3):
  kernel-shark: Add methods for selecting the plots to be shown
  kernel-shark: Add command line options for selecting plots to be shown
  kernel-shark: Set a maximum number of plots to be shown by default

 kernel-shark/src/KsGLWidget.cpp   | 13 +++++++++--
 kernel-shark/src/KsMainWindow.cpp | 39 +++++++++++++++++++++++++++++++
 kernel-shark/src/KsMainWindow.hpp |  4 ++++
 kernel-shark/src/KsUtils.cpp      | 24 +++++++++++++++++++
 kernel-shark/src/KsUtils.hpp      |  2 ++
 kernel-shark/src/kernelshark.cpp  | 34 ++++++++++++++++++++++++---
 6 files changed, 111 insertions(+), 5 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/3] kernel-shark: Add methods for selecting the plots to be shown
  2020-05-08 15:22 [PATCH v3 0/3] Yordan Karadzhov (VMware)
@ 2020-05-08 15:23 ` Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 2/3] kernel-shark: Add command line options for selecting " Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 3/3] kernel-shark: Set a maximum number of plots to be shown by default Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-05-08 15:23 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The methods are added to the public interface of the KsMainWindow class
and can be used to pre-select the CPU and Task plots to be shown, before
opening the GUI.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsMainWindow.cpp | 39 +++++++++++++++++++++++++++++++
 kernel-shark/src/KsMainWindow.hpp |  4 ++++
 2 files changed, 43 insertions(+)

diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 1f56645..fc4e9a9 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -172,6 +172,45 @@ KsMainWindow::~KsMainWindow()
 		kshark_free(kshark_ctx);
 }
 
+/** Set the list ot CPU cores to be plotted. */
+void KsMainWindow::setCPUPlots(QVector<int> cpus)
+{
+	int nCPUs = tep_get_cpus(_data.tep());
+	auto lamCPUCheck = [=] (int cpu) {
+		if (cpu >= nCPUs) {
+			qWarning() << "Warning: No CPU" << cpu << "found in the data.";
+			return true;
+		}
+
+		return false;
+	};
+
+	cpus.erase(std::remove_if(cpus.begin(), cpus.end(), lamCPUCheck),
+		   cpus.end());
+
+	_graph.cpuReDraw(cpus);
+}
+
+/** Set the list ot tasks (pids) to be plotted. */
+void KsMainWindow::setTaskPlots(QVector<int> pids)
+{
+	QVector<int> allPids = KsUtils::getPidList();
+	auto lamPidCheck = [=] (int pid) {
+		int i = allPids.indexOf(pid);
+		if (i < 0) {
+			qWarning() << "Warning: No Pid" << pid << "found in the data.";
+			return true;
+		}
+
+		return false;
+	};
+
+	pids.erase(std::remove_if(pids.begin(), pids.end(), lamPidCheck),
+		   pids.end());
+
+	_graph.taskReDraw(pids);
+}
+
 /**
  * Reimplemented event handler used to update the geometry of the window on
  * resize events.
diff --git a/kernel-shark/src/KsMainWindow.hpp b/kernel-shark/src/KsMainWindow.hpp
index 997ea54..2fac107 100644
--- a/kernel-shark/src/KsMainWindow.hpp
+++ b/kernel-shark/src/KsMainWindow.hpp
@@ -62,6 +62,10 @@ public:
 		_plugins.unregisterPlugin(plugin);
 	}
 
+	void setCPUPlots(QVector<int> cpus);
+
+	void setTaskPlots(QVector<int> pids);
+
 	void resizeEvent(QResizeEvent* event);
 
 	/** Set the Full Screen mode. */
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 2/3] kernel-shark: Add command line options for selecting plots to be shown
  2020-05-08 15:22 [PATCH v3 0/3] Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 1/3] kernel-shark: Add methods for selecting the plots to be shown Yordan Karadzhov (VMware)
@ 2020-05-08 15:23 ` Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 3/3] kernel-shark: Set a maximum number of plots to be shown by default Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-05-08 15:23 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware), Julia Lawall

Example:
  kernelshark -i mytrace.dat --cpu '1,4-7' --pid 11

This will show CPUs: 1, 4, 5, 6, 7 and task(PID): 11.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Suggested-by: Julia Lawall  <julia.lawall@inria.fr>
---
 kernel-shark/src/KsUtils.cpp     | 24 +++++++++++++++++++
 kernel-shark/src/KsUtils.hpp     |  2 ++
 kernel-shark/src/kernelshark.cpp | 41 +++++++++++++++++++++++++++++---
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/kernel-shark/src/KsUtils.cpp b/kernel-shark/src/KsUtils.cpp
index 77d0c7c..8c61b3f 100644
--- a/kernel-shark/src/KsUtils.cpp
+++ b/kernel-shark/src/KsUtils.cpp
@@ -336,6 +336,30 @@ QStringList splitArguments(QString cmd)
 	return argv;
 }
 
+/** Parse a string containing Ids. The string can be of the form "1 4-7 9". */
+QVector<int> parseIdList(QString v_str)
+{
+	QStringList list = v_str.split(",", QString::SkipEmptyParts);
+	QVector<int> v;
+
+	for (auto item: list) {
+		int i = item.indexOf('-');
+		if (i > 0) {
+			/* This item is an interval. */
+			int to = item.right(item.size() - i - 1).toInt();
+			int from = item.left(i).toInt();
+			int s = v.size();
+
+			v.resize(s + to - from + 1);
+			std::iota(v.begin() + s, v.end(), from);
+		} else {
+			v.append(item.toInt());
+		}
+	}
+
+	return v;
+}
+
 }; // KsUtils
 
 /** A stream operator for converting QColor into KsPlot::Color. */
diff --git a/kernel-shark/src/KsUtils.hpp b/kernel-shark/src/KsUtils.hpp
index f44139b..8293e7d 100644
--- a/kernel-shark/src/KsUtils.hpp
+++ b/kernel-shark/src/KsUtils.hpp
@@ -136,6 +136,8 @@ QString getSaveFile(QWidget *parent,
 
 QStringList splitArguments(QString cmd);
 
+QVector<int> parseIdList(QString v_str);
+
 }; // KsUtils
 
 /** Identifier of the Dual Marker active state. */
diff --git a/kernel-shark/src/kernelshark.cpp b/kernel-shark/src/kernelshark.cpp
index 1ec6678..0de80af 100644
--- a/kernel-shark/src/kernelshark.cpp
+++ b/kernel-shark/src/kernelshark.cpp
@@ -29,20 +29,43 @@ void usage(const char *prog)
 	printf("  -u	unregister plugin, use plugin name or absolute path\n");
 	printf("  -s	import a session\n");
 	printf("  -l	import the last session\n");
+	puts(" --cpu	show plots for CPU cores, default is \"show all\"");
+	puts(" --pid	show plots for tasks, default is \"do not show\"");
+	puts("\n example:");
+	puts("  kernelshark -i mytrace.dat --cpu 1,4-7 --pid 11 -p path/to/my/plugin/myplugin.so\n");
 }
 
+#define KS_LONG_OPTS 0
+static option longOptions[] = {
+	{"help", no_argument, nullptr, 'h'},
+	{"pid", required_argument, nullptr, KS_LONG_OPTS},
+	{"cpu", required_argument, nullptr, KS_LONG_OPTS},
+	{nullptr, 0, nullptr, 0}
+};
+
 int main(int argc, char **argv)
 {
 	QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 	QApplication a(argc, argv);
 
+	QVector<int> cpuPlots, taskPlots;
+	bool fromSession = false;
+	int optionIndex = 0;
 	KsMainWindow ks;
-
 	int c;
-	bool fromSession = false;
 
-	while ((c = getopt(argc, argv, "hvi:p:u:s:l")) != -1) {
+	while ((c = getopt_long(argc, argv, "hvi:p:u:s:l",
+					    longOptions,
+					    &optionIndex)) != -1) {
 		switch(c) {
+		case KS_LONG_OPTS:
+			if (strcmp(longOptions[optionIndex].name, "cpu") == 0)
+				cpuPlots.append(KsUtils::parseIdList(QString(optarg)));
+			else if (strcmp(longOptions[optionIndex].name, "pid") == 0)
+				taskPlots.append(KsUtils::parseIdList(QString(optarg)));
+
+			break;
+
 		case 'h':
 			usage(argv[0]);
 			return 0;
@@ -95,6 +118,18 @@ int main(int argc, char **argv)
 			ks.loadDataFile(QString(input_file));
 	}
 
+	auto lamOrderIds = [] (QVector<int> &ids) {
+		/* Sort and erase duplicates. */
+		std::sort(ids.begin(), ids.end());
+		ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
+		return ids;
+	};
+
+	if (cpuPlots.count() || taskPlots.count()) {
+		ks.setCPUPlots(lamOrderIds(cpuPlots));
+		ks.setTaskPlots(lamOrderIds(taskPlots));
+	}
+
 	ks.show();
 	return a.exec();
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 3/3] kernel-shark: Set a maximum number of plots to be shown by default
  2020-05-08 15:22 [PATCH v3 0/3] Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 1/3] kernel-shark: Add methods for selecting the plots to be shown Yordan Karadzhov (VMware)
  2020-05-08 15:23 ` [PATCH v3 2/3] kernel-shark: Add command line options for selecting " Yordan Karadzhov (VMware)
@ 2020-05-08 15:23 ` Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-05-08 15:23 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware), Julia Lawall

Set a maximum number of CPU plots to be shown by default. No more than
16 CPU plots will be shown if no command line options, per-selecting
the plots, are provided. This will be useful when opening trace file
containing hundreds of CPU cores.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Suggested-by: Julia Lawall  <julia.lawall@inria.fr>
---
 kernel-shark/src/KsGLWidget.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel-shark/src/KsGLWidget.cpp b/kernel-shark/src/KsGLWidget.cpp
index e930006..78ded33 100644
--- a/kernel-shark/src/KsGLWidget.cpp
+++ b/kernel-shark/src/KsGLWidget.cpp
@@ -340,6 +340,11 @@ void KsGLWidget::keyReleaseEvent(QKeyEvent *event)
 	return;
 }
 
+/**
+ * The maximum number of CPU plots to be shown by default when the GUI starts.
+ */
+#define KS_MAX_START_PLOTS 16
+
 /**
  * @brief Load and show trace data.
  *
@@ -358,7 +363,6 @@ void KsGLWidget::loadData(KsDataStore *data)
 	 * One bin will correspond to one pixel.
 	 */
 	nBins = width() - _hMargin * 2;
-	nCPUs = tep_get_cpus(_data->tep());
 
 	_model.reset();
 
@@ -368,8 +372,13 @@ void KsGLWidget::loadData(KsDataStore *data)
 	ksmodel_set_bining(_model.histo(), nBins, tMin, tMax);
 	_model.fill(_data->rows(), _data->size());
 
-	/* Make a default CPU list. All CPUs will be plotted. */
+	/* Make a default CPU list. All CPUs (or the first N_max) will be plotted. */
 	_cpuList = {};
+
+	nCPUs = tep_get_cpus(_data->tep());
+	if (nCPUs > KS_MAX_START_PLOTS)
+		nCPUs = KS_MAX_START_PLOTS;
+
 	for (int i = 0; i < nCPUs; ++i)
 		_cpuList.append(i);
 
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 15:22 [PATCH v3 0/3] Yordan Karadzhov (VMware)
2020-05-08 15:23 ` [PATCH v3 1/3] kernel-shark: Add methods for selecting the plots to be shown Yordan Karadzhov (VMware)
2020-05-08 15:23 ` [PATCH v3 2/3] kernel-shark: Add command line options for selecting " Yordan Karadzhov (VMware)
2020-05-08 15:23 ` [PATCH v3 3/3] kernel-shark: Set a maximum number of plots to be shown by default Yordan Karadzhov (VMware)

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git