Skip to contentSkip to conversation

kernel-shark: Move common APIs and definitions out to avoid duplication

PATCH New Hongzhan Chen 1 participant 2 messages Jan 17, 2022

lore
Share & tools
lore
#0 lore raw

cover kernel-shark: Move common APIs and definitions out to avoid duplication

Hi Yordan,

We decided to maintain new xenomai plugin in our xenomai tree at first because of concerns as we discussed so I do not send modified xenomai plugin patch to review anymore. But this patch is still meaningful to avoid code duplication.

Thanks for your patience and time to reveiw my patch. I have learned lots from your comments.

Regards

Hongzhan Chen

Hongzhan Chen (1):
kernel-shark: Move common APIs and definitions out to avoid
duplication

 src/KsPlugins.cpp           | 22 ++++++++++++
 src/KsPlugins.hpp           | 49 +++++++++++++++++++++++++
 src/plugins/SchedEvents.cpp | 71 ++++++-------------------------------
 src/plugins/common_sched.h  | 64 +++++++++++++++++++++++++++++++++
 src/plugins/sched_events.c  | 32 +----------------
 src/plugins/sched_events.h  |  5 +--
 6 files changed, 147 insertions(+), 96 deletions(-)
 create mode 100644 src/plugins/common_sched.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 kernel-shark: Move common APIs and definitions out to avoid duplication

To avoid code duplication, move some common APIs and definitions out from plugin SchedEvent to share with other plugins.

src/KsPlugins.cpp +22 -0
index ad9f478..f4fc35e 100644
@@ -11,6 +11,7 @@
 
 // C++
 #include<iostream>
+#include <limits>
 
 // KernelShark
 #include "KsPlugins.hpp"
@@ -414,3 +415,24 @@ void eventFieldIntervalPlot(KsCppArgV *argvCpp,
 			  << exc.what() << std::endl;
 	}
 }
+
+/**
+ * @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 LatencyBox::distance(int x, int y) const
+{
+	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;
+}
src/KsPlugins.hpp +48 -0

58 lines not on this page · raw message

src/plugins/SchedEvents.cpp +10 -61

112 lines not on this page · raw message

src/plugins/common_sched.h new file +64 -0

64 lines not on this page · raw message

src/plugins/sched_events.c +1 -31
index 198ed49..c3a4f47 100644
@@ -22,36 +22,6 @@
 
 /** Plugin context instance. */
 
-//! @cond Doxygen_Suppress
-
-typedef unsigned long long tep_num_field_t;
-
-#define PREV_STATE_SHIFT	((int) ((sizeof(ks_num_field_t) - 1) * 8))
-
-#define PREV_STATE_MASK		(((ks_num_field_t) 1 << 8) - 1)
-
-#define PID_MASK		(((ks_num_field_t) 1 << PREV_STATE_SHIFT) - 1)
-
-//! @endcond
-
-static void plugin_sched_set_pid(ks_num_field_t *field,
-				 tep_num_field_t pid)
-{
-	*field &= ~PID_MASK;
-	*field = pid & PID_MASK;
-}
-
-/**
- * @brief Retrieve the PID value from the data field stored in the
- *	  kshark_data_container object.
- *
- * @param field: Input location for the data field.
- */
-__hidden int plugin_sched_get_pid(ks_num_field_t field)
-{
-	return field & PID_MASK;
-}
-
 /* Use the most significant byte to store the value of "prev_state". */
 static void plugin_sched_set_prev_state(ks_num_field_t *field,
 					tep_num_field_t prev_state)
@@ -135,7 +105,7 @@ static void plugin_sched_swith_action(struct kshark_data_stream *stream,
 	struct tep_record *record = (struct tep_record *) rec;
 	struct plugin_sched_context *plugin_ctx;
 	unsigned long long next_pid, prev_state;
-	ks_num_field_t ks_field;
+	ks_num_field_t ks_field = 0;
 	int ret;
 
 	plugin_ctx = __get_context(stream->stream_id);
src/plugins/sched_events.h +1 -4
index a2ba4b4..1032075 100644
@@ -15,6 +15,7 @@
 // KernelShark
 #include "libkshark.h"
 #include "libkshark-plugin.h"
+#include "plugins/common_sched.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -55,10 +56,6 @@ struct plugin_sched_context {
 
 KS_DECLARE_PLUGIN_CONTEXT_METHODS(struct plugin_sched_context)
 
-/** The type of the data field stored in the kshark_data_container object. */
-typedef int64_t ks_num_field_t;
-
-int plugin_sched_get_pid(ks_num_field_t field);
 
 int plugin_sched_get_prev_state(ks_num_field_t field);
 
Signature · 1 line
2.17.1