linux-trace-devel.vger.kernel.org archive mirror
 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 v2 24/27] kernel-shark: Clickable sched_event plugin shapes
Date: Thu, 11 Feb 2021 12:32:02 +0200	[thread overview]
Message-ID: <20210211103205.418588-25-y.karadz@gmail.com> (raw)
In-Reply-To: <20210211103205.418588-1-y.karadz@gmail.com>

Here we make the latency boxes plotted by the sched_event plugin
clickable. When the box is clicked, the two events determining
the latency (sched_waking and sched_switch) are selected with the
markers. This is achieved by providing an implementation of the
corresponding interface of virtual functions in the definition
of the LatencyBox class. We also need to provide the plugin with
a pointer to the KsMainWindow object (the GUI itself) such that
the plugin can manipulate the markers.
---
 src/plugins/CMakeLists.txt  | 30 +++++++++++++++++--
 src/plugins/SchedEvents.cpp | 58 +++++++++++++++++++++++++++++++++++--
 src/plugins/sched_events.c  |  7 +++++
 src/plugins/sched_events.h  |  3 ++
 4 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index dc0c320..5e28368 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -17,10 +17,34 @@ function(BUILD_PLUGIN)
 
 endfunction()
 
+function(BUILD_GUI_PLUGIN)
+    set(options)
+    set(oneValueArgs NAME MOC)
+    set(multiValueArgs SOURCE)
+    cmake_parse_arguments(ADD_PLUGIN "${options}"
+                                     "${oneValueArgs}"
+                                     "${multiValueArgs}"
+                                     ${ARGN})
+
+    message(STATUS ${ADD_PLUGIN_NAME})
+
+    QT5_WRAP_CPP(plugin_moc ${ADD_PLUGIN_MOC})
+
+    add_library(${ADD_PLUGIN_NAME} SHARED ${plugin_moc} ${ADD_PLUGIN_SOURCE})
+    set_target_properties(${ADD_PLUGIN_NAME} PROPERTIES PREFIX "plugin-")
+    target_link_libraries(${ADD_PLUGIN_NAME} kshark kshark-gui)
+
+endfunction()
+
 set(PLUGIN_LIST "")
-BUILD_PLUGIN(NAME sched_events
-             SOURCE sched_events.c SchedEvents.cpp)
-list(APPEND PLUGIN_LIST "sched_events")
+
+if (Qt5Widgets_FOUND AND TT_FONT_FILE)
+
+    BUILD_GUI_PLUGIN(NAME sched_events
+                     SOURCE sched_events.c SchedEvents.cpp)
+    list(APPEND PLUGIN_LIST "sched_events")
+
+endif (Qt5Widgets_FOUND AND TT_FONT_FILE)
 
 BUILD_PLUGIN(NAME missed_events
              SOURCE missed_events.c MissedEvents.cpp)
diff --git a/src/plugins/SchedEvents.cpp b/src/plugins/SchedEvents.cpp
index c85a059..a81182e 100644
--- a/src/plugins/SchedEvents.cpp
+++ b/src/plugins/SchedEvents.cpp
@@ -20,15 +20,69 @@
 #include "plugins/sched_events.h"
 #include "KsPlotTools.hpp"
 #include "KsPlugins.hpp"
+#include "KsMainWindow.hpp"
 
 using namespace KsPlot;
 
+static KsMainWindow *ks_ptr;
+
+/**
+ * @brief Provide the plugin with a pointer to the KsMainWindow object (the GUI
+ * itself) such that the plugin can manipulate the GUI.
+ */
+void *plugin_set_gui_ptr(void *gui_ptr)
+{
+	ks_ptr = static_cast<KsMainWindow *>(gui_ptr);
+	return nullptr;
+}
+
+/**
+ * This class represents the graphical element visualizing the latency between
+ *  sched_waking and sched_switch events.
+ */
+class LatencyBox : public Rectangle
+{
+	/** On double click do. */
+	void _doubleClick() const override
+	{
+		ks_ptr->markEntry(_data[1]->entry, DualMarkerState::B);
+		ks_ptr->markEntry(_data[0]->entry, DualMarkerState::A);
+	}
+
+public:
+	/** The trace record data that corresponds to this LatencyBox. */
+	std::vector<kshark_data_field_int64 *>	_data;
+
+	/**
+	 * @brief Distance between the click and the shape. Used to decide if
+	 *	  the double click action must be executed.
+	 *
+	 * @param x: X coordinate of the click.
+	 * @param y: Y coordinate of the click.
+	 *
+	 * @returns If the click is inside the box, the distance is zero.
+	 *	    Otherwise infinity.
+	 */
+	double distance(int x, int y) const override
+	{
+		if (x < pointX(0) || x > pointX(2))
+			return std::numeric_limits<double>::max();
+
+		if (y < pointY(0) || y > pointY(1))
+			return std::numeric_limits<double>::max();
+
+		return 0;
+	}
+};
+
 static PlotObject *makeShape(std::vector<const Graph *> graph,
 			     std::vector<int> bins,
-			     std::vector<kshark_data_field_int64 *>,
+			     std::vector<kshark_data_field_int64 *> data,
 			     Color col, float size)
 {
-	Rectangle *rec = new KsPlot::Rectangle;
+	LatencyBox *rec = new LatencyBox;
+	rec->_data = data;
+
 	Point p0 = graph[0]->bin(bins[0])._base;
 	Point p1 = graph[0]->bin(bins[1])._base;
 	int height = graph[0]->height() * .3;
diff --git a/src/plugins/sched_events.c b/src/plugins/sched_events.c
index 1596880..ac4a7bf 100644
--- a/src/plugins/sched_events.c
+++ b/src/plugins/sched_events.c
@@ -216,3 +216,10 @@ int KSHARK_PLOT_PLUGIN_DEINITIALIZER(struct kshark_data_stream *stream)
 
 	return 1;
 }
