diff mbox series

[6/6] kernel-shark: Handle the case when the marker points to a filtered entry

Message ID 20190515190911.20755-7-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Headers show
Series Various modifications and fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov May 15, 2019, 7:09 p.m. UTC
Markers can point to entries that are filtered out. In such a case
the filtered marker is plotted using a dashed line.

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsDualMarker.cpp  | 10 +++++++++
 kernel-shark/src/KsPlotTools.cpp   | 33 +++++++++++++++++++++++++++++-
 kernel-shark/src/KsPlotTools.hpp   | 11 +++++++++-
 kernel-shark/src/KsTraceViewer.cpp | 22 ++++++++++++--------
 4 files changed, 65 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsDualMarker.cpp b/kernel-shark/src/KsDualMarker.cpp
index 5dcbaae..755e246 100644
--- a/kernel-shark/src/KsDualMarker.cpp
+++ b/kernel-shark/src/KsDualMarker.cpp
@@ -79,9 +79,19 @@  bool KsGraphMark::set(const KsDataStore &data,
 		      kshark_trace_histo *histo,
 		      size_t pos, int cpuGraph, int taskGraph)
 {
+	uint8_t visFlags;
+
 	_isSet = true;
 	_pos = pos;
 	_ts = data.rows()[_pos]->ts;
+	visFlags = data.rows()[_pos]->visible;
+
+	if ((visFlags & KS_TEXT_VIEW_FILTER_MASK) &&
+	    (visFlags & KS_GRAPH_VIEW_FILTER_MASK))
+		_mark.setDashed(false);
+	else
+		_mark.setDashed(true);
+
 	_cpu = cpuGraph;
 	_task = taskGraph;
 
diff --git a/kernel-shark/src/KsPlotTools.cpp b/kernel-shark/src/KsPlotTools.cpp
index f95ada5..a8eddcd 100644
--- a/kernel-shark/src/KsPlotTools.cpp
+++ b/kernel-shark/src/KsPlotTools.cpp
@@ -379,6 +379,32 @@  void drawLine(const Point &a, const Point &b,
 			 size);
 }
 
+/**
+ * @brief Draw a dashed line between point "a" and point "b".
+ *
+ * @param a: The first finishing point of the line.
+ * @param b: The second finishing point of the line.
+ * @param col: The color of the line.
+ * @param size: The size of the line.
+ * @param period: The period of the dashed line.
+ */
+void drawDashedLine(const Point &a, const Point &b,
+		    const Color &col, float size, float period)
+{
+	int dx = b.x() - a.x(), dy = b.y() - a.y();
+	float mod = sqrt(dx * dx + dy * dy);
+	int n = mod / period;
+	Point p1, p2;
+
+	for (int i = 0; i < n; ++i) {
+		p1.setX(a.x() + (i + .25) * dx / n);
+		p1.setY(a.y() + (i + .25) * dy / n);
+		p2.setX(a.x() + (i + .75) * dx / n);
+		p2.setY(a.y() + (i + .75) * dy / n);
+		drawLine(p1, p2, col, size);
+	}
+}
+
 /** @brief Create a default line. The two points are initialized at (0, 0). */
 Line::Line()
 : Shape(2)
@@ -430,6 +456,7 @@  void Polygon::_draw(const Color &col, float size) const
  * @brief Create a default Mark.
  */
 Mark::Mark()
+: _dashed(false)
 {
 	_visible = false;
 	_cpu._color = Color(225, 255, 100);
@@ -440,7 +467,11 @@  Mark::Mark()
 
 void Mark::_draw(const Color &col, float size) const
 {
-	drawLine(_a, _b, col, size);
+	if (_dashed)
+		drawDashedLine(_a, _b, col, size, 3 * _cpu._size / size);
+	else
+		drawLine(_a, _b, col, size);
+
 	_cpu.draw();
 	_task.draw();
 }
diff --git a/kernel-shark/src/KsPlotTools.hpp b/kernel-shark/src/KsPlotTools.hpp
index 11c49eb..ee447f1 100644
--- a/kernel-shark/src/KsPlotTools.hpp
+++ b/kernel-shark/src/KsPlotTools.hpp
@@ -204,7 +204,10 @@  private:
 };
 
 void drawLine(const Point &a, const Point &b,
-	      const Color &col, float s);
+	      const Color &col, float size);
+
+void drawDashedLine(const Point &a, const Point &b,
+		    const Color &col, float size, float period);
 
 /** This class represents a straight line. */
 class Line : public Shape {
@@ -326,6 +329,9 @@  public:
 
 	void setTaskVisible(bool v);
 
+	/** If True, the Mark will be plotted as a dashed line. */
+	void setDashed(bool d) {_dashed = d;}
+
 private:
 	void _draw(const Color &col, float size = 1.) const override;
 
@@ -340,6 +346,9 @@  private:
 
 	/** A point indicating the position of the Mark in a Task graph. */
 	Point _task;
+
+	/* If True, plot the Mark as a dashed line. */
+	bool _dashed;
 };
 
 /** This class represents a KernelShark graph's bin. */
diff --git a/kernel-shark/src/KsTraceViewer.cpp b/kernel-shark/src/KsTraceViewer.cpp
index 04a38b8..05977c3 100644
--- a/kernel-shark/src/KsTraceViewer.cpp
+++ b/kernel-shark/src/KsTraceViewer.cpp
@@ -493,15 +493,19 @@  void KsTraceViewer::markSwitch()
 		QModelIndex index =
 			_proxyModel.mapFromSource(_model.index(row, 0));
 
-		/*
-		 * The row of the active marker will be colored according to
-		 * the assigned property of the current state of the Dual
-		 * marker. Auto-scrolling is temporarily disabled because we
-		 * do not want to scroll to the position of the marker yet.
-		 */
-		_view.setAutoScroll(false);
-		_view.selectRow(index.row());
-		_view.setAutoScroll(true);
+		if (index.isValid()) {
+			/*
+			 * The row of the active marker will be colored according to
+			 * the assigned property of the current state of the Dual
+			 * marker. Auto-scrolling is temporarily disabled because we
+			 * do not want to scroll to the position of the marker yet.
+			 */
+			_view.setAutoScroll(false);
+			_view.selectRow(index.row());
+			_view.setAutoScroll(true);
+		} else {
+			_view.clearSelection();
+		}
 	} else {
 		_view.clearSelection();
 	}