Received: by 10.223.164.202 with SMTP id h10csp172022wrb; Fri, 10 Nov 2017 04:32:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMbh0Ct6vouGdfwrL78jmi9lFcHyd1ivwWhD3SGN1RRCOpveE2T/Uqg5wbyv7AHfNpyNpdMY X-Received: by 10.84.238.203 with SMTP id l11mr223182pln.194.1510317125109; Fri, 10 Nov 2017 04:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510317125; cv=none; d=google.com; s=arc-20160816; b=swxvXN0PlDBssEh1MLSkJxEYZok5HjFexpwSdng/X+ipgSM+QMYzPRNXF2fw9XifUl CMr817oqp5Q0SL/WQybJpQ/YfdSP7XgH07iUqpaip4NG30HtjohRABnekzmng57TmUjJ fdJYa2q4pFflsajXQn0PM8ogdm1egV+YgZUewPFuzRTfx7sGKfP6GgrfA7vG5eI86nVf 6F0PFjTV6G8Ncv2eCIRLZLnyVjHr3EoZoPfN8XUqRD/NtM17RQAH8ULfkg06Cm0GUDvB kpiRvHB1FD1W8aMi3tjMYZ/FD7y99j+dbw4gVgpgwaSbJxm+4sQGaNGOCAqIx/pzF2wZ Gryg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=A0ZuHmThPbkkkZjXQ2T5fqY2SSRnIxDycV34Woo03Yc=; b=O80KyvuPzOQArcIQBpDhG8liv+EeitX44/uKxQ0ZZmDv5owSVc+Ey8R0wmlLK5OooH x7qJmMv3UaIHUcQRal2RTvacLpbO2Jj46EFp8e5JGX07Wo+BrLHMlMiXZ1B0NcUsIxeI J55ytkEap+V3t/DA+bpmuXf4FnlGIBlRUZr9eEdT4a49SNhtATE5CoJWAlUgLwv6IDmT L2IkkDlBwS7GO+2L9Fc1uYOfkpoS0GFahuxKbMG2ViUp972VUIt/CPpww50S/O1wFVJl gxD+xXzv0+5sP0opzGhGNrZiYvI1dz+9ywxyfsyfyq87Gi+a9a+kk7GdVuzBobC57Ooh X5dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kXcK6Yb8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u136si8732328pgc.821.2017.11.10.04.31.53; Fri, 10 Nov 2017 04:32:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kXcK6Yb8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752750AbdKJMa1 (ORCPT + 82 others); Fri, 10 Nov 2017 07:30:27 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39317 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751583AbdKJMaZ (ORCPT ); Fri, 10 Nov 2017 07:30:25 -0500 Received: by mail-wm0-f68.google.com with SMTP id b189so2394209wmd.4 for ; Fri, 10 Nov 2017 04:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=A0ZuHmThPbkkkZjXQ2T5fqY2SSRnIxDycV34Woo03Yc=; b=kXcK6Yb8i5fMHVU2aF/cTE/R0UJAM4Z9lfmw8CStOToNyZH0MgrFso0Sq7SHrgsKSU E8bnuvmv33TFDzel7mVbDez0LmMccuxaYy6Wa3uJfq6jkGOosBiO6btGQTR/9T/N4l78 SSSvVbu+Oq7/7BvKyVxgfsAFRRPIgcgW79UfY0hFGDzlMaNlnjBY6gQRYrrto9asaeMR GtzMqD3kkV2H5mqBQqtzRDS6cYbFRXF+5pf3tJ3IKvYnqoFA0onehWlPzfDNNPdwhCUs xvsrIs6DytKxehFoaeX63mVbx5BS3iwKNZHwyy1WMMJMAp5pPVpLjoUOXfE6TQOuWnTg 3+lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=A0ZuHmThPbkkkZjXQ2T5fqY2SSRnIxDycV34Woo03Yc=; b=ebcdO1NIT/0W7PBknLc+YOEGk7+MUuDSa0B/jKYkFm8n0hbJ2kz4k169SXXi0HgrZZ PvCogprAfhS3RA9648phB09z/pnsJDH7IPQXMEtXrMYJeCD2FfATKU3LbsZPCoIbfXgy P/sXFGPKXtlC7YKZOIRLrpwSKW+RatxHGflEEhaBB059RAfV87LKAeVLJhQMa2f6Vhe+ RZ1w7AeihQ+nQfjv0Tgj1w8K0hpuA8lTF2VTqrORhbVa+6TKAQHkOKfAphKrGGK8abok RROMbrrrXC3iDIvbj8Knide+/pqIVl7L8Sh1bCuF+7zWjA4uydhl1b98j4bkTZVn5ska ZdsQ== X-Gm-Message-State: AJaThX6KID8tjs0XLFsxZQ+47tsGZqxxiEru3BxiWWRxENNxWHQ89dtI xdgG9Chp6B0LY1e6/RzU8IQ= X-Received: by 10.28.180.65 with SMTP id d62mr89447wmf.95.1510317024061; Fri, 10 Nov 2017 04:30:24 -0800 (PST) Received: from sc9-mailhost2.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id p4sm6196517wrf.36.2017.11.10.04.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Nov 2017 04:30:23 -0800 (PST) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: jan.kiszka@siemens.com, linux-kernel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v2 1/4] kernelshark: Adding infrastructure for GUI plugins Date: Fri, 10 Nov 2017 14:29:12 +0200 Message-Id: <20171110122915.24929-1-y.karadz@gmail.com> X-Mailer: git-send-email 2.15.0.rc0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Makefile modified in order to support building of GUI plugins. kshark_plugin_loader and kshark_plugin_unloader are modified kshark_plugin_reloader is defined and is called when the user loads a new trace data file. Signed-off-by: Yordan Karadzhov (VMware) --- Makefile | 31 ++++++++++-- kernel-shark.c | 150 +++++++++++++++++++++++++++++++++++++------------------- kshark-plugin.h | 22 ++++++++- 3 files changed, 146 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index 5c35143..8d0f16f 100644 --- a/Makefile +++ b/Makefile @@ -293,6 +293,8 @@ else print_shared_lib_compile = echo ' $(GUI)COMPILE SHARED LIB '$(GOBJ); print_plugin_obj_compile = echo ' $(GUI)COMPILE PLUGIN OBJ '$(GOBJ); print_plugin_build = echo ' $(GUI)BUILD PLUGIN '$(GOBJ); + print_gui_plugin_obj_compile = echo ' $(GUI)COMPILE GUI_PLUGIN OBJ '$(GOBJ); + print_gui_plugin_build = echo ' $(GUI)BUILD GUI_PLUGIN '$(GOBJ); print_static_lib_build = echo ' $(GUI)BUILD STATIC LIB '$(GOBJ); print_install = echo ' $(GUI)INSTALL '$(GSPACE)$1' to $(DESTDIR_SQ)$2'; endif @@ -317,6 +319,14 @@ do_plugin_build = \ ($(print_plugin_build) \ $(CC) $(CFLAGS) $(LDFLAGS) -shared -nostartfiles -o $@ $<) +do_compile_gui_plugin_obj = \ + ($(print_gui_plugin_obj_compile) \ + $(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $<) + +do_gui_plugin_build = \ + ($(print_gui_plugin_build) \ + $(CC) $(CFLAGS) $(LDFLAGS) -shared -nostartfiles -o $@ $<) + do_build_static_lib = \ ($(print_static_lib_build) \ $(RM) $@; $(AR) rcs $@ $^) @@ -373,13 +383,17 @@ PLUGIN_OBJS += plugin_tlb.o PLUGINS := $(PLUGIN_OBJS:.o=.so) +GUI_PLUGIN_OBJS = + +GUI_PLUGINS := $(GUI_PLUGIN_OBJS:.o=.so) + ALL_OBJS = $(TRACE_CMD_OBJS) $(KERNEL_SHARK_OBJS) $(TRACE_VIEW_MAIN_OBJS) \ - $(TRACE_GRAPH_MAIN_OBJS) $(TCMD_LIB_OBJS) $(PLUGIN_OBJS) + $(TRACE_GRAPH_MAIN_OBJS) $(TCMD_LIB_OBJS) $(PLUGIN_OBJS) $(GUI_PLUGIN_OBJS) CMD_TARGETS = trace_plugin_dir trace_python_dir tc_version.h libparsevent.a $(LIB_FILE) \ trace-cmd $(PLUGINS) $(BUILD_PYTHON) -GUI_TARGETS = ks_version.h trace-graph trace-view kernelshark +GUI_TARGETS = ks_version.h trace-graph trace-view kernelshark $(GUI_PLUGINS) TARGETS = $(CMD_TARGETS) $(GUI_TARGETS) @@ -401,7 +415,7 @@ gui: $(CMD_TARGETS) all_gui: $(GUI_TARGETS) show_gui_done -GUI_OBJS = $(KERNEL_SHARK_OBJS) $(TRACE_VIEW_MAIN_OBJS) $(TRACE_GRAPH_MAIN_OBJS) +GUI_OBJS = $(KERNEL_SHARK_OBJS) $(TRACE_VIEW_MAIN_OBJS) $(TRACE_GRAPH_MAIN_OBJS) $(GUI_PLUGIN_OBJS) gui_objs := $(sort $(GUI_OBJS)) @@ -447,6 +461,12 @@ $(PLUGIN_OBJS): %.o : $(src)/%.c $(PLUGINS): %.so: %.o $(Q)$(do_plugin_build) +$(GUI_PLUGIN_OBJS): %.o : $(src)/%.c + $(Q)$(do_compile_gui_plugin_obj) + +$(GUI_PLUGINS): %.so: %.o + $(Q)$(do_gui_plugin_build) + define make_version.h (echo '/* This file is automatically generated. Do not modify. */'; \ echo \#define VERSION_CODE $(shell \ @@ -549,7 +569,10 @@ cscope: force $(RM) cscope* find . -name '*.[ch]' | cscope -b -q -PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS)) $(subst .so,.install,$(PYTHON_PLUGINS)) +PLUGINS_INSTALL = +PLUGINS_INSTALL += $(subst .so,.install,$(PLUGINS)) +PLUGINS_INSTALL += $(subst .so,.install,$(GUI_PLUGINS)) +PLUGINS_INSTALL += $(subst .so,.install,$(PYTHON_PLUGINS)) define do_install $(print_install) \ diff --git a/kernel-shark.c b/kernel-shark.c index 89723c3..79b387a 100644 --- 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); +} + 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); - } -} static void sig_end(int sig) { @@ -1882,6 +1925,7 @@ void kernel_shark(int argc, char **argv) GtkWidget *spin; GtkWidget *check; GtkWidget *statusbar; + GtkTreeModel *model; int ret; int c; @@ -2495,7 +2539,8 @@ void kernel_shark(int argc, char **argv) gtk_widget_set_size_request(window, TRACE_WIDTH, TRACE_HEIGHT); - handle_plugins(info); + model = gtk_tree_view_get_model(GTK_TREE_VIEW(info->treeview)); + handle_plugins(info, TRACE_VIEW_STORE(model), KSHARK_PLUGIN_LOAD); gdk_threads_enter(); @@ -2510,6 +2555,9 @@ void kernel_shark(int argc, char **argv) info->ginfo->no_draw = FALSE; gtk_main (); gdk_threads_leave(); + + model = gtk_tree_view_get_model(GTK_TREE_VIEW(info->treeview)); + handle_plugins(info, TRACE_VIEW_STORE(model), KSHARK_PLUGIN_UNLOAD); } int main(int argc, char **argv) diff --git a/kshark-plugin.h b/kshark-plugin.h index 95ba797..81c09b5 100644 --- a/kshark-plugin.h +++ b/kshark-plugin.h @@ -17,19 +17,37 @@ * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +#include + +#include "event-parse.h" + #ifndef _KSHARK_PLUGIN_H #define _KSHARK_PLUGIN_H #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) -typedef int (*kshark_plugin_load_func)(void *info); -typedef int (*kshark_plugin_unload_func)(void *info); +typedef int (*kshark_plugin_load_func)(void *info, void *store); +typedef int (*kshark_plugin_unload_func)(void *info, void *store); + +typedef int (*kshark_plugin_event_handler_func)(struct pevent_record *record, + int task_id, + void *val); + +typedef int (*kshark_plugin_context_update_func)(struct pevent *pevent, int task_id); +enum gui_plugin_actions { + KSHARK_PLUGIN_LOAD, + KSHARK_PLUGIN_RELOAD, + KSHARK_PLUGIN_UNLOAD, +}; #endif -- 2.15.0.rc0 From 1583727045345906216@xxx Sat Nov 11 00:23:27 +0000 2017 X-GM-THRID: 1583727045345906216 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread