Re: [PATCH 1/7] kernel-shark-qt: Add plugin infrastructure to be used by the Qt-baset KS.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 29 Aug 2018 19:42:18 +0300
"Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:

> 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 Vis. 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 Vis. model changes its state.
> It turns that this second plugin-specific action (callback function)

"It turns that"?


> is very powerful and can be used not only for drawing. It has an

Note, it's best to state what the other operations are when saying "and
can be used not only for". It's not polite to end a sentence like
that ;-)

What you should say is:

 "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."

Does that make sense?

-- Steve


> access (via the pointer to the model descriptor object) to the
> entire array of kshark_entries, hence it can be used to perform
> arbitrary modifications in the data.
> 
> The plugin infrastructure of the Qt-baset KernelShark reuses the system
> of macros for loading/unloading, implemented for the original GTK version.
> 
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
>
> +			fn_size = asprintf(&func_name,
> +					   KSHARK_PLUGIN_RELOADER_NAME);
> +			break;
> +
> +		case KSHARK_PLUGIN_UNLOAD:
> +			fn_size = asprintf(&func_name,
> +					   KSHARK_PLUGIN_UNLOADER_NAME);
> +			break;
> +
> +		default:
> +			return;
> +	}
> +
> +	if (fn_size <= 0) {
> +		fprintf(stderr,
> +			"failed to allocate memory for plugin function name");
> +		return;
> +	}
> +
> +	for (plugin = kshark_ctx->plugins; plugin; plugin = plugin->next) {
> +		if (task_id == KSHARK_PLUGIN_LOAD) {
> +			plugin->handle =
> +				dlopen(plugin->file, RTLD_NOW | RTLD_GLOBAL);
> +
> +			if (!plugin->handle) {
> +				fprintf(stderr,
> +					"cannot load plugin '%s'\n%s\n",
> +					plugin->file,
> +					dlerror());
> +
> +				continue;
> +			}
> +		}
> +
> +		func = dlsym(plugin->handle, func_name);
> +		if (!func) {
> +			fprintf(stderr,
> +				"cannot find func '%s' in plugin '%s'\n%s\n",
> +				func_name,
> +				plugin->file,
> +				dlerror());
> +
> +			dlclose(plugin->handle);
> +			plugin->handle = NULL;
> +			continue;
> +		}
> +
> +		func();
> +
> +		if (task_id == KSHARK_PLUGIN_UNLOAD && plugin->handle) {
> +			dlclose(plugin->handle);
> +			plugin->handle = NULL;
> +		}
> +	}
> +
> +	free(func_name);
> +}
> diff --git a/kernel-shark-qt/src/libkshark-plugin.h b/kernel-shark-qt/src/libkshark-plugin.h
> new file mode 100644
> index 0000000..7328197
> --- /dev/null
> +++ b/kernel-shark-qt/src/libkshark-plugin.h
> @@ -0,0 +1,159 @@
> +/* SPDX-License-Identifier: LGPL-2.1 */
> +
> +/*
> + * Copyright (C) 2016 Red Hat Inc, Steven Rostedt <srostedt@xxxxxxxxxx>
> + */
> +
> + /**
> +  *  @file    libkshark-plugin.h
> +  *  @brief   KernelShark plugins.
> +  */
> +
> +#ifndef _KSHARK_PLUGIN_H
> +#define _KSHARK_PLUGIN_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif // __cplusplus
> +
> +// trace-cmd
> +#include "event-parse.h"
> +
> +/* Quiet warnings over documenting simple structures */
> +//! @cond Doxygen_Suppress
> +
> +#define KSHARK_PLUGIN_LOADER kshark_plugin_loader
> +#define KSHARK_PLUGIN_RELOADER kshark_plugin_reloader
> +#define KSHARK_PLUGIN_UNLOADER kshark_plugin_unloader
> +
> +#define _MAKE_STR(x)	#x
> +#define MAKE_STR(x)	_MAKE_STR(x)
> +#define KSHARK_PLUGIN_LOADER_NAME MAKE_STR(KSHARK_PLUGIN_LOADER)
> +#define KSHARK_PLUGIN_RELOADER_NAME MAKE_STR(KSHARK_PLUGIN_RELOADER)
> +#define KSHARK_PLUGIN_UNLOADER_NAME MAKE_STR(KSHARK_PLUGIN_UNLOADER)
> +
> +struct kshark_context;
> +struct kshark_entry;
> +
> +//! @endcond
> +
> +/**
> + * A function type to be used when defining load/reload/unload plugin
> + * functions.
> + */
> +typedef int (*kshark_plugin_load_func)(void);
> +
> +struct kshark_cpp_argv;
> +
> +/** A function type to be used when defining plugin functions for drawing. */
> +typedef void
> +(*kshark_plugin_draw_handler_func)(struct kshark_cpp_argv *argv,
> +				   int val, int draw_action);
> +
> +/**
> + * A function type to be used when defining plugin functions for data
> + * manipulation.
> + */
> +typedef void
> +(*kshark_plugin_event_handler_func)(struct kshark_context *kshark_ctx,
> +				    struct tep_record *rec,
> +				    struct kshark_entry *e);
> +
> +/** Plugin action identifier. */
> +enum kshark_plugin_actions {
> +	/**
> +	 * Load plugins action. This action identifier is used when handling
> +	 * plugins.
> +	 */
> +	KSHARK_PLUGIN_LOAD,
> +
> +	/**
> +	 * Reload plugins action. This action identifier is used when handling
> +	 * plugins.
> +	 */
> +	KSHARK_PLUGIN_RELOAD,
> +
> +	/**
> +	 * Unload plugins action. This action identifier is used when handling
> +	 * plugins.
> +	 */
> +	KSHARK_PLUGIN_UNLOAD,
> +
> +	/**
> +	 * Task draw action. This action identifier is used by the plugin draw
> +	 * function.
> +	 */
> +	KSHARK_PLUGIN_TASK_DRAW,
> +
> +	/**
> +	 * CPU draw action. This action identifier is used by the plugin draw
> +	 * function.
> +	 */
> +	KSHARK_PLUGIN_CPU_DRAW,
> +};
> +
> +/**
> + * Plugin Event handler structure, defining the properties of the required
> + * kshark_entry.
> + */
> +struct kshark_event_handler {
> +	/** Pointer to the next Plugin Event handler. */
> +	struct kshark_event_handler		*next;
> +
> +	/** Unique Id ot the trace event type. */
> +	int					id;
> +
> +	/**
> +	 * Event action function. This action can be used to modify the content
> +	 * of all kshark_entries having Event Ids equal to "id".
> +	 */
> +	kshark_plugin_event_handler_func	event_func;
> +
> +	/**
> +	 * Draw action function. This action can be used to draw additional
> +	 * graphical elements (shapes) for all kshark_entries having Event Ids
> +	 * equal to "id".
> +	 */
> +	kshark_plugin_draw_handler_func		draw_func;
> +};
> +
> +struct kshark_event_handler *find_event_handler(struct kshark_event_handler *handlers,
> +						int event_id);
> +
> +void kshark_register_event_handler(struct kshark_event_handler **handlers,
> +				   int event_id,
> +				   kshark_plugin_event_handler_func	evt_func,
> +				   kshark_plugin_draw_handler_func	dw_func);
> +
> +void kshark_unregister_event_handler(struct kshark_event_handler **handlers,
> +				     int event_id,
> +				     kshark_plugin_event_handler_func	evt_func,
> +				     kshark_plugin_draw_handler_func	dw_func);
> +
> +void kshark_free_event_handler_list(struct kshark_event_handler *handlers);
> +
> +/** Linked list of plugins. */
> +struct kshark_plugin_list {
> +	/** Pointer to the next Plugin. */
> +	struct kshark_plugin_list	*next;
> +
> +	/** The plugin object file to load. */
> +	char			*file;
> +
> +	/** Plugin Event handler. */
> +	void			*handle;
> +};
> +
> +void kshark_register_plugin(struct kshark_context *kshark_ctx, const char *file);
> +
> +void kshark_unregister_plugin(struct kshark_context *kshark_ctx, const char *file);
> +
> +void kshark_free_plugin_list(struct kshark_plugin_list *plugins);
> +
> +void kshark_handle_plugins(struct kshark_context *kshark_ctx, int task_id);
> +
> +#ifdef __cplusplus
> +}
> +#endif // __cplusplus
> +
> +#endif // _KSHARK_PLUGIN_H
> diff --git a/kernel-shark-qt/src/libkshark.h b/kernel-shark-qt/src/libkshark.h
> index 2580449..fda133c 100644
> --- a/kernel-shark-qt/src/libkshark.h
> +++ b/kernel-shark-qt/src/libkshark.h
> @@ -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);




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux