diff mbox series

[v3,1/3] kernel-shark: Add methods for selecting the plots to be shown

Message ID 20200508152302.27843-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 43a86b98239ba97e3fdf799955e6a081de4a7275
Delegated to: Steven Rostedt
Headers show
Series [v3,1/3] kernel-shark: Add methods for selecting the plots to be shown | expand

Commit Message

Yordan Karadzhov May 8, 2020, 3:23 p.m. UTC
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 mbox series

Patch

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. */