From patchwork Fri May 7 09:50:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12244223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22BC4C433ED for ; Fri, 7 May 2021 09:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02E4D6145A for ; Fri, 7 May 2021 09:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbhEGJvc (ORCPT ); Fri, 7 May 2021 05:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233618AbhEGJv1 (ORCPT ); Fri, 7 May 2021 05:51:27 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB5FEC061761 for ; Fri, 7 May 2021 02:50:26 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id t4so12757631ejo.0 for ; Fri, 07 May 2021 02:50:26 -0700 (PDT) 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=fewU8CCSpNVQZEazC24VUbehjl283KGqaJRi2EYCFao=; b=N95qtBDvwt9b/5DSeWx/sFdOw9p6Lne1fdeNitcXnhF6MlCOnryE9wUMJ+qU1vKPVs EZSs9TjZEpVgxK0QDXna+Iq2RSi/z8BOAReunH2WuXJC/osk4jxcc7ztZWztXTISthJg +UHdFIRrRKG7fOKeOM8e2bq3NKA/rvHSspvz9He858nvjgVnOenqcZQGpuumbTUVLsHG KDYYveJZj+khly8ZcV2b5SQcyT5mZIDXUzfg8p/fiSoQJ10c1Jn8Xo0hoJ9g4hVp8Kl/ JusK9ZKdyxeW2UujQkAcvBif2Y1oq6l518PPJ8jRf6y6abiaftipxMbPTty2+nTQWu2r TgAQ== 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=fewU8CCSpNVQZEazC24VUbehjl283KGqaJRi2EYCFao=; b=huu3MS8XDH/iUJghjHowRcOtXjYrTD2TY5/kBZFP9U9GZc5SrhjhKl0GAI2r9nrC6Y DtHAI50OVkZUUK0T0bp7p9GU5NsmmjZWgkbN1xjFfHBH0zI1LSyX8Z+pLAoA4H3K8++8 SmY14FLUdz+NJC3VWJbVJYIvpvEsLSuEr7BbYwzdv5KFFeqstL9lhCXtle3+quCqNcwZ Rrs2T4lv8CMCSO1EfP+UqQjzXMf8RimX1VBkScHipxEnzsy/aJIgJYtDG8kOQX3vqWSg 7ENQnge++7Qk7nMzUdNcAc1a9gY7CGdxiIbZLknk7dOoPT1WCK06fWYOZkY9gCIk3K9R a8GA== X-Gm-Message-State: AOAM531kVhjWoop2W6N+e9bdNW4MsXR10bBdDRX05UjrEJv4dy+klmIf kmgl/I/omSXm52GhqLSPGyM= X-Google-Smtp-Source: ABdhPJyLHABCYRznmeSBb4iArMmBNQ0RnZrXNEPALeX/PfQmUNyD2oopO+jszfys6Xmmcf6WH5mt+A== X-Received: by 2002:a17:906:d14c:: with SMTP id br12mr8925336ejb.429.1620381025550; Fri, 07 May 2021 02:50:25 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id a24sm3787193edr.74.2021.05.07.02.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 02:50:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 1/4] libtraceevent: Add log levels Date: Fri, 7 May 2021 12:50:19 +0300 Message-Id: <20210507095022.1079364-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com> References: <20210507095022.1079364-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Defined levels of the library logs and new API to set the desired log level. By default, only critical logs are enabled. Signed-off-by: Tzvetomir Stoyanov (VMware) --- src/event-parse.h | 12 ++++++++++++ src/parse-utils.c | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/event-parse.h b/src/event-parse.h index 05b156b..77be2b9 100644 --- a/src/event-parse.h +++ b/src/event-parse.h @@ -749,4 +749,16 @@ int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *sour int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2); +/* Control library logs */ +enum tep_loglevel { + TEP_LOG_NONE = 0, + TEP_LOG_CRITICAL, + TEP_LOG_ERROR, + TEP_LOG_WARNING, + TEP_LOG_INFO, + TEP_LOG_DEBUG, + TEP_LOG_ALL +}; +void tep_set_loglevel(enum tep_loglevel level); + #endif /* _PARSE_EVENTS_H */ diff --git a/src/parse-utils.c b/src/parse-utils.c index 6a4a2cd..bc89c44 100644 --- a/src/parse-utils.c +++ b/src/parse-utils.c @@ -9,8 +9,21 @@ #include #include +#include "event-parse.h" + #define __weak __attribute__((weak)) +static int log_level = TEP_LOG_CRITICAL; + +/** + * tep_set_loglevel - set log level of the library + * @level: desired level of the library messages + */ +void tep_set_loglevel(enum tep_loglevel level) +{ + log_level = level; +} + int __weak tep_vwarning(const char *name, const char *fmt, va_list ap) { int ret = errno; @@ -29,6 +42,9 @@ void __weak tep_warning(const char *fmt, ...) { va_list ap; + if (log_level < TEP_LOG_WARNING) + return; + va_start(ap, fmt); tep_vwarning("libtraceevent", fmt, ap); va_end(ap); From patchwork Fri May 7 09:50:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12244229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFE80C43460 for ; Fri, 7 May 2021 09:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AEF4D6145E for ; Fri, 7 May 2021 09:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbhEGJvd (ORCPT ); Fri, 7 May 2021 05:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233662AbhEGJv2 (ORCPT ); Fri, 7 May 2021 05:51:28 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFB4EC061763 for ; Fri, 7 May 2021 02:50:27 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id r9so12693268ejj.3 for ; Fri, 07 May 2021 02:50:27 -0700 (PDT) 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=kjeYPzWedHXFV9cUskK8JHWMrLdjtg+aql0UHmLl6LI=; b=YiGCI0Xf8eHulSKPhMXDLYQBpu6P+R18hbq5FSzxQ5SfnOKYHhSwq70PlVcc/idguI jHHw1mtANKkR9oSO67ekAUR1SOz2onarx77DWMju7hf1OJOPL6VPGk2IylkZCPoy2zd1 aGDubGmO7Ih6hS/E3Xt3Bet7bMzKkEByPgmB4O2CEJklpOShHPFhx3Lx503hiEC6YfKo 7WquymJeUBRmHYkrifHvFLRTQOc7WCLUG8yW3htMoyn/G6XM6a5p3Q6PJT6JuPavScb3 E6QveVgd8oeOVtV+LVXwz6bbwlNilzuy2u1pxFjfLfS2GxYGF7PHCDH76fD0wHiu/d4d lCQg== 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=kjeYPzWedHXFV9cUskK8JHWMrLdjtg+aql0UHmLl6LI=; b=BH2Qqkth38lx+ifivhF8MBaGkha/gpinyv0dTcELf3biO8YUXlWCjlAWXbCb1cAV8z Mig1iXC5jeyqBL0N2uMVQ+DJQph2Z2D9vlxCoJ+mtnjJmVy9TWKc6GMsp2kYcfjKNRzu ljcUA+Z6Wpc4eOON5MCIFMQWMNNOX85lj3s8zutiCW6EeDSr5huUV4uYqOyRpyzqiShx cI4cnz5pvBccm2tQFLPZI2/MXIvY0sVW15wHZX27bGXv7TaG29oCfcJdG7kPOkAPQLXP rYMdzzVhqOPklXNNoig/JbIjK/ZenrC5gsUt90WhJv1qWwig2rkMVkBek0FbEJ7k9Tli oqvQ== X-Gm-Message-State: AOAM532YQM25q3p8MnCR5bPQxLS01W6QUchHt3GQ5VeBVzhKGIihOsRb VA7hhQHpp5GFWB4ubx5oK1PWuw8kSWdQhA== X-Google-Smtp-Source: ABdhPJx/90NYWV649M60aeOlphZsbW0M7Bf3mudi4l/nEYea4HJeG/lu/M/GFbG6Q/sPZRTTDKiDTQ== X-Received: by 2002:a17:907:948d:: with SMTP id dm13mr8561374ejc.180.1620381026650; Fri, 07 May 2021 02:50:26 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id a24sm3787193edr.74.2021.05.07.02.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 02:50:26 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 2/4] libtraceevent: Add logs with severity info Date: Fri, 7 May 2021 12:50:20 +0300 Message-Id: <20210507095022.1079364-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com> References: <20210507095022.1079364-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Renamed existing pr_stat() internal function to tep_info() and limit it to print only when the log level is TEP_LOG_INFO. Removed duplicated and unused functions: vpr_stat() __pr_stat() __vpr_stat() Signed-off-by: Tzvetomir Stoyanov (VMware) --- src/event-parse.c | 14 +++++++------- src/event-plugin.c | 2 +- src/event-utils.h | 7 +------ src/parse-utils.c | 24 ++++-------------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 88ec909..97c1a97 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -6927,8 +6927,8 @@ static int find_event_handle(struct tep_handle *tep, struct tep_event *event) if (!(*next)) return 0; - pr_stat("overriding event (%d) %s:%s with new print handler", - event->id, event->system, event->name); + tep_info("overriding event (%d) %s:%s with new print handler", + event->id, event->system, event->name); event->handler = handle->func; event->context = handle->context; @@ -7404,7 +7404,7 @@ int tep_register_print_function(struct tep_handle *tep, * plugins updating the function. This overrides the * system defaults. */ - pr_stat("override of function helper '%s'", name); + tep_info("override of function helper '%s'", name); remove_func_handler(tep, name); } @@ -7542,8 +7542,8 @@ int tep_register_event_handler(struct tep_handle *tep, int id, if (event == NULL) goto not_found; - pr_stat("overriding event (%d) %s:%s with new print handler", - event->id, event->system, event->name); + tep_info("overriding event (%d) %s:%s with new print handler", + event->id, event->system, event->name); event->handler = func; event->context = context; @@ -7628,8 +7628,8 @@ int tep_unregister_event_handler(struct tep_handle *tep, int id, goto not_found; if (event->handler == func && event->context == context) { - pr_stat("removing override handler for event (%d) %s:%s. Going back to default handler.", - event->id, event->system, event->name); + tep_info("removing override handler for event (%d) %s:%s. Going back to default handler.", + event->id, event->system, event->name); event->handler = NULL; event->context = NULL; diff --git a/src/event-plugin.c b/src/event-plugin.c index df4a0a3..f42243f 100644 --- a/src/event-plugin.c +++ b/src/event-plugin.c @@ -497,7 +497,7 @@ load_plugin(struct tep_handle *tep, const char *path, list->name = plugin; *plugin_list = list; - pr_stat("registering plugin: %s", plugin); + tep_info("registering plugin: %s", plugin); func(tep); return; diff --git a/src/event-utils.h b/src/event-utils.h index ff4d6c4..1951557 100644 --- a/src/event-utils.h +++ b/src/event-utils.h @@ -9,15 +9,10 @@ #include #include +void tep_info(const char *fmt, ...); /* Can be overridden */ void tep_warning(const char *fmt, ...); int tep_vwarning(const char *name, const char *fmt, va_list ap); -void pr_stat(const char *fmt, ...); -void vpr_stat(const char *fmt, va_list ap); - -/* Always available */ -void __pr_stat(const char *fmt, ...); -void __vpr_stat(const char *fmt, ...); #define min(x, y) ({ \ typeof(x) _min1 = (x); \ diff --git a/src/parse-utils.c b/src/parse-utils.c index bc89c44..b997823 100644 --- a/src/parse-utils.c +++ b/src/parse-utils.c @@ -50,31 +50,15 @@ void __weak tep_warning(const char *fmt, ...) va_end(ap); } -void __vpr_stat(const char *fmt, va_list ap) -{ - vprintf(fmt, ap); - printf("\n"); -} -void __pr_stat(const char *fmt, ...) +void tep_info(const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - __vpr_stat(fmt, ap); - va_end(ap); -} - -void __weak vpr_stat(const char *fmt, va_list ap) -{ - __vpr_stat(fmt, ap); -} - -void __weak pr_stat(const char *fmt, ...) -{ - va_list ap; + if (log_level < TEP_LOG_INFO) + return; va_start(ap, fmt); - __vpr_stat(fmt, ap); + tep_vwarning("libtraceevent", fmt, ap); va_end(ap); } From patchwork Fri May 7 09:50:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12244227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FA5BC43462 for ; Fri, 7 May 2021 09:50:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4705C6145D for ; Fri, 7 May 2021 09:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233618AbhEGJvd (ORCPT ); Fri, 7 May 2021 05:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233932AbhEGJva (ORCPT ); Fri, 7 May 2021 05:51:30 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4FFEC0613ED for ; Fri, 7 May 2021 02:50:28 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id b25so12656877eju.5 for ; Fri, 07 May 2021 02:50:28 -0700 (PDT) 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=EYmXLuz5HWqYvmjP3afWQgDI8brkrL0+fi+ydYlVaKA=; b=FF/c36hDXC41ouJ+1QocIjjhHl/UyT94ji/8FMyJCT0Phdfdc8C021QYaNd6DT3FpJ eJR1vUReEfh8gHzaM72wrpNZlf5jKco8jFtOmC0J055Pj+EkpRMAlJ5so3AOuVREP8mG 3pGY4Q2EyI5HDYDRizZgMEuNc5onQv5qF7p/X3OwwEKDAVh3Uz4TM/RnG81Gykj/hudT wdvu5AO7+w3GnHxD8fhcT77EWuASzmZtGHFo41K81kV3PA6/oQZZ3AeE0mDqLkuNWSL3 dEbkI2sQPtTA2NKrErhJdUYMBPWPx1iqnn/KPmHv/D1bx81lGx6eKwOcqB9i5A8Fs8p2 vwfQ== 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=EYmXLuz5HWqYvmjP3afWQgDI8brkrL0+fi+ydYlVaKA=; b=oPDKsqj3Em1HJKs9XFNqxwXrxQY1HSR7To5P7UGSLd6IlJ4vzmSM/RD/+823aC4nop gU8Y7kHcNTjVA2XFhz/tkfDNeNsHvkdpjXPt4kJ+9rDLJED+KgIu5UDsLplc+DOJ/CRM 5fIks5p5Tvcca98rtVi61RujbthL7QRew5pxC2ivhyNfbSDjpZh5oZ4jIs+GQw/9pEJF 8xWsl2UOKQTQgxEPmjL+6OV+8iglu9IgezsssynrZxKYLbPrf1gCBvUArp+NO++laKvV GJsHv1VIjJ8AgWJ1aHtMSNp73T24xzZvGEHU2M5XSRQmITDtkvJrCV4Nh8Oz0QEpBPX/ O+Sg== X-Gm-Message-State: AOAM533LPUG//ko2Wf3GmEueB8ez1YQ3N8ty1k12ngqDlS9qZnzRDbTG 9zqr1APzs9YYul36/7ALXP4= X-Google-Smtp-Source: ABdhPJwtX1qbTovF7gEDe5aPZO836HgZJ+NGT5wXZdwiwkTDHtXcLLcdykDpDv1JAW5kVyIEMVPwbg== X-Received: by 2002:a17:906:d0c8:: with SMTP id bq8mr8770996ejb.423.1620381027616; Fri, 07 May 2021 02:50:27 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id a24sm3787193edr.74.2021.05.07.02.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 02:50:27 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 3/4] libtraceevent: Rename tep_vwarning() to tep_vprint() Date: Fri, 7 May 2021 12:50:21 +0300 Message-Id: <20210507095022.1079364-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com> References: <20210507095022.1079364-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Renamed the existing weak function tep_vwarning() to tep_vprint(), to match its purpose. This function is used to print library logs with any log severity, not only warnings. Signed-off-by: Tzvetomir Stoyanov (VMware) --- src/event-utils.h | 5 +++-- src/parse-utils.c | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/event-utils.h b/src/event-utils.h index 1951557..0617a28 100644 --- a/src/event-utils.h +++ b/src/event-utils.h @@ -9,10 +9,11 @@ #include #include +void tep_warning(const char *fmt, ...); void tep_info(const char *fmt, ...); /* Can be overridden */ -void tep_warning(const char *fmt, ...); -int tep_vwarning(const char *name, const char *fmt, va_list ap); +int tep_vprint(const char *name, enum tep_loglevel level, + bool print_err, const char *fmt, va_list ap); #define min(x, y) ({ \ typeof(x) _min1 = (x); \ diff --git a/src/parse-utils.c b/src/parse-utils.c index b997823..7510157 100644 --- a/src/parse-utils.c +++ b/src/parse-utils.c @@ -24,11 +24,28 @@ void tep_set_loglevel(enum tep_loglevel level) log_level = level; } -int __weak tep_vwarning(const char *name, const char *fmt, va_list ap) +/** + * tep_vprint - print library log messages + * @name: name of the library. + * @level: severity of the log message. This parameter is not used in this implementation, but as + * the function is weak and can be overridden, having the log level could be useful + * for other implementations. + * @print_err: whether to print the errno, if non zero. + * @fmt: printf format string of the message. + * @ap: list of printf parameters. + * + * This function is used to print all messages from traceevent, tracefs and trace-cmd libraries. + * It is defined as weak, so the application that uses those libraries can override it in order + * to implement its own logic for printing library logs. + * + * Return the value of errno at the function enter. + */ +int __weak tep_vprint(const char *name, enum tep_loglevel level, + bool print_err, const char *fmt, va_list ap) { int ret = errno; - if (errno) + if (errno && print_err) perror(name); fprintf(stderr, " "); @@ -38,7 +55,7 @@ int __weak tep_vwarning(const char *name, const char *fmt, va_list ap) return ret; } -void __weak tep_warning(const char *fmt, ...) +void tep_warning(const char *fmt, ...) { va_list ap; @@ -46,7 +63,7 @@ void __weak tep_warning(const char *fmt, ...) return; va_start(ap, fmt); - tep_vwarning("libtraceevent", fmt, ap); + tep_vprint("libtraceevent", TEP_LOG_WARNING, true, fmt, ap); va_end(ap); } @@ -59,6 +76,6 @@ void tep_info(const char *fmt, ...) return; va_start(ap, fmt); - tep_vwarning("libtraceevent", fmt, ap); + tep_vprint("libtraceevent", TEP_LOG_INFO, false, fmt, ap); va_end(ap); } From patchwork Fri May 7 09:50:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12244231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80BF7C43461 for ; Fri, 7 May 2021 09:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6075E61451 for ; Fri, 7 May 2021 09:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231517AbhEGJvd (ORCPT ); Fri, 7 May 2021 05:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232135AbhEGJv3 (ORCPT ); Fri, 7 May 2021 05:51:29 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E08E7C06138A for ; Fri, 7 May 2021 02:50:29 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id u3so12628745eja.12 for ; Fri, 07 May 2021 02:50:29 -0700 (PDT) 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=9ZQ8lr8871xKPs3LDyWgoFfjwRgVLQ9CUpWrYg99OME=; b=FqXqMz1ZdWBlkvLUwkS018Ck2HWrGPxECF/rSWIar4Lru8E2OB6JHIl5SlaMOSt+Ns pNAWqgrQ2Bziea28rHBPZaYga0eGIbhDZXesziN5OKTJimo4XR9elEMzg6HE5sFo481s BTteWkFKmFA+cJ5/Fg3D5ejQB1g2ZMG8D2MqxfwHENChbZmn8pVq5bN4Er4MvEuJKXr6 giEODR7XAFBaqlxSDuQmB3SNdmWdQVTzs+AuOJehHspC+f1R9dlCzA6QDXXbE8HwFVic RRiIF8rP6BZrgZD3MfOln4R09+aBJyAx/KR5CdclQRjpEsAfdaOU0K0xY0mx3fixQNhL X8UA== 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=9ZQ8lr8871xKPs3LDyWgoFfjwRgVLQ9CUpWrYg99OME=; b=ASraeZ4IScXm4TPRfoRReSmZegYkwFFwqJuYqTBx441lTVIOfhTRANX/QaUUGioa4s /cSsE3AiBCKtjIUJbGUHVMhes9V07pKHePGADBssIugK0BSfuVkYnLzNvMTjWO1ykJXK SmqkIWfJ/+ALAyhW14lfHXI+L5vPXsyNEWDbJR7jQSOIegE4W4b4HKSpF7yV/yjy1VgY TrVgzDL3729C+/qINuFBCmiPRsQdFd5XUR7H5lNSSfTe0tkQzkwBnfZgB5Yh70glkpae juVFLy+PheQkRsN+3Y78CgrY7OfIe4ZI8fig337WJ5dFuRR5ztunIn+qpW/nJpHeHriD FIZw== X-Gm-Message-State: AOAM5312wWA28SGb2vjsraHMj76naO+TZhsoz4hhIQ8e3gZMcndIVnvz jJPdiDG4S9hlK6G+sQ2j/6DM6MBkiHH1xw== X-Google-Smtp-Source: ABdhPJwHoAIf7P4Ut04f7G2ku0ML6EuEUGE8zlbl907iKuZ6cSm/2ahF3Grz4ko8e1q+rr9ng7lgww== X-Received: by 2002:a17:906:c57:: with SMTP id t23mr3790997ejf.355.1620381028586; Fri, 07 May 2021 02:50:28 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id a24sm3787193edr.74.2021.05.07.02.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 02:50:28 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 4/4] libtraceevent: Document new log functionality Date: Fri, 7 May 2021 12:50:22 +0300 Message-Id: <20210507095022.1079364-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507095022.1079364-1-tz.stoyanov@gmail.com> References: <20210507095022.1079364-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Updated man pages with the new log API and log levels. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtraceevent-log.txt | 90 +++++++++++++++++++++++++++++ Documentation/libtraceevent.txt | 3 + 2 files changed, 93 insertions(+) create mode 100644 Documentation/libtraceevent-log.txt diff --git a/Documentation/libtraceevent-log.txt b/Documentation/libtraceevent-log.txt new file mode 100644 index 0000000..0aee21d --- /dev/null +++ b/Documentation/libtraceevent-log.txt @@ -0,0 +1,90 @@ +libtraceevent(3) +================ + +NAME +---- +tep_set_loglevel - Set log level of the library + +SYNOPSIS +-------- +[verse] +-- +*#include * + +enum *tep_loglevel* { + TEP_LOG_NONE = 0, + TEP_LOG_CRITICAL, + TEP_LOG_ERROR, + TEP_LOG_WARNING, + TEP_LOG_INFO, + TEP_LOG_DEBUG, + TEP_LOG_ALL +}; + +int *tep_set_loglevel*(enum tep_loglevel _level_); + +-- +DESCRIPTION +----------- +The _tep_set_loglevel()_ function sets the level of the library logs that will be printed +on the console. Library log levels are: +[verse] +-- + _TEP_LOG_NONE_ - Do not print any logs. + _TEP_LOG_CRITICAL_ - Print critical logs, problem that may case a crash. + _TEP_LOG_ERROR_ - Print error logs, problem that could break the main logic of an API. + _TEP_LOG_WARNING_ - Print warnings, problem that could limit the result of an API. + _TEP_LOG_INFO_ - Print information about normal execution of an API. + _TEP_LOG_DEBUG_ - Print debug information. + _TEP_LOG_ALL_ - Print logs from all levels. +-- +Setting the log level to specific value means that logs from the previous levels will be printed +too. For example _TEP_LOG_WARNING_ will print any logs with severity _TEP_LOG_WARNING_, +_TEP_LOG_ERROR_ and _TEP_LOG_CRITICAL_. The default log level is _TEP_LOG_CRITICAL_. + + +EXAMPLE +------- +[source,c] +-- +#include + +tep_set_loglevel(TEP_LOG_ALL); +... +/* call libtraceevent APIs and observe any logs they produce */ +... +tep_set_loglevel(TEP_LOG_CRITICAL); +-- + +FILES +----- +[verse] +-- +*event-parse.h* + Header file to include in order to have access to the library APIs. +*-ltraceevent* + Linker switch to add when building a program that uses the library. +-- + +SEE ALSO +-------- +_libtraceevent(3)_, _trace-cmd(1)_ + +AUTHOR +------ +[verse] +-- +*Steven Rostedt* , author of *libtraceevent*. +*Tzvetomir Stoyanov* , author of this man page. +-- +REPORTING BUGS +-------------- +Report bugs to + +LICENSE +------- +libtraceevent is Free Software licensed under the GNU LGPL 2.1 + +RESOURCES +--------- +https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt index 3365455..d42b5c9 100644 --- a/Documentation/libtraceevent.txt +++ b/Documentation/libtraceevent.txt @@ -127,6 +127,9 @@ Endian related APIs: bool *tep_is_local_bigendian*(struct tep_handle pass:[*]_tep_); void *tep_set_local_bigendian*(struct tep_handle pass:[*]_tep_, enum tep_endian _endian_); +Control library logs: + int *tep_set_loglevel*(enum tep_loglevel _level_); + Trace sequences: *#include * void *trace_seq_init*(struct trace_seq pass:[*]_s_);