Add infrastructure for plugins.
v5 cover Add infrastructure for plugins.
The infrastructure for plugins used by the Qt-based version of KernelShark is introduced in this series of patches. This is the last major component of the C API. The last patch adds a plugin for dealing with "sched" events.
This is version 5 of this series of patches. In this version I address the final comments made by Steven Rostedt in his review of v4. The criteria for deciding when to start plotting latencies ([PATCH v5 8/8]) will stay as a TODO action item.
Yordan Karadzhov (VMware) (8):
kernel-shark-qt: Add plugin infrastructure to be used by the Qt-baset
KS.
kernel-shark-qt: Add Plugin event handlers to session.
kernel-shark-qt: Add C++/C conversion for args of a plugin draw
function.
kernel-shark-qt: Make kshark_read_at() non-static.
kernel-shark-qt: Remove the TODO action in kshark_read_at()
kernel-shark-qt: Add src/plugins dir. to hold the source code of the
plugins
kernel-shark-qt: Tell Doxygen to enter ../src/plugins/
kernel-shark-qt: Add a plugin for sched events.
kernel-shark-qt/doc/dox_config | 2 +- kernel-shark-qt/src/CMakeLists.txt | 3 + kernel-shark-qt/src/KsPlugins.hpp | 51 ++++ kernel-shark-qt/src/libkshark-plugin.c | 290 +++++++++++++++++++ kernel-shark-qt/src/libkshark-plugin.h | 179 ++++++++++++ kernel-shark-qt/src/libkshark.c | 38 ++- kernel-shark-qt/src/libkshark.h | 20 ++ kernel-shark-qt/src/plugins/CMakeLists.txt | 27 ++ kernel-shark-qt/src/plugins/SchedEvents.cpp | 263 +++++++++++++++++ kernel-shark-qt/src/plugins/sched_events.c | 305 ++++++++++++++++++++ kernel-shark-qt/src/plugins/sched_events.h | 76 +++++ 11 files changed, 1248 insertions(+), 6 deletions(-) create mode 100644 kernel-shark-qt/src/KsPlugins.hpp create mode 100644 kernel-shark-qt/src/libkshark-plugin.c create mode 100644 kernel-shark-qt/src/libkshark-plugin.h create mode 100644 kernel-shark-qt/src/plugins/CMakeLists.txt create mode 100644 kernel-shark-qt/src/plugins/SchedEvents.cpp create mode 100644 kernel-shark-qt/src/plugins/sched_events.c create mode 100644 kernel-shark-qt/src/plugins/sched_events.h
Signature · 1 line
2.17.1
PATCH v5 1/8 kernel-shark-qt: Add plugin infrastructure to be used by the Qt-baset KS.
This patch adds infrastructure for loading/unloading of plugins. Each plugin is coupled to a specific type of trace event and is allowed to perform two types of actions.
The first action is executed once for each kshark_entry only at the time when the data is loaded. This action can modify (even completely rewrite) the content of the kshark_entrys generated from the trace events having the type of the plugin.
The second action can add graphical elements on top of the existing graphs generated by the Visualization model. This will become clear in the following patches. This action is executed once for each graph and this is happening every time when the Visualization model changes its state. It is very powerful and can be used not only for drawing, but also for performing arbitrary modifications on the data. The pointer to the model descriptor object can access the entire array of kshark_entries, which, in turn, could be used to modify those entries.
The plugin infrastructure of the Qt-baset KernelShark reuses the system of macros for loading/unloading, implemented for the original GTK version.
This version of the patch contains number of improvements suggested by Steven Rostedt. Thanks Steven!
--- kernel-shark-qt/src/CMakeLists.txt | 1 + kernel-shark-qt/src/libkshark-plugin.c | 290 +++++++++++++++++++++++++ kernel-shark-qt/src/libkshark-plugin.h | 179 +++++++++++++++ kernel-shark-qt/src/libkshark.h | 3 + 4 files changed, 473 insertions(+) create mode 100644 kernel-shark-qt/src/libkshark-plugin.c create mode 100644 kernel-shark-qt/src/libkshark-plugin.h
kernel-shark-qt/src/CMakeLists.txt +1 -0
@@ -3,6 +3,7 @@ message("\n src ...") message(STATUS "libkshark") add_library(kshark SHARED libkshark.c libkshark-model.c + libkshark-plugin.c libkshark-configio.c libkshark-collection.c)
kernel-shark-qt/src/libkshark-plugin.c new file +290 -0
290 lines not on this page · raw message
kernel-shark-qt/src/libkshark-plugin.h new file +179 -0
179 lines not on this page · raw message
kernel-shark-qt/src/libkshark.h +3 -0
@@ -121,6 +121,9 @@ struct kshark_context {/** List of Data collections. */ struct kshark_entry_collection *collections; + +/** List of Plugins. */ +struct kshark_plugin_list *plugins; };bool kshark_instance (struct kshark_context **kshark_ctx);
Signature · 1 line
2.17.1
PATCH v5 2/8 kernel-shark-qt: Add Plugin event handlers to session.
In reply to Yordan Karadzhov (VMware)Plugin event handlers are added to the Session context descriptor. The handlers are used to execute plugin-specific action (callback function) during the processing of the trace data.
--- kernel-shark-qt/src/libkshark.c | 21 +++++++++++++++++++++ kernel-shark-qt/src/libkshark.h | 14 ++++++++++++++ 2 files changed, 35 insertions(+)
kernel-shark-qt/src/libkshark.c +21 -0
@@ -33,6 +33,9 @@ static bool kshark_default_context(struct kshark_context **context)if (!kshark_ctx)return false; + kshark_ctx->event_handlers =NULL ; + kshark_ctx->plugins =NULL ; + kshark_ctx->show_task_filter =tracecmd_filter_id_hash_alloc (); kshark_ctx->hide_task_filter =tracecmd_filter_id_hash_alloc ();
@@ -217,6 +220,12 @@ void kshark_free(struct kshark_context *kshark_ctx)tracecmd_filter_id_hash_free (kshark_ctx->show_event_filter);tracecmd_filter_id_hash_free (kshark_ctx->hide_event_filter); +if (kshark_ctx->plugins) { +kshark_handle_plugins (kshark_ctx,KSHARK_PLUGIN_CLOSE ); +kshark_free_plugin_list (kshark_ctx->plugins); +kshark_free_event_handler_list (kshark_ctx->event_handlers); + } +kshark_free_task_list (kshark_ctx);if (seq.buffer)
@@ -564,6 +573,7 @@ static void free_rec_list(struct rec_list **rec_list, int n_cpus,static size_t get_records (struct kshark_context *kshark_ctx,struct rec_list ***rec_list,enum rec_type type) { +struct kshark_event_handler *evt_handler;struct event_filter *adv_filter;struct kshark_task_list *task;struct tep_record *rec;
@@ -608,6 +618,17 @@ static size_t get_records(struct kshark_context *kshark_ctx, entry = &temp_rec->entry;kshark_set_entry_values (kshark_ctx, rec, entry); + +/* Execute all plugin-provided actions (if any). */ + evt_handler = kshark_ctx->event_handlers; +while ((evt_handler =kshark_find_event_handler (evt_handler, + entry->event_id))) { + evt_handler->event_func (kshark_ctx, rec, entry); + evt_handler = evt_handler->next; +if (!evt_handler) + entry->visible &= ~KS_PLUGIN_UNTOUCHED_MASK ; + } + pid = entry->pid;/* Apply event filtering. */ ret =FILTER_MATCH ;
kernel-shark-qt/src/libkshark.h +14 -0
@@ -29,6 +29,9 @@ extern "C" {#include "event-parse.h" #include "trace-filter-hash.h" +// KernelShark +#include "libkshark-plugin.h" +/** * Kernel Shark entry contains all information from one trace record needed * in order to visualize the time-series of trace records. The part of the
@@ -124,6 +127,9 @@ struct kshark_context {/** List of Plugins. */ struct kshark_plugin_list *plugins; + +/** List of Plugin Event handlers. */ +struct kshark_event_handler *event_handlers; };bool kshark_instance (struct kshark_context **kshark_ctx);
@@ -160,6 +166,14 @@ enum kshark_filter_masks {/** Special mask used whene filtering events. */ KS_EVENT_VIEW_FILTER_MASK =1 <<2 , + +/* The next 4 bits are reserved for more KS_X_VIEW_FILTER_MASKs. */ + +/** +* Use this mask to check if the content of the entry has been accessed +* by a plugin-defined function. +*/ + KS_PLUGIN_UNTOUCHED_MASK = 1 << 7 };/** Filter type identifier. */
Signature · 1 line
2.17.1
PATCH v5 3/8 kernel-shark-qt: Add C++/C conversion for args of a plugin draw function.
In reply to Yordan Karadzhov (VMware)The draw function of a plugin has a type declared in C. However, the function needs to access some high level objects, defined in the C++ libraries. This patch adds instruments for converting the arguments of the plugin's draw function from C++ to C and from C to C++.
--- kernel-shark-qt/src/KsPlugins.hpp | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 kernel-shark-qt/src/KsPlugins.hpp
kernel-shark-qt/src/KsPlugins.hpp new file +51 -0
@@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ + +/* + * Copyright (C) 2018 VMware Inc, Yordan Karadzhov <[email protected]> + */ + +/** + * @file KsPlugins.hpp + * @brief KernelShark C++ plugin declarations. + */ + +#ifndef _KS_PLUGINS_H +#define _KS_PLUGINS_H + +// KernelShark +#include "libkshark-model.h" +#include "KsPlotTools.hpp" + +/** + * Structure representing the vector of C++ arguments of the drawing function + * of a plugin. + */ +struct KsCppArgV { + /** Pointer to the model descriptor object. */ + kshark_trace_histo *_histo; + + /** Pointer to the graph object. */ + KsPlot::Graph *_graph; + + /** + * Pointer to the list of shapes. All shapes created by the plugin + * will be added to this list. + */ + KsPlot::PlotObjList *_shapes; + + /** + * Convert the "this" pointer of the C++ argument vector into a + * C pointer. + */ + kshark_cpp_argv *toC() + { + return reinterpret_cast<kshark_cpp_argv *>(this); + } +}; + +/** + * Macro used to convert a C pointer into a pointer to KsCppArgV (C++ struct). + */ +#define KS_ARGV_TO_CPP(a) (reinterpret_cast<KsCppArgV *>(a)) + +#endif
Signature · 1 line
2.17.1
PATCH v5 4/8 kernel-shark-qt: Make kshark_read_at() non-static.
In reply to Yordan Karadzhov (VMware)kshark_read_at() function provides a thread-safe read of a record from a specific offset inside the trace.dat file. So far this function was used only in libkshark.c and was defined static. This patch makes the function non-static in order to make possible to use it from a plugin.
--- kernel-shark-qt/src/libkshark.c | 12 ++++++++++-- kernel-shark-qt/src/libkshark.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-)
kernel-shark-qt/src/libkshark.c +10 -2
@@ -830,8 +830,16 @@ ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx,return -ENOMEM ; } -static struct tep_record *kshark_read_at (struct kshark_context *kshark_ctx, -uint64_t offset) +/** +* @brief A thread-safe read of a record from a specific offset. +* +* @param kshark_ctx: Input location for the session context pointer. +* @param offset: the offset into the file to find the record. +* +* @returns The returned pevent_record must be freed. +*/ +struct tep_record *kshark_read_at (struct kshark_context *kshark_ctx, +uint64_t offset) {/* * It turns that tracecmd_read_at() is not thread-safe.
kernel-shark-qt/src/libkshark.h +3 -0
@@ -150,6 +150,9 @@ void kshark_free(struct kshark_context *kshark_ctx);char *kshark_dump_entry (const struct kshark_entry *entry); +struct tep_record *kshark_read_at (struct kshark_context *kshark_ctx, +uint64_t offset); +/** Bit masks used to control the visibility of the entry after filtering. */ enum kshark_filter_masks {/**
Signature · 1 line
2.17.1
PATCH v5 5/8 kernel-shark-qt: Remove the TODO action in kshark_read_at()
In reply to Yordan Karadzhov (VMware)The TODO message states that we have to understand why racecmd_read_at() is not thread-safe and see if this can be fixed. We now know why and we know that this cannot be fixed.
--- kernel-shark-qt/src/libkshark.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
kernel-shark-qt/src/libkshark.c +2 -3
@@ -842,9 +842,8 @@ struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx, uint64_t offset) {/* -* It turns that tracecmd_read_at() is not thread-safe. -* TODO: Understand why and see if this can be fixed. -* For the time being use a mutex to protect the access. +* Calling tracecmd_read_at() is not thread-safe. Use a mutex to +* protect the access. */ pthread_mutex_lock (&kshark_ctx->input_mutex);
Signature · 1 line
2.17.1
Re: [PATCH v5 5/8] kernel-shark-qt: Remove the TODO action in kshark_read_at()
Quoted 3 lines · On Thu, 20 Sep 2018 19:55:41 +0300 "Yordan Karadzhov (VMware)"…
The TODO message states that we have to understand why
racecmd_read_at()is not thread-safe and see if this can be fixed. We now know why and we know that this cannot be fixed.
I wouldn't say that it can not be fixed, but that it's hard to fix.
I'll update the change log.
Thanks!
-- Steve
Quoted 22 lines
Signed-off-by Yordan Karadzhov (VMware) <[email protected]>--- kernel-shark-qt/src/libkshark.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)kernel-shark-qt/src/libkshark.c +2
-3@@ -842,9 +842,8 @@ struct tep_record *kshark_read_at(struct kshark_context *kshark_ctx, uint64_t offset) {/* -* It turns that tracecmd_read_at() is not thread-safe. -* TODO: Understand why and see if this can be fixed. -* For the time being use a mutex to protect the access. +* Calling tracecmd_read_at() is not thread-safe. Use a mutex to +* protect the access. */ pthread_mutex_lock (&kshark_ctx->input_mutex);
PATCH v5 6/8 kernel-shark-qt: Add src/plugins dir. to hold the source code of the plugins
In reply to Yordan Karadzhov (VMware)Tell Cmake to enter src/plugins. Add a Cmake function for building plugin libraries.
--- kernel-shark-qt/src/CMakeLists.txt | 2 ++ kernel-shark-qt/src/plugins/CMakeLists.txt | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 kernel-shark-qt/src/plugins/CMakeLists.txt
kernel-shark-qt/src/CMakeLists.txt +2 -0
@@ -28,5 +28,7 @@ if (OPENGL_FOUND AND GLUT_FOUND) endif (OPENGL_FOUND AND GLUT_FOUND) +add_subdirectory(plugins) + configure_file( ${KS_DIR}/build/deff.h.cmake ${KS_DIR}/src/KsDeff.h)
kernel-shark-qt/src/plugins/CMakeLists.txt new file +22 -0
@@ -0,0 +1,22 @@ +message("\n src/plugins ...") + +function(BUILD_PLUGIN) + set(options ) + set(oneValueArgs NAME) + set(multiValueArgs SOURCE) + cmake_parse_arguments(ADD_PLUGIN "${options}" + ${oneValueArgs} + ${multiValueArgs} + ${ARGN}) + + message(STATUS ${ADD_PLUGIN_NAME}) + + add_library(${ADD_PLUGIN_NAME} SHARED ${ADD_PLUGIN_SOURCE}) + set_target_properties(${ADD_PLUGIN_NAME} PROPERTIES PREFIX "plugin-") + target_link_libraries(${ADD_PLUGIN_NAME} kshark) + +endfunction() + +set(PLUGIN_LIST "") + +set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
Signature · 1 line
2.17.1
PATCH v5 7/8 kernel-shark-qt: Tell Doxygen to enter ../src/plugins/
In reply to Yordan Karadzhov (VMware)This Patch adds ../src/plugins/ to the list of input locations used by Doxygen to search for documented source files.
--- kernel-shark-qt/doc/dox_config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark-qt/doc/dox_config +1 -1
@@ -4,7 +4,7 @@ DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "kernel-shark-qt" PROJECT_BRIEF = "Kernel Shark is a front-end reader of the Linux kernel tracing data." -INPUT = "../src/" +INPUT = ../src/ ../src/plugins/ SOURCE_BROWSER = YES QT_AUTOBRIEF = YES TAB_SIZE = 8
Signature · 1 line
2.17.1
PATCH v5 8/8 kernel-shark-qt: Add a plugin for sched events.
In reply to Yordan Karadzhov (VMware)The plugin is responsible for the following actions, specific for "sched" events:
1. Changes the value of the "pid" field of the "sched_switch" entries. This alows the sched_switch entry to be plotted as part of the "next" task.
2. On "sched_switch" event, the plugin registers the "next" task (if not registered already).
3. Plots in green the wake up latency of the task and in red the time the task was preempted by another task.
--- kernel-shark-qt/src/plugins/CMakeLists.txt | 5 + kernel-shark-qt/src/plugins/SchedEvents.cpp | 263 +++++++++++++++++ kernel-shark-qt/src/plugins/sched_events.c | 305 ++++++++++++++++++++ kernel-shark-qt/src/plugins/sched_events.h | 76 +++++ 4 files changed, 649 insertions(+) create mode 100644 kernel-shark-qt/src/plugins/SchedEvents.cpp create mode 100644 kernel-shark-qt/src/plugins/sched_events.c create mode 100644 kernel-shark-qt/src/plugins/sched_events.h
kernel-shark-qt/src/plugins/CMakeLists.txt +5 -0
@@ -19,4 +19,9 @@ endfunction() set(PLUGIN_LIST "") +BUILD_PLUGIN(NAME sched_events + SOURCE sched_events.c SchedEvents.cpp) +list(APPEND PLUGIN_LIST "sched_events default") # This plugin will be loaded by default +# list(APPEND PLUGIN_LIST "sched_events") # This plugin isn't loaded by default + set(PLUGINS ${PLUGIN_LIST} PARENT_SCOPE)
kernel-shark-qt/src/plugins/SchedEvents.cpp new file +263 -0
263 lines not on this page · raw message
kernel-shark-qt/src/plugins/sched_events.c new file +305 -0
305 lines not on this page · raw message
kernel-shark-qt/src/plugins/sched_events.h new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.17.1