linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] kernel-shark: Update the C++ tools for plotting
@ 2020-12-09 13:45 Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 01/10] kernel-shark: Integrate streams with KsPlotTools Yordan Karadzhov (VMware)
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

Yordan Karadzhov (VMware) (10):
  kernel-shark: Integrate streams with KsPlotTools
  kernel-shark: Add getStreamColorTable()
  kernel-shark: Redefine the args of KsPlot::getColor()
  kernel-shark: Add TextBox class to KsPlot namespace
  kernel-shark: Consistent method naming in KsPlotTools
  kernel-shark: Make the label part of the graph
  kernel-shark: Remove the hard-coded Idle PID
  kernel-shark: Add class Polyline to KsPlot namespace
  kernel-shark: Add VirtBridge and VirtGap classes
  kernel-shark: Add double click interface to PlotObject

 src/CMakeLists.txt  |   4 +-
 src/KsPlotTools.cpp | 412 +++++++++++++++++++++++++++++++++++++-------
 src/KsPlotTools.hpp | 199 +++++++++++++++++----
 3 files changed, 519 insertions(+), 96 deletions(-)

-- 
2.25.1


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

* [PATCH 01/10] kernel-shark: Integrate streams with KsPlotTools
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 02/10] kernel-shark: Add getStreamColorTable() Yordan Karadzhov (VMware)
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The C++ ploting toolls are adapted in order to be able to work with
the new version of the C API. Now we can handle multiple Data streams.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/CMakeLists.txt  |  4 +-
 src/KsPlotTools.cpp | 94 ++++++++++++++++++++++++++++++++-------------
 src/KsPlotTools.hpp |  4 +-
 3 files changed, 71 insertions(+), 31 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cbd45ed..bc12853 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,8 +22,8 @@ install(TARGETS kshark LIBRARY DESTINATION ${_LIBDIR}/${KS_APP_NAME})
 if (OPENGL_FOUND)
 
     message(STATUS "libkshark-plot")
