diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2016-10-05 14:49:13 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2016-10-05 14:49:13 -0400 |
commit | 5670dbf636d1d37842a69e884dfef5f2519a2384 (patch) | |
tree | 1f7ccd63f3740f7a08588c6b12174696b9810200 | |
parent | 5758cd040588d0fec656ee79d690920f894968ec (diff) | |
download | trace-cmd-5670dbf636d1d37842a69e884dfef5f2519a2384.tar.gz |
kernelshark: Add infrastructure to allow kernelshark to have plugins
Add a -p plugin command line option for kernelshark to accept a plugin that
can modify how kernelshark works. This is just adds a loader, currently
nothing uses it yet.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | kernel-shark.c | 60 | ||||
-rw-r--r-- | kshark-plugin.h | 35 |
2 files changed, 94 insertions, 1 deletions
diff --git a/kernel-shark.c b/kernel-shark.c index 58ab9d63..a7a75a80 100644 --- a/kernel-shark.c +++ b/kernel-shark.c @@ -29,12 +29,14 @@ #include <errno.h> #include <getopt.h> #include <libgen.h> +#include <dlfcn.h> #include "trace-compat.h" #include "trace-capture.h" #include "trace-cmd.h" #include "trace-gui.h" #include "kernel-shark.h" +#include "kshark-plugin.h" #include "event-utils.h" #include "version.h" @@ -1799,6 +1801,57 @@ 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(default_input_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); + } +} + static void sig_end(int sig) { fprintf(stderr, "kernelshark: Received SIGINT\n"); @@ -1835,7 +1888,7 @@ void kernel_shark(int argc, char **argv) gtk_init(&argc, &argv); - while ((c = getopt(argc, argv, "hvi:")) != -1) { + while ((c = getopt(argc, argv, "hvi:p:")) != -1) { switch(c) { case 'h': usage(basename(argv[0])); @@ -1848,6 +1901,9 @@ void kernel_shark(int argc, char **argv) case 'i': input_file = optarg; break; + case 'p': + add_plugin(optarg); + break; default: /* assume the other options are for gtk */ break; @@ -2435,6 +2491,8 @@ void kernel_shark(int argc, char **argv) gtk_widget_set_size_request(window, TRACE_WIDTH, TRACE_HEIGHT); + handle_plugins(info); + gdk_threads_enter(); /* diff --git a/kshark-plugin.h b/kshark-plugin.h new file mode 100644 index 00000000..95ba797a --- /dev/null +++ b/kshark-plugin.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License (not later!) + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses> + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +#ifndef _KSHARK_PLUGIN_H +#define _KSHARK_PLUGIN_H + +#define KSHARK_PLUGIN_LOADER kshark_plugin_loader +#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_UNLOADER_NAME MAKE_STR(KSHARK_PLUGIN_UNLOADER) + +typedef int (*kshark_plugin_load_func)(void *info); +typedef int (*kshark_plugin_unload_func)(void *info); + + +#endif |