+
+/** Initialize the control interface of the plugin. */
+void *KSHARK_MENU_PLUGIN_INITIALIZER(void *gui_ptr)
+{
+	printf("--> sched init menu\n");
+	return plugin_set_gui_ptr(gui_ptr);
+}
diff --git a/src/plugins/sched_events.h b/src/plugins/sched_events.h
index 4c57606..78cfda0 100644
--- a/src/plugins/sched_events.h
+++ b/src/plugins/sched_events.h
@@ -53,6 +53,7 @@ struct plugin_sched_context {
 	struct kshark_data_container	*sw_data;
 };
 
+/** A general purpose macro is used to define plugin context. */
 KS_DEFINE_PLUGIN_CONTEXT(struct plugin_sched_context);
 
 /** The type of the data field stored in the kshark_data_container object. */
@@ -65,6 +66,8 @@ int plugin_sched_get_prev_state(ks_num_field_t field);
 void plugin_draw(struct kshark_cpp_argv *argv, int sd, int pid,
 		 int draw_action);
 
+void *plugin_set_gui_ptr(void *gui_ptr);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.25.1


  parent reply	other threads:[~2021-02-11 10:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 10:31 [PATCH v2 00/27] Complete the KernelShark v2 transformation Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 01/27] kernel-shark: Add get_stream_object() Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 02/27] kernel-shark: Do proper reset in kshark_close_all() Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 03/27] kernel-shark: Restore the counting of event handlers Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 04/27] kernel-shark: Fix a misleading comment Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 05/27] kernel-shark: Count the number of readout interfaces Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 06/27] kernel-shark: Update KsUtils Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 07/27] kernel-shark: Update KsModels and KsSearchFSM Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 08/27] kernel-shark: Add trace data files for CI testing Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 09/27] kernel-shark: Add plugin tests Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 10/27] kernel-shark: Add model tests Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 11/27] kernel-shark: Update KsWidgetsLib Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 12/27] kernel-shark: Add combo point to Mark Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 13/27] kernel-shark: Add new methods to KsPlot::Mark Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 14/27] kernel-shark: Update the plotting example Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 15/27] kernel-shark: Search for font with Cmake at pre-build Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 16/27] kernel-shark: Update KsDualMarker and KsGLWidget Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 17/27] kernel-shark: Update KsTraceGraph and KsQuickContextMenu Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 18/27] kernel-shark: Update KsTraceViewer Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 19/27] kernel-shark: Update KsAdvFilteringDialog Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 20/27] kernel-shark: Update KsCaptureDialog Yordan Karadzhov (VMware)
2021-02-11 10:31 ` [PATCH v2 21/27] kernel-shark: Update KsSession Yordan Karadzhov (VMware)
2021-02-11 10:32 ` [PATCH v2 22/27] kernel-shark: Update MissedEvents plugin Yordan Karadzhov (VMware)
2021-02-11 10:32 ` [PATCH v2 23/27] kernel-shark: Update KsMainWindow and kernelshark.cpp Yordan Karadzhov (VMware)
2021-02-11 10:32 ` Yordan Karadzhov (VMware) [this message]
2021-02-11 10:32 ` [PATCH v2 25/27] kernel-shark: Show Task plots from command lime Yordan Karadzhov (VMware)
2021-02-11 10:32 ` [PATCH v2 26/27] kernel-shark: Add pkg-config configuration for libkshark Yordan Karadzhov (VMware)
2021-02-11 10:32 ` [PATCH v2 27/27] kernel-shark: Install libkshark-tepdata.h Yordan Karadzhov (VMware)
2021-02-11 15:02 ` [PATCH v2 00/27] Complete the KernelShark v2 transformation Steven Rostedt

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=20210211103205.418588-25-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 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).