From patchwork Wed Jan 22 14:59:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11345879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10FA117EA for ; Wed, 22 Jan 2020 15:00:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E33702467A for ; Wed, 22 Jan 2020 15:00:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F54xntWU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725940AbgAVPAK (ORCPT ); Wed, 22 Jan 2020 10:00:10 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35505 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbgAVPAK (ORCPT ); Wed, 22 Jan 2020 10:00:10 -0500 Received: by mail-lj1-f195.google.com with SMTP id j1so7175018lja.2 for ; Wed, 22 Jan 2020 07:00:07 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=GFfy6wL/teGiwg0SM8LV1Kej7UWruPwH8gtWUyWMYXk=; b=F54xntWUqs4gbH85Kv0+yoz9uEZHohf6rYSvBWQ/WNmJGUNTztrSsgGbCYgDdL8su4 2VJVdHpyxLDD1CiJnNxDfsSq9IQ2AwzuyWQ9spv6W0rhnonfzxCOdSB4Qj2LslK8u4xr 7Sb6nhVzef9VxaPo6W0PzAidjU/+rfE/S+Xx1oG0GmiSpVihCcA59YcX4UvDeB38Ua1o txvz/bQCj99ZolMZqqoBSXx3g1Z8TRWK9/16clfSYDtoyaCRK3kjnctPB2sOESgQhUjO LuC9OBToahtrLgyg1C6E3uSEkxOgk/IlH84l8WCLfXycxtSt/HN4XqcQNgs92mO+MF1q qqBg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=GFfy6wL/teGiwg0SM8LV1Kej7UWruPwH8gtWUyWMYXk=; b=NZzJ55XLM7D2YQ69BO35sABEqU0YIYfKsR97ODarbQp2jJvzLt3+uLPH5v4t2A36+1 aZF5MT7orSwIlACtgQPWHaE2srbXShK3n43SSxVlRXuKFHHwXKeaTrcd+/vQCF/lgPOg tweda4/6ACSk7Wj4snDI6mVWoZYgGpyzajX2IHUnnZM692MqZBRS3Jvsi57ZLLo5tsQ3 I6N3pDtyrz6BHdKAb0ofxp+kxWdmECAGPICGbpaVVT+ZErHFeDy9hZSh6foxNUOSOUCx WFDEYzc3tq5nkDqWf9utcLA2ACRqyCcTlR46AMtCQGv0SkshAy1t+2ENUYuF3+T7DAZE cNiQ== X-Gm-Message-State: APjAAAV6CXe+KYGByrk+LQyX3kOvb9JnL9WFB60EuUVvTxrLqP2029Kz R6hIvsK/exSZjfjmUOp7p+dlo599 X-Google-Smtp-Source: APXvYqy2q1Ht4m++an7bzyM5TYKxGWb+5L21lySCgPfGQn5dQ4Dxah8nesRoXfzP3IR2Eq0QA27cgA== X-Received: by 2002:a2e:81c7:: with SMTP id s7mr20201514ljg.3.1579705206886; Wed, 22 Jan 2020 07:00:06 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id l7sm20722803lfc.80.2020.01.22.07.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 07:00:06 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 1/7] trace-cmd,libtraceevent: Plugin options rework Date: Wed, 22 Jan 2020 16:59:56 +0200 Message-Id: <20200122150002.763233-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com> References: <20200122150002.763233-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When registering a plugin option, the current API allows to set an alias to the option's plugin. This logic complicates the implementation, but is not used by any existing plugin. In order to simplify the libtracevent API, these changes are introduced, related to plugin options: - Removed "plugin_alias" from options and all logic associated with it. - Renamed "file" field to "plugin", the new name describes more closely its purpose. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/traceevent/event-parse.h | 13 +------- lib/trace-cmd/trace-ftrace.c | 4 +-- lib/trace-cmd/trace-plugin.c | 5 --- lib/traceevent/event-plugin.c | 41 +++++++----------------- lib/traceevent/plugins/plugin_function.c | 6 ++-- 5 files changed, 17 insertions(+), 52 deletions(-) diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h index 52bafa5..72f7aaf 100644 --- a/include/traceevent/event-parse.h +++ b/include/traceevent/event-parse.h @@ -56,9 +56,8 @@ typedef int (*tep_plugin_unload_func)(struct tep_handle *tep); struct tep_plugin_option { struct tep_plugin_option *next; void *handle; - char *file; + char *plugin; char *name; - char *plugin_alias; char *description; const char *value; void *priv; @@ -84,7 +83,6 @@ struct tep_plugin_option { * struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = { * { * .name = "option-name", - * .plugin_alias = "override-file-name", (optional) * .description = "description of option to show users", * }, * { @@ -94,27 +92,18 @@ struct tep_plugin_option { * * Array must end with .name = NULL; * - * - * .plugin_alias is used to give a shorter name to access - * the vairable. Useful if a plugin handles more than one event. - * * If .value is not set, then it is considered a boolean and only * .set will be processed. If .value is defined, then it is considered * a string option and .set will be ignored. - * - * TEP_PLUGIN_ALIAS: (optional) - * The name to use for finding options (uses filename if not defined) */ #define TEP_PLUGIN_LOADER tep_plugin_loader #define TEP_PLUGIN_UNLOADER tep_plugin_unloader #define TEP_PLUGIN_OPTIONS tep_plugin_options -#define TEP_PLUGIN_ALIAS tep_plugin_alias #define _MAKE_STR(x) #x #define MAKE_STR(x) _MAKE_STR(x) #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER) #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER) #define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS) -#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS) enum tep_format_flags { TEP_FIELD_IS_ARRAY = 1, diff --git a/lib/trace-cmd/trace-ftrace.c b/lib/trace-cmd/trace-ftrace.c index 20bf71f..f251ad1 100644 --- a/lib/trace-cmd/trace-ftrace.c +++ b/lib/trace-cmd/trace-ftrace.c @@ -12,14 +12,14 @@ struct tep_plugin_option trace_ftrace_options[] = { { + .plugin = "ftrace", .name = "tailprint", - .plugin_alias = "fgraph", .description = "Print function name at function exit in function graph", }, { + .plugin = "ftrace", .name = "depth", - .plugin_alias = "fgraph", .description = "Show the depth of each entry", }, diff --git a/lib/trace-cmd/trace-plugin.c b/lib/trace-cmd/trace-plugin.c index 6bec18b..ce2f062 100644 --- a/lib/trace-cmd/trace-plugin.c +++ b/lib/trace-cmd/trace-plugin.c @@ -100,7 +100,6 @@ load_plugin(struct trace_plugin_context *trace, const char *path, struct trace_plugin_list **plugin_list = data; tracecmd_plugin_load_func func; struct trace_plugin_list *list; - const char *alias; char *plugin; void *handle; int ret; @@ -118,10 +117,6 @@ load_plugin(struct trace_plugin_context *trace, const char *path, goto out_free; } - alias = dlsym(handle, TRACECMD_PLUGIN_ALIAS_NAME); - if (!alias) - alias = file; - func = dlsym(handle, TRACECMD_PLUGIN_LOADER_NAME); if (!func) { warning("could not find func '%s' in plugin '%s'\n%s\n", diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index 30c1526..bbe87d4 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -113,11 +113,10 @@ char **tep_plugin_list_options(void) for (reg = registered_options; reg; reg = reg->next) { for (op = reg->options; op->name; op++) { - char *alias = op->plugin_alias ? op->plugin_alias : op->file; char **temp = list; int ret; - ret = asprintf(&name, "%s:%s", alias, op->name); + ret = asprintf(&name, "%s:%s", op->plugin, op->name); if (ret < 0) goto err; @@ -163,20 +162,14 @@ update_option(const char *file, struct tep_plugin_option *option) struct trace_plugin_options *op; char *plugin; int ret = 0; + char *p; - if (option->plugin_alias) { - plugin = strdup(option->plugin_alias); - if (!plugin) - return -1; - } else { - char *p; - plugin = strdup(file); - if (!plugin) - return -1; - p = strstr(plugin, "."); - if (p) - *p = '\0'; - } + plugin = strdup(file); + if (!plugin) + return -1; + p = strstr(plugin, "."); + if (p) + *p = '\0'; /* first look for named options */ for (op = trace_plugin_options; op; op = op->next) { @@ -274,16 +267,10 @@ find_registered_option(const char *plugin, const char *option) { struct registered_plugin_options *reg; struct tep_plugin_option *op; - const char *op_plugin; for (reg = registered_options; reg; reg = reg->next) { for (op = reg->options; op->name; op++) { - if (op->plugin_alias) - op_plugin = op->plugin_alias; - else - op_plugin = op->file; - - if (plugin && strcmp(plugin, op_plugin) != 0) + if (plugin && strcmp(plugin, op->plugin) != 0) continue; if (strcmp(option, op->name) != 0) continue; @@ -404,8 +391,7 @@ void tep_plugin_print_options(struct trace_seq *s) for (op = reg->options; op->name; op++) { if (op != reg->options) trace_seq_printf(s, "------------\n"); - print_op_data(s, "file", op->file); - print_op_data(s, "plugin", op->plugin_alias); + print_op_data(s, "plugin", op->plugin); print_op_data(s, "option", op->name); print_op_data(s, "desc", op->description); print_op_data(s, "value", op->value); @@ -444,7 +430,6 @@ load_plugin(struct tep_handle *tep, const char *path, struct tep_plugin_option *options; tep_plugin_load_func func; struct tep_plugin_list *list; - const char *alias; char *plugin; void *handle; int ret; @@ -462,14 +447,10 @@ load_plugin(struct tep_handle *tep, const char *path, goto out_free; } - alias = dlsym(handle, TEP_PLUGIN_ALIAS_NAME); - if (!alias) - alias = file; - options = dlsym(handle, TEP_PLUGIN_OPTIONS_NAME); if (options) { while (options->name) { - ret = update_option(alias, options); + ret = update_option(file, options); if (ret < 0) goto out_free; options++; diff --git a/lib/traceevent/plugins/plugin_function.c b/lib/traceevent/plugins/plugin_function.c index 938b741..8c36920 100644 --- a/lib/traceevent/plugins/plugin_function.c +++ b/lib/traceevent/plugins/plugin_function.c @@ -22,21 +22,21 @@ static int cpus = -1; struct tep_plugin_option plugin_options[] = { { + .plugin = "ftrace", .name = "parent", - .plugin_alias = "ftrace", .description = "Print parent of functions for function events", }, { + .plugin = "ftrace", .name = "indent", - .plugin_alias = "ftrace", .description = "Try to show function call indents, based on parents", .set = 1, }, { + .plugin = "ftrace", .name = "offset", - .plugin_alias = "ftrace", .description = "Show function names as well as their offsets", .set = 0, From patchwork Wed Jan 22 14:59:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11345877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA0916C1 for ; Wed, 22 Jan 2020 15:00:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B7EEF2467A for ; Wed, 22 Jan 2020 15:00:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U6ZVuTSb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725933AbgAVPAK (ORCPT ); Wed, 22 Jan 2020 10:00:10 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41155 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbgAVPAK (ORCPT ); Wed, 22 Jan 2020 10:00:10 -0500 Received: by mail-lj1-f195.google.com with SMTP id h23so7154083ljc.8 for ; Wed, 22 Jan 2020 07:00:08 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=5cTGrODYd3dJjy50DGZIcltWX7fMy2sP1MkBDzwPeqw=; b=U6ZVuTSbSDf+HGLZrhmZXemqPGHYvGrP4hfS2++o3i550Sdqk1LX0UaXYBzU0Xqe3d 84NlG48dve0mjytSKPW8zpy+xTZIftE54xZtU3C3/+51PdZBAnHd7L6DeYo4lvRECTQy 71NQU0XMyJjZeA9wQQBYotAaJSVq+wOi0dUNEKzg9oNvsKyR7EEx/59jX2gRTdR3x9K6 gj0QQnuHBC1M7hXzk0FIfULcU3Z898BqiA2JWkgqZJwAhQWBAmuisKysdUEEEEHapJyQ eXlW0VzTBtqJdOd57bdRnjRkrIbzymKyO9KEbLoPYOu7ooVqVVf14FtapKOhC8KPFI6K ndIA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=5cTGrODYd3dJjy50DGZIcltWX7fMy2sP1MkBDzwPeqw=; b=MoIanmVK6kjTp1y7zJ9Sxzv4yrJvenrgxDkNfnF/xPUYlR3lc7zts5ig21chP7GcgN vna1r9iFU1cUMp76EX6Kt+mOPtU6FC5HGvQ9uxYze1xI/sr45n3oVMrycoOHnWCqxCQq 2waf9D9rMzt5BVHme0wb5UGD5RTP/f5uYCKRfH8GxrpUATFX3d3uVto1eoH9uJf1Pmkq S0QHmXiq3PWGY0ITO5ZLQoBWnS2QksBwRlo+Ol/vA49A3oaNwbYDE3OrPu/LaYW5IgS1 mIW4t/9MxDCmNoyGFJaV49mqvq3qm18t/+rA2K+Oh7jBY0O/2srhcAsp8Ox3w3dH4PPv bbxQ== X-Gm-Message-State: APjAAAW/aLhpgFfvMIaJq1ot0isEtsAw1+8gPHbPzWN6iYLZtFgvJCny UQ3/VaZ+1fqJti145FhZjWP92J9a X-Google-Smtp-Source: APXvYqxbd7M8lLtxbnrgWT6WniDH47DxPl0clGefUQX7G7t8bdIXmUUvlgb3tW5+8NnY7CT3C2foLw== X-Received: by 2002:a2e:3309:: with SMTP id d9mr19783067ljc.262.1579705208196; Wed, 22 Jan 2020 07:00:08 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id l7sm20722803lfc.80.2020.01.22.07.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 07:00:07 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 2/7] trace-cmd,libtraceevent: Remove TEP_PLUGIN_OPTIONS Date: Wed, 22 Jan 2020 16:59:57 +0200 Message-Id: <20200122150002.763233-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com> References: <20200122150002.763233-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When loading a plugin, the current API searches for TEP_PLUGIN_OPTIONS array in plugin's symbols and loads any options from it. This API duplicates tep_plugin_add_options() In order to simplify the APIs, The duplicated TEP_PLUGIN_OPTIONS is removed as an API, as it is not used by any existing plugin. The tep_plugin_add_options() API is the only way to register plugin options. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/traceevent/event-parse.h | 20 -------------------- lib/traceevent/event-plugin.c | 11 ----------- 2 files changed, 31 deletions(-) diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h index 72f7aaf..cb1b46e 100644 --- a/include/traceevent/event-parse.h +++ b/include/traceevent/event-parse.h @@ -77,33 +77,13 @@ struct tep_plugin_option { * * int TEP_PLUGIN_UNLOADER(struct tep_handle *tep) * - * TEP_PLUGIN_OPTIONS: (optional) - * Plugin options that can be set before loading - * - * struct tep_plugin_option TEP_PLUGIN_OPTIONS[] = { - * { - * .name = "option-name", - * .description = "description of option to show users", - * }, - * { - * .name = NULL, - * }, - * }; - * - * Array must end with .name = NULL; - * - * If .value is not set, then it is considered a boolean and only - * .set will be processed. If .value is defined, then it is considered - * a string option and .set will be ignored. */ #define TEP_PLUGIN_LOADER tep_plugin_loader #define TEP_PLUGIN_UNLOADER tep_plugin_unloader -#define TEP_PLUGIN_OPTIONS tep_plugin_options #define _MAKE_STR(x) #x #define MAKE_STR(x) _MAKE_STR(x) #define TEP_PLUGIN_LOADER_NAME MAKE_STR(TEP_PLUGIN_LOADER) #define TEP_PLUGIN_UNLOADER_NAME MAKE_STR(TEP_PLUGIN_UNLOADER) -#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS) enum tep_format_flags { TEP_FIELD_IS_ARRAY = 1, diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index bbe87d4..8c48ccf 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -427,7 +427,6 @@ load_plugin(struct tep_handle *tep, const char *path, const char *file, void *data) { struct tep_plugin_list **plugin_list = data; - struct tep_plugin_option *options; tep_plugin_load_func func; struct tep_plugin_list *list; char *plugin; @@ -447,16 +446,6 @@ load_plugin(struct tep_handle *tep, const char *path, goto out_free; } - options = dlsym(handle, TEP_PLUGIN_OPTIONS_NAME); - if (options) { - while (options->name) { - ret = update_option(file, options); - if (ret < 0) - goto out_free; - options++; - } - } - func = dlsym(handle, TEP_PLUGIN_LOADER_NAME); if (!func) { warning("could not find func '%s' in plugin '%s'\n%s\n", From patchwork Wed Jan 22 14:59:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11345881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E87876C1 for ; Wed, 22 Jan 2020 15:00:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C63E524676 for ; Wed, 22 Jan 2020 15:00:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sWUfPnCt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725943AbgAVPAL (ORCPT ); Wed, 22 Jan 2020 10:00:11 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:36131 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgAVPAL (ORCPT ); Wed, 22 Jan 2020 10:00:11 -0500 Received: by mail-lj1-f195.google.com with SMTP id r19so7168041ljg.3 for ; Wed, 22 Jan 2020 07:00:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=oiz0tIFJTUyp9BFc+W4zhPg/52E3kMlWtCBQ4cLOvso=; b=sWUfPnCtqvAPsMjHA/Tdzgn6DCQ84kcu2ZEBYyCPeu/nfKDa0ETiaurf/qux0dNxY9 pNH7DtXGLokk33ntRnFui73r82XdmC1fwuZ8abDb+VjtrFLzBZ5Me5OXegI30hnUu/xQ StD6BLXaSdXPzg/VYTv/HhjbCAp0cKNm3c9XMT5KwAFY1xvCoGCcvSPQDQTQmhvxla8j f1vIcGr/1mj02thOpw6rNzeYDGHb3wXA23UtUBxAh6qSBqScXmEAbTKDbrQ9n0swycmZ RHn19XroiWE3HQbfSmYFS9G60EGzQXzikEWod84xX+cGIGKC+SaDtzQzEnvFR07V2r/t C2OA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=oiz0tIFJTUyp9BFc+W4zhPg/52E3kMlWtCBQ4cLOvso=; b=IIJJi3RFGIo3XNAplHpCB5/tHHiGd069SYu/B/+wfk4av0vgfvIXgB0Gd5RiJcgwHs dQHilxev/TTdk3UivmzrZjyQ7EyeagEEAVV/n/ft2XjkYppivjWVYyMlTI0xoxttBrwM ehjZDTty5lCEwAH2qme2R841QQQq65Q0jH7nxkaEmq76PK2+RCmWstQDk3Nj07YshTuf vrM/MRIiJXS/dJ88oA6ZWbyFrCnvhYa0q+2S41h8W4Cnv8CmGUem1KQ0wG5PiFgNI7K9 75n63Yyc5EpNrNR4STTy8/zHKRHGfXV84+/ybUUTzRt1c4w21TI5kX4KpM2K6kOMvpe1 yMtQ== X-Gm-Message-State: APjAAAVwIUzW7iXlAv9vOn6aYPaHNQlHMyHrdinzMEXLcrEivODOi4ow xFhyeLN9XUjojXqRX/uHdIphZIoH X-Google-Smtp-Source: APXvYqz1bF1AOMy+Ytlta/v9gvca9efDThfg7qJKKfP1MdAf/6mZMlfq9ebm29ziCVd64VVXvsJBnA== X-Received: by 2002:a2e:3a0c:: with SMTP id h12mr19929510lja.200.1579705209408; Wed, 22 Jan 2020 07:00:09 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id l7sm20722803lfc.80.2020.01.22.07.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 07:00:08 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 3/7] trace-cmd,libtraceevent: Check for plugin options duplication Date: Wed, 22 Jan 2020 16:59:58 +0200 Message-Id: <20200122150002.763233-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com> References: <20200122150002.763233-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When loading new plugin options, check is an option with the same name and plugin is already registered. The API tep_plugin_add_options() is modified to return errors is these cases: - The "plugin" field in the option's description is not set, return -EINVAL - An option with the same name and plugin is already registered return -EBUSY Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/traceevent/event-plugin.c | 50 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index 8c48ccf..e53b09c 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -202,6 +202,26 @@ update_option(const char *file, struct tep_plugin_option *option) return ret; } +static struct tep_plugin_option * +find_registered_option(const char *plugin, const char *option) +{ + struct registered_plugin_options *reg; + struct tep_plugin_option *op; + + for (reg = registered_options; reg; reg = reg->next) { + for (op = reg->options; op->name; op++) { + if (plugin && strcmp(plugin, op->plugin) != 0) + continue; + if (strcmp(option, op->name) != 0) + continue; + + return op; + } + } + + return NULL; +} + /** * tep_plugin_add_options - Add a set of options by a plugin * @name: The name of the plugin adding the options @@ -213,6 +233,16 @@ int tep_plugin_add_options(const char *name, struct tep_plugin_option *options) { struct registered_plugin_options *reg; + struct tep_plugin_option *option; + + option = options; + while (option && option->name) { + if (!option->plugin) + return -EINVAL; + if (find_registered_option(name, option->name)) + return -EBUSY; + option++; + } reg = malloc(sizeof(*reg)); if (!reg) @@ -262,26 +292,6 @@ static void parse_option_name(char **option, char **plugin) } } -static struct tep_plugin_option * -find_registered_option(const char *plugin, const char *option) -{ - struct registered_plugin_options *reg; - struct tep_plugin_option *op; - - for (reg = registered_options; reg; reg = reg->next) { - for (op = reg->options; op->name; op++) { - if (plugin && strcmp(plugin, op->plugin) != 0) - continue; - if (strcmp(option, op->name) != 0) - continue; - - return op; - } - } - - return NULL; -} - static int process_option(const char *plugin, const char *option, const char *val) { struct tep_plugin_option *op; From patchwork Wed Jan 22 14:59:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11345883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16D39924 for ; Wed, 22 Jan 2020 15:00:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E82DE2465B for ; Wed, 22 Jan 2020 15:00:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IbDrDKiv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725946AbgAVPAM (ORCPT ); Wed, 22 Jan 2020 10:00:12 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:41161 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbgAVPAM (ORCPT ); Wed, 22 Jan 2020 10:00:12 -0500 Received: by mail-lj1-f193.google.com with SMTP id h23so7154248ljc.8 for ; Wed, 22 Jan 2020 07:00:11 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=UFYwSqbQzzhMH5vl8zY2CSKRunphQOXVq2ylRzgHbug=; b=IbDrDKivxUA0Grfsh6/y4nQ0oD5Kywc8PVHeqrGTr0En7KS6fqjTa2kisz3Sn6vuK9 iwi+ELvyLbcM845KYh0eARocr3xG+tUtsd2oY7AIVnsCtdtAxsUxJnbwnywSGV5YYS9D PC5WD4kfoKuG47RGqPMLT8cv7pibUJnihTGMEFz4hifrmVAqUMO0qcuExcW4b+5BeRKm dvKRgmEJ+FkYsTmVjz6GG07nTjSpXIpU4jCXeq/hzF6l7xL3Xmwh39IivKCK06kPKbP3 unHXHQztx+jmvurPGJrCkVzOYwWqiCDBWqWeB0igrSB1Jos+/Apye3mEAKVojc910Ou2 L6LQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=UFYwSqbQzzhMH5vl8zY2CSKRunphQOXVq2ylRzgHbug=; b=nDeObtfQG+ocGvioG89JF/DiGGBJF3saXdDf0nkOjc6GSF2Rr38XnBkuFrtsrOp6uH R3chMHuUyb5OXdu5mfiJ4YSFr6NoZ+jg3KESMVb8W1twkD+iKEImPswdPXdrqgGMbk1K fu64ID5hFUKNVipfc0HyTZQTqcAe7baxYGxd/GYbk/VPO+XiXifEgz43pcG8ln+PEULn HjUtL3Ao922i0yBEDla/cG/fI1/OxM+m6FblpKoiRVy4JqFYZ3+xVLCKXoIFDTcRWfrL boPtc5PBW7003HXxJZdcug0BAm1eR8h74QV3+GZdL5gDpzL0REWiWMoIKVRYb/2kmZ1M YtIw== X-Gm-Message-State: APjAAAUYow8p+7ME5+hkAcuaCFKuNPVsZhjFD4pyTnpx8WmCSQ0AJSAI LKd5fKnsqgtHe8jVbWZrP9M= X-Google-Smtp-Source: APXvYqx0o+MqoPlGrmhvdxJ7zsH0I4ubNSmhHX6p7i1/QOr3QawAcKawGaDTfMz0XZ5YB0Nl/QZNwA== X-Received: by 2002:a05:651c:204f:: with SMTP id t15mr20427210ljo.240.1579705210561; Wed, 22 Jan 2020 07:00:10 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id l7sm20722803lfc.80.2020.01.22.07.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 07:00:10 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 4/7] trace-cmd,libtraceevent: Check for plugin duplication Date: Wed, 22 Jan 2020 16:59:59 +0200 Message-Id: <20200122150002.763233-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com> References: <20200122150002.763233-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When loading new plugin, check if plugin with the same file name is already registered. If there is such plugin, unload it and then load the new one. In case of duplication, the last one wins. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/traceevent/event-plugin.c | 50 +++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index e53b09c..a33cf09 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -432,16 +432,60 @@ void tep_print_plugins(struct trace_seq *s, } } + +static void unload_plugin(void *handle, struct tep_handle *tep) +{ + tep_plugin_unload_func func; + + if (!handle) + return; + func = dlsym(handle, TEP_PLUGIN_UNLOADER_NAME); + if (func) + func(tep); + dlclose(handle); +} + +static struct tep_plugin_list * +detach_plugin(const char *name, struct tep_plugin_list **plist) +{ + struct tep_plugin_list *plugins = *plist; + struct tep_plugin_list *prev = NULL; + char *file; + + while (plugins) { + file = strrchr(plugins->name, '/'); + if (file) + file++; + else + file = plugins->name; + if (!strcmp(file, name)) { + if (prev) + prev->next = plugins->next; + else + *plist = plugins->next; + return plugins; + } + prev = plugins; + plugins = plugins->next; + } + + return NULL; +} + static void load_plugin(struct tep_handle *tep, const char *path, const char *file, void *data) { struct tep_plugin_list **plugin_list = data; + struct tep_plugin_list *old; tep_plugin_load_func func; struct tep_plugin_list *list; char *plugin; void *handle; int ret; + old = detach_plugin(file, plugin_list); + if (old) + unload_plugin(old->handle, tep); ret = asprintf(&plugin, "%s/%s", path, file); if (ret < 0) { @@ -652,16 +696,12 @@ void tep_free_plugin_paths(struct tep_handle *tep) void tep_unload_plugins(struct tep_plugin_list *plugin_list, struct tep_handle *tep) { - tep_plugin_unload_func func; struct tep_plugin_list *list; while (plugin_list) { list = plugin_list; + unload_plugin(list->handle, tep); plugin_list = list->next; - func = dlsym(list->handle, TEP_PLUGIN_UNLOADER_NAME); - if (func) - func(tep); - dlclose(list->handle); free(list->name); free(list); } From patchwork Wed Jan 22 15:00:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11345885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07A99924 for ; Wed, 22 Jan 2020 15:00:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D050224673 for ; Wed, 22 Jan 2020 15:00:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d26Mx0EO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726061AbgAVPAO (ORCPT ); Wed, 22 Jan 2020 10:00:14 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39658 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgAVPAO (ORCPT ); Wed, 22 Jan 2020 10:00:14 -0500 Received: by mail-lj1-f195.google.com with SMTP id o11so6853675ljc.6 for ; Wed, 22 Jan 2020 07:00:12 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=yQK/ew4P9/ik9t+81/pBL+7ZeC8YM+7P18kcUY2BQ2c=; b=d26Mx0EO3SGa/By2Q8gwo64wfqE6fKOeeMrztcwSdM071gKb+2Rahp9LXIvtcdjzsL e2or606G8CU1pyBaqDAFYqBnivTQwLFso5bnxrmJtXIC968OQ6558Oz+JdPU1qk8Og6T CNuQ35J+qZuMI5n/xNgOpTvpGgGPdj0HlKXw1VnTLuyMMei89cGhA+j9RbYiQMnyMCt2 eNa5P8grLcVJKnuAXQ2TEwrzZozBB2NM2ttpssfuSOgSVszwWpaVQc0Sl6PKeTg+8OdS ynz1yTxPBmo0fMYoBQ34IWi2+gonvZ6GBx7hNsXWc+dQF2Xqa7WFAECLQgLxEnrbs0lJ xgxg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=yQK/ew4P9/ik9t+81/pBL+7ZeC8YM+7P18kcUY2BQ2c=; b=bncfnL+2v8cfV6wU8gpERel4RmepiwsuFwycDBqFj5Z/qiedv7JUJ68E948jcEL0Ri olrokmGstuyB+GvqOYmSqgh+jnYEg+gRm5MspHN431hcbzclfUQascz96vd5JHIxMNjd MjcDUaklHRNjFYw4+0bcQylNRiI9qBRcu8SvcKXHwolNqOM8vvTpVu1RQuzDeDCCvHEY 3tjznssCFecSShxNrkF0/DL7LE+PP2gNwgkDYlK4yBa73m9b4hNa+L21XSqquD8jqQe4 CXytAA985qPan9eg50fQZt7iaDdIE+Y6+6+0xTkd1yqEUM50cbNU3jZois5cVIoCtq5n LKJw== X-Gm-Message-State: APjAAAWv0s9W6cqbTrGhcogV76F9z2XYi/kSsfXl9i6itnjSjWOO68c4 Ovspu7qTcxszxX9B+pAZVQs= X-Google-Smtp-Source: APXvYqy2ZXkwyu539JyrkEOc7H+5k4DJK4BYxtmsJ4M1s2svNEdH3ZW7DchnvJZ+F7QSmSv1SQo23w== X-Received: by 2002:a2e:909a:: with SMTP id l26mr19423838ljg.209.1579705211648; Wed, 22 Jan 2020 07:00:11 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id l7sm20722803lfc.80.2020.01.22.07.00.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 07:00:11 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 5/7] trace-cmd,libtraceevent: Remove API for plugin options print Date: Wed, 22 Jan 2020 17:00:00 +0200 Message-Id: <20200122150002.763233-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com> References: <20200122150002.763233-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The functionality for printing registered plugin options is moved from libtraceevent to the application. A more generic walk API is introduced. Removed APIs: tep_plugin_list_options() tep_plugin_free_options_list() tep_plugin_print_options() Added API tep_plugin_walk_options() Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/traceevent/event-parse.h | 9 ++- lib/traceevent/event-plugin.c | 98 ++++---------------------------- tracecmd/trace-list.c | 43 +++++++++++++- 3 files changed, 58 insertions(+), 92 deletions(-) diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h index cb1b46e..3b4f3a5 100644 --- a/include/traceevent/event-parse.h +++ b/include/traceevent/event-parse.h @@ -346,8 +346,6 @@ enum tep_errno { struct tep_plugin_list; -#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1)) - enum tep_plugin_load_priority { TEP_PLUGIN_FIRST, TEP_PLUGIN_LAST, @@ -364,13 +362,14 @@ void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix, const char *name, void *data), void *data); -char **tep_plugin_list_options(void); -void tep_plugin_free_options_list(char **list); int tep_plugin_add_options(const char *name, struct tep_plugin_option *options); int tep_plugin_add_option(const char *name, const char *val); void tep_plugin_remove_options(struct tep_plugin_option *options); -void tep_plugin_print_options(struct trace_seq *s); +void tep_plugin_walk_options(int (*callback)(struct tep_plugin_option *op, + void *context), + void *context); + void tep_print_plugins(struct trace_seq *s, const char *prefix, const char *suffix, const struct tep_plugin_list *list); diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index a33cf09..191b27b 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -91,71 +91,6 @@ static int update_option_value(struct tep_plugin_option *op, const char *val) return 0; } -/** - * tep_plugin_list_options - get list of plugin options - * - * Returns an array of char strings that list the currently registered - * plugin options in the format of :