-    add_library(kshark-plot  SHARED  libkshark-plot.c)
-#                                      KsPlotTools.cpp)
+    add_library(kshark-plot  SHARED  libkshark-plot.c
+                                     KsPlotTools.cpp)
 
     target_link_libraries(kshark-plot  kshark
                                        ${GLUT_LIBRARY}
diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index fe3008e..113a6c0 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -10,16 +10,13 @@
  */
 
 // C
+#include <cstring>
 #include <math.h>
 
 // C++
 #include <algorithm>
 #include <vector>
 
-// OpenGL
-#include <GL/freeglut.h>
-#include <GL/gl.h>
-
 // KernelShark
 #include "KsPlotTools.hpp"
 
@@ -109,29 +106,45 @@ void Color::setRainbowColor(int n)
 ColorTable getTaskColorTable()
 {
 	struct kshark_context *kshark_ctx(nullptr);
+	int nTasks(0), pid, *pids, i(0), *streamIds;
+	std::vector<int> tempPids;
 	ColorTable colors;
-	int nTasks, pid, *pids, i(0);
 
 	if (!kshark_instance(&kshark_ctx))
 		return colors;
 
-	nTasks = kshark_get_task_pids(kshark_ctx, &pids);
-	if (!nTasks)
+	streamIds = kshark_all_streams(kshark_ctx);
+	for (int j = 0; j < kshark_ctx->n_streams; ++j) {
+		nTasks = kshark_get_task_pids(kshark_ctx, streamIds[j], &pids);
+		tempPids.insert(tempPids.end(), pids, pids + nTasks);
+		free(pids);
+	}
+
+	free(streamIds);
+
+	if (!tempPids.size())
 		return colors;
 
-	std::vector<int> temp_pids(pids, pids + nTasks);
-	std::sort(temp_pids.begin(), temp_pids.end());
+	std::sort(tempPids.begin(), tempPids.end());
 
-	free(pids);
+	/* Erase duplicates. */
+	tempPids.erase(unique(tempPids.begin(), tempPids.end()),
+		       tempPids.end());
 
-	if (temp_pids[i] == 0) {
-		/* The "Idle" process (pid = 0) will be plotted in black. */
+	/* Erase negative (error codes). */
+	auto isNegative = [](int i) {return i < 0;};
+	auto it = remove_if(tempPids.begin(), tempPids.end(), isNegative);
+	tempPids.erase(it, tempPids.end());
+
+	nTasks = tempPids.size();
+	if (tempPids[i] == 0) {
+		/* Pid <= 0 will be plotted in black. */
 		colors[i++] = {};
 	}
 
 	for (; i < nTasks; ++i) {
-		pid = temp_pids[i];
-		colors[pid].setRainbowColor(i - 1);
+		pid = tempPids[i];
+		colors[pid].setRainbowColor(i);
 	}
 
 	return colors;
@@ -145,16 +158,26 @@ ColorTable getTaskColorTable()
  */
 ColorTable getCPUColorTable()
 {
-	struct kshark_context *kshark_ctx(nullptr);
+	kshark_context *kshark_ctx(nullptr);
+	int nCPUs, nCPUMax(0), *streamIds;
+	kshark_data_stream *stream;
 	ColorTable colors;
-	int nCPUs;
 
 	if (!kshark_instance(&kshark_ctx))
 		return colors;
 
-	nCPUs =  tep_get_cpus(kshark_ctx->pevent);
-	for (int i = 0; i < nCPUs; ++i)
-		colors[i].setRainbowColor(i);
+	streamIds = kshark_all_streams(kshark_ctx);
+	for (int i = 0; i < kshark_ctx->n_streams; ++i) {
+		stream = kshark_get_data_stream(kshark_ctx, streamIds[i]);
+		nCPUs =  stream->n_cpus;
+		if (nCPUMax < nCPUs)
+			nCPUMax = nCPUs;
+	}
+
+	free(streamIds);
+
+	for (int i = 0; i < nCPUMax; ++i)
+		colors[i].setRainbowColor(i + 8);
 
 	return colors;
 }
@@ -788,9 +811,10 @@ void Graph::setBin(int bin, int pidF, int pidB, const Color &col, uint8_t m)
 /**
  * @brief Process a CPU Graph.
  *
+ * @param sd: Data stream identifier.
  * @param cpu: The CPU core.
  */
-void Graph::fillCPUGraph(int cpu)
+void Graph::fillCPUGraph(int sd, int cpu)
 {
 	struct kshark_entry *eFront;
 	int pidFront(0), pidBack(0);
@@ -804,6 +828,7 @@ void Graph::fillCPUGraph(int cpu)
 		eFront = nullptr;
 
 		pidFront = ksmodel_get_pid_front(_histoPtr, bin,
+							    sd,
 							    cpu,
 							    true,
 							    _collectionPtr,
@@ -813,6 +838,7 @@ void Graph::fillCPUGraph(int cpu)
 			eFront = _histoPtr->data[index];
 
 		pidBack = ksmodel_get_pid_back(_histoPtr, bin,
+							  sd,
 							  cpu,
 							  true,
 							  _collectionPtr,
@@ -820,10 +846,11 @@ void Graph::fillCPUGraph(int cpu)
 
 		pidBackNoFilter =
 			ksmodel_get_pid_back(_histoPtr, bin,
-						       cpu,
-						       false,
-						       _collectionPtr,
-						       nullptr);
+							sd,
+							cpu,
+							false,
+							_collectionPtr,
+							nullptr);
 
 		if (pidBack != pidBackNoFilter)
 			pidBack = KS_FILTERED_BIN;
@@ -832,6 +859,7 @@ void Graph::fillCPUGraph(int cpu)
 		if (eFront) {
 			if (!(eFront->visible & KS_EVENT_VIEW_FILTER_MASK) &&
 			    ksmodel_cpu_visible_event_exist(_histoPtr, bin,
+								       sd,
 								       cpu,
 								       _collectionPtr,
 								       &index)) {
@@ -874,6 +902,7 @@ void Graph::fillCPUGraph(int cpu)
 		 */
 		pidBackNoFilter = ksmodel_get_pid_back(_histoPtr,
 						       LOWER_OVERFLOW_BIN,
+						       sd,
 						       cpu,
 						       false,
 						       _collectionPtr,
@@ -882,6 +911,7 @@ void Graph::fillCPUGraph(int cpu)
 		/* Now get the Pid back, applying filters. */
 		pidBack = ksmodel_get_pid_back(_histoPtr,
 					       LOWER_OVERFLOW_BIN,
+					       sd,
 					       cpu,
 					       true,
 					       _collectionPtr,
@@ -916,9 +946,10 @@ void Graph::fillCPUGraph(int cpu)
 /**
  * @brief Process a Task Graph.
  *
+ * @param sd: Data stream identifier.
  * @param pid: The Process Id of the Task.
  */
-void Graph::fillTaskGraph(int pid)
+void Graph::fillTaskGraph(int sd, int pid)
 {
 	int cpuFront, cpuBack(0), pidFront(0), pidBack(0), lastCpu(-1), bin(0);
 	struct kshark_entry *eFront;
@@ -972,6 +1003,7 @@ void Graph::fillTaskGraph(int pid)
 			 */
 			int cpuPid = ksmodel_get_pid_back(_histoPtr,
 							  bin,
+							  sd,
 							  lastCpu,
 							  false,
 							  nullptr, // No collection
@@ -998,6 +1030,7 @@ void Graph::fillTaskGraph(int pid)
 		eFront = nullptr;
 		/* Get the CPU used by this task. */
 		cpuFront = ksmodel_get_cpu_front(_histoPtr, bin,
+						 sd,
 						 pid,
 						 false,
 						 _collectionPtr,
@@ -1006,6 +1039,7 @@ void Graph::fillTaskGraph(int pid)
 			eFront = _histoPtr->data[index];
 
 		cpuBack = ksmodel_get_cpu_back(_histoPtr, bin,
+					       sd,
 					       pid,
 					       false,
 					       _collectionPtr,
@@ -1020,6 +1054,7 @@ void Graph::fillTaskGraph(int pid)
 			 */
 			pidFront = ksmodel_get_pid_front(_histoPtr,
 							 bin,
+							 sd,
 							 cpuFront,
 							 false,
 							 _collectionPtr,
@@ -1027,6 +1062,7 @@ void Graph::fillTaskGraph(int pid)
 
 			pidBack = ksmodel_get_pid_back(_histoPtr,
 						       bin,
+						       sd,
 						       cpuBack,
 						       false,
 						       _collectionPtr,
@@ -1037,6 +1073,7 @@ void Graph::fillTaskGraph(int pid)
 				if (!(eFront->visible & KS_EVENT_VIEW_FILTER_MASK) &&
 				    ksmodel_task_visible_event_exist(_histoPtr,
 								     bin,
+								     sd,
 								     pid,
 								     _collectionPtr,
 								     &index)) {
@@ -1062,8 +1099,9 @@ void Graph::fillTaskGraph(int pid)
 		 * No data from this Task in the very first bin. Use the Lower
 		 * Overflow Bin to retrieve the CPU used by the task (if any).
 		 */
-		cpuFront = ksmodel_get_cpu_back(_histoPtr, LOWER_OVERFLOW_BIN, pid,
-					   false, _collectionPtr, nullptr);
+		cpuFront = ksmodel_get_cpu_back(_histoPtr, LOWER_OVERFLOW_BIN,
+						sd, pid,
+						false, _collectionPtr, nullptr);
 		if (cpuFront >= 0) {
 			/*
 			 * The Lower Overflow Bin contains data from this Task.
@@ -1075,6 +1113,7 @@ void Graph::fillTaskGraph(int pid)
 
 			pidCpu0 = ksmodel_get_pid_back(_histoPtr,
 						       0,
+						       sd,
 						       cpuFront,
 						       false,
 						       _collectionPtr,
@@ -1082,6 +1121,7 @@ void Graph::fillTaskGraph(int pid)
 
 			pidCpuLOB = ksmodel_get_pid_back(_histoPtr,
 							 LOWER_OVERFLOW_BIN,
+							 sd,
 							 cpuFront,
 							 false,
 							 _collectionPtr,
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index ee447f1..6e66373 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -432,9 +432,9 @@ public:
 	/** @brief Set the Hash table of Task's colors. */
 	void setBinColorTablePtr(KsPlot::ColorTable *ct) {_binColors = ct;}
 
-	void fillCPUGraph(int cpu);
+	void fillCPUGraph(int sd, int cpu);
 
-	void fillTaskGraph(int pid);
+	void fillTaskGraph(int sd, int pid);
 
 	void draw(float s = 1);
 
-- 
2.25.1


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

* [PATCH 02/10] kernel-shark: Add getStreamColorTable()
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 01/10] kernel-shark: Integrate streams with KsPlotTools Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 03/10] kernel-shark: Redefine the args of KsPlot::getColor() Yordan Karadzhov (VMware)
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

This method provides a hash table that maps the stream Ids to
rainbow-like colors.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 33 +++++++++++++++++++++++++++++++++
 src/KsPlotTools.hpp |  2 ++
 2 files changed, 35 insertions(+)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 113a6c0..7a0450b 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -182,6 +182,39 @@ ColorTable getCPUColorTable()
 	return colors;
 }
 
+/**
+ * @brief Create a Hash table of Rainbow colors. The Steam Ids are
+ *	  mapped to the palette of Rainbow colors.
+ *
+ * @returns ColorTable instance.
+ */
+ColorTable getStreamColorTable()
+{
+	kshark_context *kshark_ctx(nullptr);
+	ColorTable colors;
+	Color color;
+	float alpha(.35);
+	int *streamIds;
+
+	if (!kshark_instance(&kshark_ctx))
+		return colors;
+
+	streamIds = kshark_all_streams(kshark_ctx);
+	for (int i = 0; i < kshark_ctx->n_streams; ++i) {
+		/*
+		 * Starting from index 6 provides better functioning of the
+		 * color scheme slider.
+		 */
+		color.setRainbowColor(i + 6);
+		color.blend(alpha);
+		colors[streamIds[i]] = color;
+	}
+
+	free(streamIds);
+
+	return colors;
+}
+
 /**
  * @brief Search the Hash table of Rainbow colors for a particular key (pid).
  *
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index 6e66373..ab28f43 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -78,6 +78,8 @@ ColorTable getTaskColorTable();
 
 ColorTable getCPUColorTable();
 
+ColorTable getStreamColorTable();
+
 Color getColor(ColorTable *colors, int pid);
 
 /** Represents an abstract graphical element. */
-- 
2.25.1


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

* [PATCH 03/10] kernel-shark: Redefine the args of KsPlot::getColor()
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 01/10] kernel-shark: Integrate streams with KsPlotTools Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 02/10] kernel-shark: Add getStreamColorTable() Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 04/10] kernel-shark: Add TextBox class to KsPlot namespace Yordan Karadzhov (VMware)
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The function was originally designed to return the color that
correspond to a given PID. However we now have 3 different color
maps (for PID, CPU Id and Stream Id) and the same method can be
used with each of the 3 maps. We also want to prevent the method
from modifying the map itself.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 10 +++++-----
 src/KsPlotTools.hpp |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 7a0450b..52c3cbb 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -216,17 +216,17 @@ ColorTable getStreamColorTable()
 }
 
 /**
- * @brief Search the Hash table of Rainbow colors for a particular key (pid).
+ * @brief Search the Hash table of Rainbow colors for a particular key (Id).
  *
  * @param colors: Input location for the ColorTable instance.
- * @param pid: the Process Id to search for.
+ * @param id: The Id to search for.
  *
- * @returns The Rainbow color of the key "pid". If "pid" does not exist, the
+ * @returns The Rainbow color of the key "id". If "id" does not exist, the
  *	    returned color is Black.
  */
-Color getColor(ColorTable *colors, int pid)
+Color getColor(const ColorTable *colors, int id)
 {
-	auto item = colors->find(pid);
+	auto item = colors->find(id);
 
 	if (item != colors->end())
 		return item->second;
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index ab28f43..dbb15bf 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -80,7 +80,7 @@ ColorTable getCPUColorTable();
 
 ColorTable getStreamColorTable();
 
-Color getColor(ColorTable *colors, int pid);
+Color getColor(const ColorTable *colors, int id);
 
 /** Represents an abstract graphical element. */
 class PlotObject {
-- 
2.25.1


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

* [PATCH 04/10] kernel-shark: Add TextBox class to KsPlot namespace
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (2 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 03/10] kernel-shark: Redefine the args of KsPlot::getColor() Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 05/10] kernel-shark: Consistent method naming in KsPlotTools Yordan Karadzhov (VMware)
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

This class represents a text that is printed/drawn inside a colorful
frame.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++
 src/KsPlotTools.hpp |  42 ++++++++++++++++
 2 files changed, 158 insertions(+)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 52c3cbb..ef15cde 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -97,6 +97,23 @@ void Color::setRainbowColor(int n)
 	set(r, g, b);
 }
 
+/** Alpha blending with white background. */
+void Color::blend(float alpha)
+{
+	if (alpha < 0 || alpha > 1.)
+		return;
+
+	auto lamBld = [alpha](int val) {
+		return  val * alpha + (1 - alpha) * 255;
+	};
+
+	int r = lamBld(this->r());
+	int g = lamBld(this->g());
+	int b = lamBld(this->b());
+
+	set(r, g, b);
+}
+
 /**
  * @brief Create a Hash table of Rainbow colors. The sorted Pid values are
  *	  mapped to the palette of Rainbow colors.
@@ -507,6 +524,105 @@ void Polygon::_draw(const Color &col, float size) const
 					    col.color_c_ptr(),
 					    size);
 }
+/** The created object will print/draw only the text without the frame. */
+TextBox::TextBox()
+: _text(""),
+  _font(nullptr)
+{
+	setPos(Point(0, 0));
+	_box._visible = false;
+}
+
+
+/** The created object will print/draw only the text without the frame. */
+TextBox::TextBox(ksplot_font *f)
+: _text(""),
+  _font(f)
+{
+	setPos(Point(0, 0));
+	_box._visible = false;
+}
+
+/** The created object will print/draw only the text without the frame. */
+TextBox::TextBox(ksplot_font *f, const std::string &text, const Point &pos)
+: _text(text),
+  _font(f)
+{
+	setPos(pos);
+	_box._visible = false;
+}
+
+/** The created object will print/draw only the text without the frame. */
+TextBox::TextBox(ksplot_font *f, const std::string &text, const Color &col,
+		 const Point &pos)
+: _text(text),
+  _font(f)
+{
+	_color = col;
+	setPos(pos);
+	_box._visible = false;
+}
+
+/** The created object will print/draw the text and the frame. */
+TextBox::TextBox(ksplot_font *f, const std::string &text, const Color &col,
+		 const Point &pos, int l, int h)
+: _text(text),
+  _font(f)
+{
+	setPos(pos);
+	setBoxAppearance(col, l, h);
+}
+
+/**
+ * @brief Set the position of the bottom-left corner of the frame.
+ *
+ * @param p: The coordinates of the bottom-left corner.
+ */
+void TextBox::setPos(const Point &p)
+{
+	_box.setPoint(0, p);
+}
+
+/**
+ * @brief Set the color and the dimensions of the frame.
+ *
+ * @param col: The color of the frame.
+ * @param l: The length of the frame.
+ * @param h: The height of the frame.
+ */
+void TextBox::setBoxAppearance(const Color &col, int l, int h)
+{
+	_box.setFill(true);
+	_box._color = col;
+	_box._visible = true;
+
+	if (h <= 0 && _font)
+		h = _font->height;
+
+	_box.setPoint(1, _box.getPointX(0),	_box.getPointY(0) - h);
+	_box.setPoint(2, _box.getPointX(0) + l,	_box.getPointY(0) - h);
+	_box.setPoint(3, _box.getPointX(0) + l,	_box.getPointY(0));
+}
+
+void TextBox::_draw(const Color &col, float size) const
+{
+	_box.draw();
+	if (!_font || _text.empty())
+		return;
+
+	if (_box._visible ) {
+		int bShift = (_box.getPointY(0) - _box.getPointY(1) - _font->height) / 2;
+		ksplot_print_text(_font, NULL,
+				  _box.getPointX(0) + _font->height / 4,
+				  _box.getPointY(0) - _font->base - bShift,
+				  _text.c_str());
+	} else {
+		ksplot_print_text(_font, col.color_c_ptr(),
+				  _box.getPointX(0) + _font->height / 4,
+				  _box.getPointY(0) - _font->base,
+				  _text.c_str());
+	}
+}
 
 /**
  * @brief Create a default Mark.
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index dbb15bf..b270a56 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -47,6 +47,8 @@ public:
 
 	void setRainbowColor(int n);
 
+	void blend(float alpha);
+
 	/**
 	 * @brief Get the C struct defining the RGB color.
 	 */
@@ -305,6 +307,46 @@ public:
 	virtual ~Rectangle() {}
 };
 
+/**
+ * This class represents a text that is printed/drawn inside a colorful frame.
+ */
+class TextBox : public PlotObject {
+public:
+	TextBox();
+
+	TextBox(ksplot_font *f);
+
+	TextBox(ksplot_font *f, const std::string &text, const Point &pos);
+
+	TextBox(ksplot_font *f, const std::string &text, const Color &col,
+		const Point &pos);
+
+	TextBox(ksplot_font *f, const std::string &text, const Color &col,
+		const Point &pos, int l, int h = -1);
+
+	/** Destroy the TextBox object. Keep this destructor virtual. */
+	virtual ~TextBox() {}
+
+	/** Set the font to be used. */
+	void setFont(ksplot_font *f) {_font = f;}
+
+	/** Set the text. */
+	void setText(const std::string &t) {_text = t;}
+
+	void setPos(const Point &p);
+
+	void setBoxAppearance(const Color &col, int l, int h);
+
+private:
+	void _draw(const Color &, float size = 1.) const override;
+
+	std::string	_text;
+
+	ksplot_font	*_font;
+
+	Rectangle	_box;
+};
+
 /**
  * This class represents the graphical element of the KernelShark GUI marker.
  */
-- 
2.25.1


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

* [PATCH 05/10] kernel-shark: Consistent method naming in KsPlotTools
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (3 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 04/10] kernel-shark: Add TextBox class to KsPlot namespace Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 06/10] kernel-shark: Make the label part of the graph Yordan Karadzhov (VMware)
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

Remove "get" from the name of the methods used to retrieve data fields
in KsPlotTools. This makes the naming consistent with the style used by
Qt.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 30 +++++++++++++++---------------
 src/KsPlotTools.hpp | 34 +++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index ef15cde..4bf08ef 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -120,7 +120,7 @@ void Color::blend(float alpha)
  *
  * @returns ColorTable instance.
  */
-ColorTable getTaskColorTable()
+ColorTable taskColorTable()
 {
 	struct kshark_context *kshark_ctx(nullptr);
 	int nTasks(0), pid, *pids, i(0), *streamIds;
@@ -173,7 +173,7 @@ ColorTable getTaskColorTable()
  *
  * @returns ColorTable instance.
  */
-ColorTable getCPUColorTable()
+ColorTable CPUColorTable()
 {
 	kshark_context *kshark_ctx(nullptr);
 	int nCPUs, nCPUMax(0), *streamIds;
@@ -205,7 +205,7 @@ ColorTable getCPUColorTable()
  *
  * @returns ColorTable instance.
  */
-ColorTable getStreamColorTable()
+ColorTable streamColorTable()
 {
 	kshark_context *kshark_ctx(nullptr);
 	ColorTable colors;
@@ -360,7 +360,7 @@ void Shape::setPoint(size_t i, const Point &p)
  * @brief Get the point "i". If the point does not exist, the function returns
  *	  nullptr.
  */
-const ksplot_point *Shape::getPoint(size_t i) const
+const ksplot_point *Shape::point(size_t i) const
 {
 	if (i < _nPoints)
 		return &_points[i];
@@ -394,7 +394,7 @@ void Shape::setPointY(size_t i, int y) {
  * @brief Get the horizontal coordinate of the point "i". If the point does
  * 	  not exist, the function returns 0.
  */
-int Shape::getPointX(size_t i) const {
+int Shape::pointX(size_t i) const {
 	if (i < _nPoints)
 		return _points[i].x;
 
@@ -405,7 +405,7 @@ int Shape::getPointX(size_t i) const {
  * @brief Get the vertical coordinate of the point "i". If the point does
  * 	  not exist, the function returns 0.
  */
-int Shape::getPointY(size_t i) const {
+int Shape::pointY(size_t i) const {
 	if (i < _nPoints)
 		return _points[i].y;
 
@@ -599,9 +599,9 @@ void TextBox::setBoxAppearance(const Color &col, int l, int h)
 	if (h <= 0 && _font)
 		h = _font->height;
 
-	_box.setPoint(1, _box.getPointX(0),	_box.getPointY(0) - h);
-	_box.setPoint(2, _box.getPointX(0) + l,	_box.getPointY(0) - h);
-	_box.setPoint(3, _box.getPointX(0) + l,	_box.getPointY(0));
+	_box.setPoint(1, _box.pointX(0),	_box.pointY(0) - h);
+	_box.setPoint(2, _box.pointX(0) + l,	_box.pointY(0) - h);
+	_box.setPoint(3, _box.pointX(0) + l,	_box.pointY(0));
 }
 
 void TextBox::_draw(const Color &col, float size) const
@@ -611,15 +611,15 @@ void TextBox::_draw(const Color &col, float size) const
 		return;
 
 	if (_box._visible ) {
-		int bShift = (_box.getPointY(0) - _box.getPointY(1) - _font->height) / 2;
+		int bShift = (_box.pointY(0) - _box.pointY(1) - _font->height) / 2;
 		ksplot_print_text(_font, NULL,
-				  _box.getPointX(0) + _font->height / 4,
-				  _box.getPointY(0) - _font->base - bShift,
+				  _box.pointX(0) + _font->height / 4,
+				  _box.pointY(0) - _font->base - bShift,
 				  _text.c_str());
 	} else {
 		ksplot_print_text(_font, col.color_c_ptr(),
-				  _box.getPointX(0) + _font->height / 4,
-				  _box.getPointY(0) - _font->base,
+				  _box.pointX(0) + _font->height / 4,
+				  _box.pointY(0) - _font->base,
 				  _text.c_str());
 	}
 }
@@ -808,7 +808,7 @@ void Graph::_initBins()
 /**
  *  Get the number of bins.
  */
-int Graph::size()
+int Graph::size() const
 {
 	return _size;
 }
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index b270a56..287e0fb 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -64,7 +64,7 @@ public:
 	 * @brief Get the frequency value used to generate the Rainbow
 	 * palette.
 	 */
-	static float getRainbowFrequency() {return _frequency;}
+	static float rainbowFrequency() {return _frequency;}
 
 private:
 	ksplot_color _col_c;
@@ -76,11 +76,11 @@ private:
 /** Hash table of colors. */
 typedef std::unordered_map<int, KsPlot::Color> ColorTable;
 
-ColorTable getTaskColorTable();
+ColorTable taskColorTable();
 
-ColorTable getCPUColorTable();
+ColorTable CPUColorTable();
 
-ColorTable getStreamColorTable();
+ColorTable streamColorTable();
 
 Color getColor(const ColorTable *colors, int id);
 
@@ -143,15 +143,15 @@ public:
 
 	void setPoint(size_t i, const Point &p);
 
-	const ksplot_point *getPoint(size_t i) const;
+	const ksplot_point *point(size_t i) const;
 
 	void setPointX(size_t i, int x);
 
 	void setPointY(size_t i, int y);
 
-	int getPointX(size_t i) const;
+	int pointX(size_t i) const;
 
-	int getPointY(size_t i) const;
+	int pointY(size_t i) const;
 
 	/**
 	 * @brief Get the number of point used to define the polygon.
@@ -179,10 +179,10 @@ public:
 	virtual ~Point() {}
 
 	/** @brief Get the horizontal coordinate of the point. */
-	int x() const {return getPointX(0);}
+	int x() const {return pointX(0);}
 
 	/** @brief Get the vertical coordinate of the point. */
-	int y() const {return getPointY(0);}
+	int y() const {return pointY(0);}
 
 	/** @brief Set the horizontal coordinate of the point. */
 	void setX(int x) {setPointX(0, x);}
@@ -201,7 +201,7 @@ public:
 	/**
 	 * @brief Get the C struct defining the point.
 	 */
-	const ksplot_point *point_c_ptr() const {return getPoint(0);}
+	const ksplot_point *point_c_ptr() const {return point(0);}
 
 private:
 	void _draw(const Color &col, float size = 1.) const override;
@@ -235,7 +235,7 @@ public:
 	void setA(int x, int y) { setPoint(0, x, y);}
 
 	/** @brief Get the first finishing point of the line. */
-	const ksplot_point *getA() const {return getPoint(0);}
+	const ksplot_point *a() const {return point(0);}
 
 	/**
 	 * @brief Set the coordinats of the second finishing point of the
@@ -247,7 +247,7 @@ public:
 	void setB(int x, int y) {setPoint(1, x, y);}
 
 	/** @brief Get the second finishing point of the line. */
-	const ksplot_point *getB() const {return getPoint(1);}
+	const ksplot_point *b() const {return point(1);}
 
 private:
 	void _draw(const Color &col, float size = 1.) const override;
@@ -408,7 +408,7 @@ public:
 	void drawVal(float size = 2.);
 
 	/** Get the height (module) of the line, representing the Bin. */
-	int mod() {return _val.y() - _base.y();}
+	int mod() const {return _val.y() - _base.y();}
 
 	/** @brief Set the vertical coordinate of the "val" Point. */
 	void setVal(int v) {_val.setY(_base.y() - v); }
@@ -458,7 +458,7 @@ public:
 	/* Keep this destructor virtual. */
 	virtual ~Graph();
 
-	int size();
+	int size() const;
 
 	void setModelPtr(kshark_trace_histo *histo);
 
@@ -485,12 +485,12 @@ public:
 	void setBase(int b);
 
 	/** @brief Get the vertical coordinate of the Graph's base. */
-	int getBase() const {return _bins[0]._base.y();}
+	int base() const {return _bins[0]._base.y();}
 
 	void setHeight(int h);
 
 	/** @brief Get the vertical size (height) of the Graph. */
-	int getHeight() const {return _height;}
+	int height() const {return _height;}
 
 	void setBinValue(int bin, int val);
 
@@ -504,7 +504,7 @@ public:
 		    const Color &col, uint8_t m);
 
 	/** @brief Get a particular bin. */
-	const Bin &getBin(int bin) const {return _bins[bin];}
+	const Bin &bin(int bin) const {return _bins[bin];}
 
 	void setHMargin(int hMargin);
 
-- 
2.25.1


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

* [PATCH 06/10] kernel-shark: Make the label part of the graph
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (4 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 05/10] kernel-shark: Consistent method naming in KsPlotTools Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 07/10] kernel-shark: Remove the hard-coded Idle PID Yordan Karadzhov (VMware)
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The capability to draw text with OpenGL is used. With this
functionality we will no longer need to create special Qt widgets
containing the text of the labels and carefully align those widgets
next to the OpenGL plotting area. This will greatly simplify the
internel structure of the TraceGraph widget.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 34 +++++++++++++++++++++++++---------
 src/KsPlotTools.hpp | 18 +++++++++++++++---
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 4bf08ef..d952f5e 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -759,6 +759,7 @@ Graph::Graph()
   _collectionPtr(nullptr),
   _binColors(nullptr),
   _ensembleColors(nullptr),
+  _label(),
   _zeroSuppress(false)
 {}
 
@@ -777,6 +778,7 @@ Graph::Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct, KsPlot::ColorTa
   _collectionPtr(nullptr),
   _binColors(bct),
   _ensembleColors(ect),
+  _label(),
   _zeroSuppress(false)
 {
 	if (!_bins) {
@@ -795,10 +797,15 @@ Graph::~Graph()
 	delete[] _bins;
 }
 
+int Graph::_firstBinOffset()
+{
+	return _labelSize + 2 * _hMargin;
+}
+
 void Graph::_initBins()
 {
 	for (int i = 0; i < _size; ++i) {
-		_bins[i]._base.setX(i + _hMargin);
+		_bins[i]._base.setX(i + _firstBinOffset());
 		_bins[i]._base.setY(0);
 		_bins[i]._val.setX(_bins[i]._base.x());
 		_bins[i]._val.setY(_bins[i]._base.y());
@@ -852,6 +859,8 @@ void Graph::setBase(int b)
 	if (b == _bins[0]._base.y()) // Nothing to do.
 		return;
 
+	_label.setBoxAppearance(_label._color, _labelSize, height());
+
 	for (int i = 0; i < _size; ++i) {
 		mod = _bins[i].mod();
 		_bins[i]._base.setY(b);
@@ -870,24 +879,29 @@ void Graph::setHeight(int h)
 }
 
 /**
- * @brief Set the size of the white space added on both sides of the Graph.
+ * @brief Set the color and the dimensions of the graph's label.
  *
- * @param hMargin: the size of the white space in pixels.
+ * @param f: The font to be used to draw the labels.
+ * @param col: The color of the ComboGraph's label.
+ * @param lSize: the size of the graph's label in pixels.
+ * @param hMargin: the size of the white margine space in pixels.
  */
-void Graph::setHMargin(int hMargin)
+void Graph::setLabelAppearance(ksplot_font *f, Color col, int lSize, int hMargin)
 {
 	if (!_size)
 		return;
 
-	if (hMargin == _bins[0]._base.x()) // Nothing to do.
-		return;
+	_labelSize = lSize;
+	_hMargin = hMargin;
+
+	_label.setPos({_hMargin, base()});
+	_label.setFont(f);
+	_label.setBoxAppearance(col, lSize, height());
 
 	for (int i = 0; i < _size; ++i) {
-		_bins[i]._base.setX(i + hMargin);
+		_bins[i]._base.setX(i + _firstBinOffset());
 		_bins[i]._val.setX(_bins[i]._base.x());
 	}
-
-	_hMargin = hMargin;
 }
 
 /**
@@ -1312,6 +1326,8 @@ void Graph::draw(float size)
 	int lastPid(-1), b(0), boxH(_height * .3);
 	Rectangle taskBox;
 
+	_label.draw();
+
 	/*
 	 * Start by drawing a line between the base points of the first and
 	 * the last bin.
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index 287e0fb..8f530b0 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -506,7 +506,11 @@ public:
 	/** @brief Get a particular bin. */
 	const Bin &bin(int bin) const {return _bins[bin];}
 
-	void setHMargin(int hMargin);
+	/** Set the text of the graph's label. */
+	void setLabelText(std::string text) {_label.setText(text);}
+
+	void setLabelAppearance(ksplot_font *f, Color col,
+				int lSize, int hMargin);
 
 	/**
 	 * Check if this graph is Zero Suppressed. Zero Suppressed means that
@@ -521,7 +525,7 @@ public:
 	 */
 	void setZeroSuppressed(bool zs) {_zeroSuppress = zs;}
 
-private:
+protected:
 	/** Pointer to the model descriptor object. */
 	kshark_trace_histo	*_histoPtr;
 
@@ -537,6 +541,9 @@ private:
 	 */
 	int			_hMargin;
 
+	/** The horizontal size of the Graph's label. */
+	int			_labelSize;
+
 	/** The vertical size (height) of the Graph. */
 	int			_height;
 
@@ -549,9 +556,14 @@ private:
 	/** Hash table of ensemble's colors. */
 	ColorTable		*_ensembleColors;
 
+private:
+	TextBox		_label;
+
 	bool			_zeroSuppress;
 
-	void _initBins();
+	void	_initBins();
+
+	int	_firstBinOffset();
 };
 
 }; // KsPlot
-- 
2.25.1


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

* [PATCH 07/10] kernel-shark: Remove the hard-coded Idle PID
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (5 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 06/10] kernel-shark: Make the label part of the graph Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 08/10] kernel-shark: Add class Polyline to KsPlot namespace Yordan Karadzhov (VMware)
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

KernelShark plots differently all events coming from Idle tasks.
This is done in order to provide more intuitive visualization of
the Idleness of the system. So far the process Id of the Idle task
was assumed to be Zero. However this is true only for Linux systems.
In this patch we make the PID of the Idle task configurable.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 48 +++++++++++++++++++++++++++++++++------------
 src/KsPlotTools.hpp | 22 +++++++++------------
 2 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index d952f5e..529f737 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -755,12 +755,13 @@ Graph::Graph()
 : _histoPtr(nullptr),
   _bins(nullptr),
   _size(0),
-  _hMargin(30),
   _collectionPtr(nullptr),
   _binColors(nullptr),
   _ensembleColors(nullptr),
   _label(),
-  _zeroSuppress(false)
+  _idleSuppress(false),
+  _idlePid(0),
+  _drawBase(true)
 {}
 
 /**
@@ -774,12 +775,13 @@ Graph::Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct, KsPlot::ColorTa
 : _histoPtr(histo),
   _bins(new(std::nothrow) Bin[histo->n_bins]),
   _size(histo->n_bins),
-  _hMargin(30),
   _collectionPtr(nullptr),
   _binColors(bct),
   _ensembleColors(ect),
   _label(),
-  _zeroSuppress(false)
+  _idleSuppress(false),
+  _idlePid(0),
+  _drawBase(true)
 {
 	if (!_bins) {
 		_size = 0;
@@ -904,6 +906,20 @@ void Graph::setLabelAppearance(ksplot_font *f, Color col, int lSize, int hMargin
 	}
 }
 
+/**
+ * @brief Set Idle Suppression. If True, the bins containing Idle task records
+ *	  are not grouped together.
+ *
+ * @param is: If True, Idle is suppressed.
+ * @param ip: The process Id of the Idle task. If Idle is not suppressed, this
+ *	      value has no effect.
+ */
+void Graph::setIdleSuppressed(bool is, int ip)
+{
+	_idleSuppress = is;
+	_idlePid = ip;
+}
+
 /**
  * @brief Set the value of a given bin.
  *
@@ -916,7 +932,7 @@ void Graph::setBinValue(int bin, int val)
 }
 
 /**
- * @brief Set the Process Id (Front and Back) a given bin.
+ * @brief Set the Process Id (Front and Back) of a given bin.
  *
  * @param bin: Bin Id.
  * @param pidF: The Process Id detected at the from (first in time) edge of
@@ -1328,22 +1344,28 @@ void Graph::draw(float size)
 
 	_label.draw();
 
-	/*
-	 * Start by drawing a line between the base points of the first and
-	 * the last bin.
-	 */
-	drawLine(_bins[0]._base, _bins[_size - 1]._base, {}, size);
+	if (_drawBase) {
+		/*
+		 * Start by drawing a line between the base points of the first and
+		 * the last bin.
+		 */
+		drawLine(_bins[0]._base, _bins[_size - 1]._base, {}, size);
+	}
 
 	/* Draw as vartical lines all bins containing data. */
 	for (int i = 0; i < _size; ++i)
-		if (_bins[i]._idFront >= 0 || _bins[i]._idBack >= 0)
+		if (_bins[i]._idFront >= 0 || _bins[i]._idBack >= 0 ||
+		    _bins[i]._idFront == _idlePid || _bins[i]._idBack ==_idlePid)
 			if (_bins[i]._visMask & KS_EVENT_VIEW_FILTER_MASK) {
 				_bins[i]._size = size;
 				_bins[i].draw();
 			}
 
 	auto lamCheckEnsblVal = [this] (int v) {
-		return v > 0 || (v == 0 && !this->_zeroSuppress);
+		if (_idleSuppress && v == _idlePid)
+			return false;
+
+		return v >= 0;
 	};
 
 	/*
@@ -1424,4 +1446,4 @@ void Graph::draw(float size)
 	}
 }
 
-}; // KsPlot
+} // KsPlot
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index 8f530b0..5ce8f6f 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -449,7 +449,7 @@ public:
 	 */
 	Graph(const Graph &) = delete;
 
-	/* Disable moving. Same as copying.*/
+	/* Disable moving. Same as copying. */
 	Graph(Graph &&) = delete;
 
 	Graph(kshark_trace_histo *histo, KsPlot::ColorTable *bct,
@@ -512,18 +512,10 @@ public:
 	void setLabelAppearance(ksplot_font *f, Color col,
 				int lSize, int hMargin);
 
-	/**
-	 * Check if this graph is Zero Suppressed. Zero Suppressed means that
-	 * bins having Id value = 0 (Idle task records) are not grouped
-	 * together.
-	 */
-	bool zeroSuppressed(bool zs) {return _zeroSuppress;}
+	void setIdleSuppressed(bool is, int ip = 0);
 
-	/**
-	 * Set Zero Suppression. If True, the bins having Id value = 0 (Idle
-	 * task records) are not grouped together.
-	 */
-	void setZeroSuppressed(bool zs) {_zeroSuppress = zs;}
+	/** Draw the base line of the graph or not. */
+	void setDrawBase(bool b) {_drawBase = b;}
 
 protected:
 	/** Pointer to the model descriptor object. */
@@ -559,7 +551,11 @@ protected:
 private:
 	TextBox		_label;
 
-	bool			_zeroSuppress;
+	bool	_idleSuppress;
+
+	int	_idlePid;
+
+	bool	_drawBase;
 
 	void	_initBins();
 
-- 
2.25.1


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

* [PATCH 08/10] kernel-shark: Add class Polyline to KsPlot namespace
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (6 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 07/10] kernel-shark: Remove the hard-coded Idle PID Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 09/10] kernel-shark: Add VirtBridge and VirtGap classes Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 10/10] kernel-shark: Add double click interface to PlotObject Yordan Karadzhov (VMware)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

This is a simple plotting class that represents a poly-line.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 14 ++++++++++++++
 src/KsPlotTools.hpp | 16 ++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 529f737..9f98386 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -503,6 +503,20 @@ void Line::_draw(const Color &col, float size) const
 				 col.color_c_ptr(), size);
 }
 
+/**
+ * @brief Create a default polyline. All points are initialized at (0, 0).
+ *
+ * @param n: The number of points connected by the polyline.
+ */
+Polyline::Polyline(size_t n)
+: Shape(n)
+{}
+
+void Polyline::_draw(const Color &col, float size) const
+{
+	ksplot_draw_polyline(_points, _nPoints, col.color_c_ptr(), size);
+}
+
 /**
  * @brief Create a default polygon. All points are initialized at (0, 0).
  *
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index 5ce8f6f..4a7ca0a 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -253,6 +253,22 @@ private:
 	void _draw(const Color &col, float size = 1.) const override;
 };
 
+/** This class represents a polyline. */
+class Polyline : public Shape {
+public:
+	Polyline(size_t n);
+
+	/**
+	 * @brief Destroy the polyline object. Keep this destructor virtual.
+	 */
+	virtual ~Polyline() {}
+
+private:
+	Polyline() = delete;
+
+	void _draw(const Color &, float size = 1.) const override;
+};
+
 /** This class represents a polygon. */
 class Polygon : public Shape {
 public:
-- 
2.25.1


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

* [PATCH 09/10] kernel-shark: Add VirtBridge and VirtGap classes
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (7 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 08/10] kernel-shark: Add class Polyline to KsPlot namespace Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  2020-12-09 13:45 ` [PATCH 10/10] kernel-shark: Add double click interface to PlotObject Yordan Karadzhov (VMware)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The two simple plotting classes will be used to visualise the
guest->host data correlations.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 22 +++++++++++++++++++++
 src/KsPlotTools.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 9f98386..8d38009 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -1460,4 +1460,26 @@ void Graph::draw(float size)
 	}
 }
 
+void VirtGap::_draw(const Color &col, float size) const
+{
+	if (_entryPoint.x() - _exitPoint.x() < 4)
+		return;
+
+	Point p0(_exitPoint.x() + _size, _exitPoint.y());
+	Point p1(_exitPoint.x() + _size, _exitPoint.y() - _height);
+	Point p2(_entryPoint.x() - _size , _entryPoint.y());
+	Point p3(_entryPoint.x() - _size , _entryPoint.y() - _height);
+
+	Rectangle g;
+
+	g.setPoint(0, p0);
+	g.setPoint(1, p1);
+	g.setPoint(2, p2);
+	g.setPoint(3, p3);
+
+	g._color = {255, 255, 255}; // The virt. gap is always white.
+	g.setFill(false);
+	g.draw();
+}
+
 } // KsPlot
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index 4a7ca0a..b9b93f3 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -578,6 +578,53 @@ private:
 	int	_firstBinOffset();
 };
 
+/**
+ * This class represents the graphical element visualizing how the execution
+ * goes from the host to the guest and back.
+ */
+class VirtBridge : public Polyline {
+public:
+	/** Create a default VirtBridge. */
+	VirtBridge() : Polyline(4) {}
+
+	/* Keep this destructor virtual. */
+	virtual ~VirtBridge() {}
+
+	/** Set the coordinates of the EntryHost point of the VirtBridge. */
+	void setEntryHost(int x, int y) {setPoint(0, x, y);}
+
+	/** Set the coordinates of the EntryGuest point of the VirtBridge. */
+	void setEntryGuest(int x, int y) {setPoint(1, x, y);}
+
+	/** Set the coordinates of the ExitGuest point of the VirtBridge. */
+	void setExitGuest(int x, int y) {setPoint(2, x, y);}
+
+	/** Set the coordinates of the ExitHost point of the VirtBridge. */
+	void setExitHost(int x, int y) {setPoint(3, x, y);}
+};
+
+/**
+ * This class represents the graphical element visualizing the time interval
+ * in the guest during which the execution has been returned to the host.
+ */
+class VirtGap : public Shape {
+public:
+	/** Create a VirtGap with height "h". */
+	VirtGap(int h) :_height(h) {}
+
+	/**  The point where the execution exits the VM. */
+	Point _exitPoint;
+
+	/** The point where the execution enters the VM. */
+	Point _entryPoint;
+
+private:
+	/** The vertical size (height) of the graphical element. */
+	int _height;
+
+	void _draw(const Color &col, float size) const;
+};
+
 }; // KsPlot
 
 #endif  /* _KS_PLOT_TOOLS_H */
-- 
2.25.1


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

* [PATCH 10/10] kernel-shark: Add double click interface to PlotObject
  2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
                   ` (8 preceding siblings ...)
  2020-12-09 13:45 ` [PATCH 09/10] kernel-shark: Add VirtBridge and VirtGap classes Yordan Karadzhov (VMware)
@ 2020-12-09 13:45 ` Yordan Karadzhov (VMware)
  9 siblings, 0 replies; 11+ messages in thread
From: Yordan Karadzhov (VMware) @ 2020-12-09 13:45 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

The interface consists of two virtual methods that have to be implemented
by the inheriting classes. The first implements the double-click action
of the object while the second one calculates the distance between the
object and the exact position of the mouse click. The second method is
used by the GUI to decide if the double-click action has to be executed
or not. The patch contains a simple method for retrieving the geometrical
center of a Shape. This helper method can be useful when implementing the
calculation of the distance in the inheriting classes.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/KsPlotTools.cpp | 31 +++++++++++++++++++++++++++++++
 src/KsPlotTools.hpp | 14 ++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp
index 8d38009..ac9c5b2 100644
--- a/src/KsPlotTools.cpp
+++ b/src/KsPlotTools.cpp
@@ -251,6 +251,21 @@ Color getColor(const ColorTable *colors, int id)
 	return {};
 }
 
+/**
+ * @brief A method to be implemented in the inheriting class. It calculates
+ *	  the distance between the position of the click and the shape. This
+ *	  distance is used by the GUI to decide if the corresponding
+ *	  "Double click" action of the shape must be executed. The default
+ *	  implementation returns infinity.
+ *
+ * @param x: The X coordinate of the click.
+ * @param y: The Y coordinate of the click.
+ */
+double PlotObject::distance(int x, int y) const
+{
+	return std::numeric_limits<double>::max();
+}
+
 /**
  * @brief Create a default Shape.
  */
@@ -298,6 +313,22 @@ Shape::~Shape() {
 	delete[] _points;
 }
 
+/** @brief Get the coordinates of the geometrical center of this shape. */
+ksplot_point Shape::center() const
+{
+	ksplot_point c = {0, 0};
+
+	for (size_t i = 0; i < _nPoints; ++i) {
+		c.x += _points[i].x;
+		c.y += _points[i].y;
+	}
+
+	c.x /= _nPoints;
+	c.y /= _nPoints;
+
+	return c;
+}
+
 /** Assignment operator. */
 void Shape::operator=(const Shape &s)
 {
diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp
index b9b93f3..c993181 100644
--- a/src/KsPlotTools.hpp
+++ b/src/KsPlotTools.hpp
@@ -103,6 +103,16 @@ public:
 			_draw(_color, _size);
 	}
 
+	/**
+	 * Generic action to be executed when the objects is double clicked.
+	 */
+	void doubleClick() const {
+		if (_visible)
+			_doubleClick();
+	}
+
+	virtual double distance(int x, int y) const;
+
 	/** Is this object visible. */
 	bool	_visible;
 
@@ -114,6 +124,8 @@ public:
 
 private:
 	virtual void _draw(const Color &col, float s) const = 0;
+
+	virtual void _doubleClick() const {}
 };
 
 /** List of graphical element. */
@@ -135,6 +147,8 @@ public:
 	/* Keep this destructor virtual. */
 	virtual ~Shape();
 
+	ksplot_point center() const;
+
 	void operator=(const Shape &s);
 
 	void setPoint(size_t i, int x, int y);
-- 
2.25.1


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

end of thread, other threads:[~2020-12-09 13:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 13:45 [PATCH 00/10] kernel-shark: Update the C++ tools for plotting Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 01/10] kernel-shark: Integrate streams with KsPlotTools Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 02/10] kernel-shark: Add getStreamColorTable() Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 03/10] kernel-shark: Redefine the args of KsPlot::getColor() Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 04/10] kernel-shark: Add TextBox class to KsPlot namespace Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 05/10] kernel-shark: Consistent method naming in KsPlotTools Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 06/10] kernel-shark: Make the label part of the graph Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 07/10] kernel-shark: Remove the hard-coded Idle PID Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 08/10] kernel-shark: Add class Polyline to KsPlot namespace Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 09/10] kernel-shark: Add VirtBridge and VirtGap classes Yordan Karadzhov (VMware)
2020-12-09 13:45 ` [PATCH 10/10] kernel-shark: Add double click interface to PlotObject Yordan Karadzhov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).