[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171110092336.5ea1c99a@gandalf.local.home>
Date: Fri, 10 Nov 2017 09:23:36 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: "Yordan Karadzhov (VMware)" <y.karadz@...il.com>
Cc: jan.kiszka@...mens.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/4] kernelshark: Adding infrastructure for GUI
plugins
On Fri, 10 Nov 2017 14:29:12 +0200
"Yordan Karadzhov (VMware)" <y.karadz@...il.com> wrote:
> --- a/kernel-shark.c
> +++ b/kernel-shark.c
> @@ -339,6 +339,96 @@ int kernelshark_load_file(struct shark_info *info, const char *file)
> return 0;
> }
>
> +static struct plugin_list {
> + struct plugin_list *next;
> + const char *file;
> +} *plugins;
> +static struct plugin_list **plugin_next = &plugins;
> +
> +static void add_plugin(const char *file)
> +{
> + struct stat st;
> + int ret;
> +
> + ret = stat(file, &st);
> + if (ret < 0) {
> + warning("plugin %s not found", file);
> + return;
> + }
> +
> + *plugin_next = calloc(sizeof(struct plugin_list), 1);
> + if (!*plugin_next) {
> + warning("failed to allocat memory for plugin");
> + return;
> + }
> +
> + (*plugin_next)->file = file;
> + plugin_next = &(*plugin_next)->next;
> +}
> +
> +static void handle_plugins(struct shark_info *info,
> + struct trace_view_store *store,
> + int task_id)
> +{
> + kshark_plugin_load_func func;
> + struct plugin_list *plugin;
> + void *handle;
> + char* func_name;
> + int fn_size = 0;
> +
> + switch (task_id) {
> + case KSHARK_PLUGIN_LOAD:
> + fn_size = asprintf(&func_name, KSHARK_PLUGIN_LOADER_NAME);
> + break;
> +
> + case KSHARK_PLUGIN_RELOAD:
> + 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) {
> + warning("failed to allocat memory for plugin function name");
> + return;
> + }
> +
> + for (plugin = plugins; plugin; plugin = plugin->next) {
> + handle = dlopen(plugin->file, RTLD_NOW | RTLD_GLOBAL);
> +
> + if (!handle) {
> + warning("cound not load plugin '%s'\n%s\n",
> + plugin->file, dlerror());
> + continue;
> + }
> +
> + func = dlsym(handle, func_name);
> + if (!func) {
> + warning("cound not find func '%s' in plugin '%s'\n%s\n",
> + func_name, plugin->file, dlerror());
> + continue;
> + }
> +
> + func(info, store);
> + }
> +
> + if (task_id == KSHARK_PLUGIN_UNLOAD) {
> + while ((plugin = plugins)) {
> + plugins = plugin->next;
> + free(plugin);
> + }
> +
> + plugin_next = &plugins;
> + }
> +
> + free(func_name);
> +}
> +
Break the move of the above functions into their own patch first, then
it is easier to see what changed here.
-- Steve
> static void
> /* Callback for the clicked signal of the Load button */
> load_clicked (gpointer data)
> @@ -353,6 +443,9 @@ load_clicked (gpointer data)
>
> kernelshark_load_file(info, filename);
>
> + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(info->treeview));
> + handle_plugins(info, TRACE_VIEW_STORE(model), KSHARK_PLUGIN_RELOAD);
> +
> g_free(filename);
> }
>
> @@ -1805,56 +1898,6 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
> return FALSE;
> }
>
> -static struct plugin_list {
> - struct plugin_list *next;
> - const char *file;
> -} *plugins;
> -static struct plugin_list **plugin_next = &plugins;
> -
> -static void add_plugin(const char *file)
> -{
> - struct stat st;
> - int ret;
> -
> - ret = stat(file, &st);
> - if (ret < 0) {
> - warning("plugin %s not found", file);
> - return;
> - }
> -
> - *plugin_next = calloc(sizeof(struct plugin_list), 1);
> - if (!*plugin_next)
> - die("failed to allocat memory for plugin");
> -
> - (*plugin_next)->file = file;
> - plugin_next = &(*plugin_next)->next;
> -}
> -
> -static void handle_plugins(struct shark_info *info)
> -{
> - kshark_plugin_load_func func;
> - struct plugin_list *plugin;
> - void *handle;
> -
> - while ((plugin = plugins)) {
> - plugins = plugin->next;
> -
> - handle = dlopen(plugin->file, RTLD_NOW | RTLD_GLOBAL);
> - free(plugin);
> - if (!handle) {
> - warning("cound not load plugin '%s'\n%s\n",
> - plugin->file, dlerror());
> - continue;
> - }
> - func = dlsym(handle, KSHARK_PLUGIN_LOADER_NAME);
> - if (!func) {
> - warning("cound not find func '%s' in plugin '%s'\n%s\n",
> - KSHARK_PLUGIN_LOADER_NAME, plugin->file, dlerror());
> - continue;
> - }
> - func(info);
> - }
> -}
>
Powered by blists - more mailing lists