From patchwork Mon Aug 23 09:56:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12452243 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.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,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 90CBBC4320A for ; Mon, 23 Aug 2021 09:56:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7959E6137B for ; Mon, 23 Aug 2021 09:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbhHWJ5Q (ORCPT ); Mon, 23 Aug 2021 05:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235808AbhHWJ5P (ORCPT ); Mon, 23 Aug 2021 05:57:15 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3482C061757 for ; Mon, 23 Aug 2021 02:56:32 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id d11so35691221eja.8 for ; Mon, 23 Aug 2021 02:56:32 -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=eDFIT2pmq3gGUvLlGfimEKq5mRLiux/wJen4AyI8UUg=; b=dmvxSEPCMvSiwIU8dyeIeRR1FtzHnDxjt40zijMg5a3nQ1EHqWVo5woJ4hdaU1lilQ M3LDEW/YRJnqTmrkGNnS8mICUN1iQnJ1LxpUNy5/H+O/7si4gU1p0ylNVhdKMzlZWlKa 1mL4MlTQ79dQ2i1ReJFW7NK2Ym++WXr+uoDGX2tkedKrfe6w+l+RNFg0b4qfB8+UZg5Q ZaDIS5ClzW6QAEDiOrKR7bXKCCjODbF05oiE4uxjpJWdERxxSwlg35xkZesPc9xXgKAX y3auCiEj0gAzApIe5EWR0TbBMBVn85znC0Fzx56o2gK7/EMVyfdskSV0Y2xD8i5Df9Ch unBw== 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=eDFIT2pmq3gGUvLlGfimEKq5mRLiux/wJen4AyI8UUg=; b=YLPYpS0aSwjVAlX04YzNmhtrlR0Rgr9BXj+nASxRGPai8yRJ0QGMX2ZZmpeUlXP1R1 /rKfruEsROeUNdqbujLG4jyqTSeGlDGwDmAHMXSImkQOChH1Jc0VZsk+Fv8a1eJP9Dlj NsSdZCkqfqgRAba+YaB8Gfw6LndgYwaT67lJVUDUnLnfWOgL18qbO9wIFLUP2t+V4HjW IuZoOiuXBoaCa6QubFAT/aKEm31U2MekU4oarca4G8nHTE0z5lAPWbHIFBJtUCms9v2x +NHwyGff9Xsi5YPL16bwVwPcI+AJdwRzzR8UxnRzQ0Oo3q80GhciLJOT9GAVX8h2wbDa 0ItA== X-Gm-Message-State: AOAM532k3KazkoQcQR91r5JgPy+ivSQEZpvSRUg0kd/nTcrZkGP2Hq2U fSoU6DTOiFFWMAJqqgaP+vI= X-Google-Smtp-Source: ABdhPJyZ+HhjrNMusPcdP7hlFX4cnZ5ZqaDpbW38NZZHhwm6ssVcXDohZu0+2YdWR6Ko0ke6XOrBfA== X-Received: by 2002:a17:907:d09:: with SMTP id gn9mr35259689ejc.447.1629712591362; Mon, 23 Aug 2021 02:56:31 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id y23sm7047831ejp.115.2021.08.23.02.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 02:56:30 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v7 1/4] libtraceevent: Improve tep_print_field() Date: Mon, 23 Aug 2021 12:56:15 +0300 Message-Id: <20210823095618.138887-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823095618.138887-1-y.karadz@gmail.com> References: <20210823095618.138887-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The existing method tep_print_fields() gets upgraded to use the printing formats provided by the tokens. Suggested-by: Steven Rostedt Signed-off-by: Yordan Karadzhov (VMware) --- src/event-parse.c | 115 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 28 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 02ec677..6129a0c 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -3913,7 +3913,6 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg arg->field.field = tep_find_any_field(event, arg->field.name); if (!arg->field.field) goto out_warning_field; - } /* must be a number */ val = tep_read_number(tep, data + arg->field.field->offset, @@ -5326,8 +5325,8 @@ static int is_printable_array(char *p, unsigned int len) return 1; } -void tep_print_field(struct trace_seq *s, void *data, - struct tep_format_field *field) +static void print_field_raw(struct trace_seq *s, void *data, + struct tep_format_field *field) { struct tep_handle *tep = field->event->tep; unsigned int offset, len, i; @@ -5389,6 +5388,56 @@ void tep_print_field(struct trace_seq *s, void *data, } } +static int print_parse_data(struct tep_print_parse *parse, struct trace_seq *s, + void *data, int size, struct tep_event *event); + +void tep_print_field(struct trace_seq *s, void *data, + struct tep_format_field *field) +{ + struct tep_event *event = field->event; + struct tep_print_parse *parse; + bool has_0x; + + parse = event->print_fmt.print_cache; + + if (event->flags & TEP_EVENT_FL_FAILED) + goto out; + + if (field->flags & (TEP_FIELD_IS_ARRAY || TEP_FIELD_IS_STRING)) + goto out; + + for (;parse; parse = parse->next) { + if (parse->type == PRINT_FMT_STRING) { + int len = strlen(parse->format); + + if (len > 1 && + strcmp(parse->format + (len -2), "0x") == 0) + has_0x = true; + else + has_0x = false; + + continue; + } + + if (!parse->arg || + parse->arg->type != TEP_PRINT_FIELD || + parse->arg->field.field != field) { + has_0x = false; + continue; + } + + if (has_0x) + trace_seq_puts(s, "0x"); + + print_parse_data(parse, s, data, field->size, event); + return; + } + + out: + /* Not found. */ + print_field_raw(s, data, field); +} + void tep_print_fields(struct trace_seq *s, void *data, int size __maybe_unused, struct tep_event *event) { @@ -5908,35 +5957,45 @@ parse_args(struct tep_event *event, const char *format, struct tep_print_arg *ar return parse_ret; } -static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s, - void *data, int size, struct tep_event *event) +static int print_parse_data(struct tep_print_parse *parse, struct trace_seq *s, + void *data, int size, struct tep_event *event) { int len_arg; + if (parse->len_as_arg) + len_arg = eval_num_arg(data, size, event, parse->len_as_arg); + + switch (parse->type) { + case PRINT_FMT_ARG_DIGIT: + print_arg_number(s, parse->format, + parse->len_as_arg ? len_arg : -1, data, + size, parse->ls, event, parse->arg); + break; + case PRINT_FMT_ARG_POINTER: + print_arg_pointer(s, parse->format, + parse->len_as_arg ? len_arg : 1, + data, size, event, parse->arg); + break; + case PRINT_FMT_ARG_STRING: + print_arg_string(s, parse->format, + parse->len_as_arg ? len_arg : -1, + data, size, event, parse->arg); + break; + case PRINT_FMT_STRING: + default: + trace_seq_printf(s, "%s", parse->format); + /* Return 1 on non field. */ + return 1; + } + /* Return 0 on field being processed. */ + return 0; +} + +static void print_event_cache(struct tep_print_parse *parse, struct trace_seq *s, + void *data, int size, struct tep_event *event) +{ while (parse) { - if (parse->len_as_arg) - len_arg = eval_num_arg(data, size, event, parse->len_as_arg); - switch (parse->type) { - case PRINT_FMT_ARG_DIGIT: - print_arg_number(s, parse->format, - parse->len_as_arg ? len_arg : -1, data, - size, parse->ls, event, parse->arg); - break; - case PRINT_FMT_ARG_POINTER: - print_arg_pointer(s, parse->format, - parse->len_as_arg ? len_arg : 1, - data, size, event, parse->arg); - break; - case PRINT_FMT_ARG_STRING: - print_arg_string(s, parse->format, - parse->len_as_arg ? len_arg : -1, - data, size, event, parse->arg); - break; - case PRINT_FMT_STRING: - default: - trace_seq_printf(s, "%s", parse->format); - break; - } + print_parse_data(parse, s, data, size, event); parse = parse->next; } } From patchwork Mon Aug 23 09:56:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12452247 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.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,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 0120CC432BE for ; Mon, 23 Aug 2021 09:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFAA66137C for ; Mon, 23 Aug 2021 09:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbhHWJ5Q (ORCPT ); Mon, 23 Aug 2021 05:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235843AbhHWJ5Q (ORCPT ); Mon, 23 Aug 2021 05:57:16 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B9FCC061757 for ; Mon, 23 Aug 2021 02:56:33 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id r19so25285555eds.13 for ; Mon, 23 Aug 2021 02:56:33 -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=lKVm56iNrg2ITtHMgmPFwOq6LiHp7d6R7+no24BD/RA=; b=um2NGM4LO27aGDmR7qg2jNm/kQgtTVDkcbenfugUGqeLBXLfIjC0gy1hXzp2rfpdr3 CYm+OPEyvCsGzw4tGs+kBcPu9CzS68JOFkBkmt5z/wrI6qaqmzMuEz/1A8GDLxa+yZvK 4+3WF3HkYieEYS95zkkB4bnzuFNXvVk1Ets763qNdCZzceYjMQjuYiz+Uls4ZVum1Mwj jsHHuYaKM488k9kyhuI4Rbojy5buo+h41RmcxU0ceEYXxfiQA5PHuLt6Fvc/VG52AB77 tILHCJ7YmuSc/OPsLU1mH7W3FyujCnveHNURXbs5dhFZFGQBkLXIaVmC65vNPwPWQN9U JXHw== 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=lKVm56iNrg2ITtHMgmPFwOq6LiHp7d6R7+no24BD/RA=; b=Zxevnk3BJ7jJs+gm4Ii/RP9xiVDXAdx8GrpnNcdymTJG2cCLdyDuxpKx95RrkicvLF +MODif9zowhoNeVEcyXUN/9TbxSCUh58pYKZOXt7iTZ6yOJ2LZEOYLsW9v5KRMCK3hyd NkEU0emdSE+ElGrtdEEQ5tOq7wQQ1r24kDZp5wZsWPJJfgivcQGbctcnRdyyrSqn25UV x7VymWcGZit5vdWhXX2yEXkHC74FnWCxemTELxFbxZ1j+GKxcMr9qUKSaQGpx5t6BFbC 8/sWlmx0N8XYmjE0hCOVPM2OoTxBnxDmV1fQwtaJO6vtvGB42ZF2krqycICJWzvZzc4J AJzQ== X-Gm-Message-State: AOAM533pvgbFO80jSA7nhkMhW8oPHwQdV+1kgv6LJMHmlS2VmR6Ua8K0 5i9dOU4VmK5r1xEiBOtC9aY= X-Google-Smtp-Source: ABdhPJyuBQkV9xbcVbKW1eG+q0iwVoKlaWxTV5rRmyAjmP2/dc30xRGz3GEYBN2rzajDg6Z2KaRHJw== X-Received: by 2002:a05:6402:d7:: with SMTP id i23mr36347754edu.291.1629712592134; Mon, 23 Aug 2021 02:56:32 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id y23sm7047831ejp.115.2021.08.23.02.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 02:56:31 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v7 2/4] libtraceevent: Optimize tep_print_fields() Date: Mon, 23 Aug 2021 12:56:16 +0300 Message-Id: <20210823095618.138887-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823095618.138887-1-y.karadz@gmail.com> References: <20210823095618.138887-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The current implementation of tep_print_fields() loops over all individual fields of the event and calls tep_print_field() for each one. In the same time inside tep_print_field() we loop over the list of all tokens of the printing format descriptor in order to determine how the current field must be printed (its own appropriate printing format). The problem is that in this second loop over the tokens we always start from the very first token and this can be quite inefficient for example in a case of a kprobe that has a large number of fields. This patch optimizes tep_print_fields(), allowing the traverse of the list of tokens to continue from the place reached when we searched for the format of the previous field. For most of the tracing events the order of fields matches the order of the corresponding format tokens, however this is not strictly guaranteed. This problem is addressed by making the loop over the tokens circular. Signed-off-by: Yordan Karadzhov (VMware) --- src/event-parse.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 6129a0c..51cb30b 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5391,22 +5391,25 @@ static void print_field_raw(struct trace_seq *s, void *data, static int print_parse_data(struct tep_print_parse *parse, struct trace_seq *s, void *data, int size, struct tep_event *event); -void tep_print_field(struct trace_seq *s, void *data, - struct tep_format_field *field) +void static inline print_field(struct trace_seq *s, void *data, + struct tep_format_field *field, + struct tep_print_parse **parse_ptr) { struct tep_event *event = field->event; + struct tep_print_parse *start_parse; struct tep_print_parse *parse; bool has_0x; - parse = event->print_fmt.print_cache; + parse = parse_ptr ? *parse_ptr : event->print_fmt.print_cache; - if (event->flags & TEP_EVENT_FL_FAILED) + if (!parse || event->flags & TEP_EVENT_FL_FAILED) goto out; if (field->flags & (TEP_FIELD_IS_ARRAY || TEP_FIELD_IS_STRING)) goto out; - for (;parse; parse = parse->next) { + start_parse = parse; + do { if (parse->type == PRINT_FMT_STRING) { int len = strlen(parse->format); @@ -5416,37 +5419,52 @@ void tep_print_field(struct trace_seq *s, void *data, else has_0x = false; - continue; + goto next; } if (!parse->arg || parse->arg->type != TEP_PRINT_FIELD || parse->arg->field.field != field) { has_0x = false; - continue; + goto next; } if (has_0x) trace_seq_puts(s, "0x"); print_parse_data(parse, s, data, field->size, event); + + if (parse_ptr) + *parse_ptr = parse->next; + return; - } + + next: + parse = parse->next ? parse->next : + event->print_fmt.print_cache; + } while (parse != start_parse); out: /* Not found. */ print_field_raw(s, data, field); } +void tep_print_field(struct trace_seq *s, void *data, + struct tep_format_field *field) +{ + print_field(s, data, field, NULL); +} + void tep_print_fields(struct trace_seq *s, void *data, int size __maybe_unused, struct tep_event *event) { + struct tep_print_parse *parse = event->print_fmt.print_cache; struct tep_format_field *field; field = event->format.fields; while (field) { trace_seq_printf(s, " %s=", field->name); - tep_print_field(s, data, field); + print_field(s, data, field, &parse); field = field->next; } } From patchwork Mon Aug 23 09:56:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12452245 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.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,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 D5C3AC43214 for ; Mon, 23 Aug 2021 09:56:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C041B61078 for ; Mon, 23 Aug 2021 09:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235897AbhHWJ5R (ORCPT ); Mon, 23 Aug 2021 05:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235841AbhHWJ5Q (ORCPT ); Mon, 23 Aug 2021 05:57:16 -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 3FA10C061575 for ; Mon, 23 Aug 2021 02:56:34 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id d11so35691367eja.8 for ; Mon, 23 Aug 2021 02:56:34 -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=dK10IrGqEdfcd4P06/H9hsX5lRFxqCCdsXrn6ekP5Ew=; b=YH5TOy5FzuZkXbux9T4jz8OES2WwpGfJN8WhVKg9XBEU/ZZ2ENAQiX1JkbhNtOfnle PUMGFv2iFnwSoKKa7B/uH6wwYsyQ1Z1+HcsDqxjxfFkkVvJ/1cfqvl0MfpjhGLUDj6fK SQXDZBwXQuGI9uVXWk3/FYXy0uJnXBtc01rYbg7TSckjrkZB8dgp6DT5DTckzPK/IIjf TAMK9wSb4sqDFV6YeLFgqWsRTZXr9NQRk96yB/xQnr124QZ9YCtmAalkAmgQTtH8ld1g a+EnmvC/MnsEbaAPGAZIqFcgEwgNRVP2emXXkP3N5+1RKw1qJ0tyQoTNtMNbteZ6XPrd EPyw== 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=dK10IrGqEdfcd4P06/H9hsX5lRFxqCCdsXrn6ekP5Ew=; b=AIdqHMjA5ooEsWEvOtGLM/6z4ged3f82b5oQIgkhdMDbDwXtKerOIwiAeA22eR4P07 D1gPG+fvSQFYvxj741hCEfyhXfDNLTyQnBAy8sDAHZb8JyxxffWDWCsfbNBVOBPtOsph Fe01rFfKIBh5zK/zSDFu7a1tRpwdABZIrkkm7b6G3343ijdzeRxZR0564AYri4OiWmFR p1NcQSjz0d3N72qP5FubQYOhJ/rtq0JFfW3a3j2pQiYq9SUqY5l6aqVm3Dp0LekJIJBt aOYr5XekrqsUUR12k36oyC6PVH0IRrJkTPHSh+lRQA3SKwMXNGCbPUB2i3yF7j7q32G+ JoZw== X-Gm-Message-State: AOAM530BHpZIkBzlctDGH/WfImyshqoUmSE1Bw0lvMGoatPVv9vJhwXD J6yWTIJOyzj+PjzZvLDfSUPk27av8j8= X-Google-Smtp-Source: ABdhPJwuTMDR3nPVJjPBDBFeWz+pobWjNGrj1ytUZVvl4gzxoYLFliBzNjqnSxOseuIyQiyF6u1jiw== X-Received: by 2002:a17:906:6b8b:: with SMTP id l11mr12329923ejr.508.1629712592810; Mon, 23 Aug 2021 02:56:32 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id y23sm7047831ejp.115.2021.08.23.02.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 02:56:32 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v7 3/4] libtraceevent: Add APIs for printing the fields of a record Date: Mon, 23 Aug 2021 12:56:17 +0300 Message-Id: <20210823095618.138887-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823095618.138887-1-y.karadz@gmail.com> References: <20210823095618.138887-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new methods can print all unique data fielsd, or only a subset of the fields of the trace event. The print format is derived from the parsing tokens (tep_print_parse objects) of the event. Signed-off-by: Yordan Karadzhov (VMware) --- src/event-parse.c | 49 +++++++++++++++++++++++++++++++++++++++++++---- src/event-parse.h | 7 +++++++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 51cb30b..71a3ccd 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5455,20 +5455,61 @@ void tep_print_field(struct trace_seq *s, void *data, print_field(s, data, field, NULL); } -void tep_print_fields(struct trace_seq *s, void *data, - int size __maybe_unused, struct tep_event *event) +static inline void +print_selected_fields(struct trace_seq *s, void *data, + struct tep_event *event, + unsigned long long ignore_mask) { struct tep_print_parse *parse = event->print_fmt.print_cache; struct tep_format_field *field; + unsigned long long field_mask = 1; field = event->format.fields; - while (field) { + for(; field; field = field->next, field_mask <<= 1) { + if (field_mask & ignore_mask) + continue; + trace_seq_printf(s, " %s=", field->name); print_field(s, data, field, &parse); - field = field->next; } } +void tep_print_fields(struct trace_seq *s, void *data, + int size __maybe_unused, struct tep_event *event) +{ + print_selected_fields(s, data, event, 0); +} + +/** + * tep_record_print_selected_fields - print the field name followed by the + * record's field value for a selected subset of record fields. + * @s: The seq to print to + * @record: The record to get the event from + * @event: The event that the field is for + */ +void tep_record_print_fields(struct trace_seq *s, + struct tep_record *record, + struct tep_event *event) +{ + print_selected_fields(s, record->data, event, 0); +} + +/** + * tep_record_print_selected_fields - print the field name followed by the + * record's field value for a selected subset of record fields. + * @s: The seq to print to + * @record: The record to get the event from + * @event: The event that the field is for + * @ignore_mask: Bit mask defining the fields to be ignored + */ +void tep_record_print_selected_fields(struct trace_seq *s, + struct tep_record *record, + struct tep_event *event, + unsigned long long ignore_mask) +{ + print_selected_fields(s, record->data, event, ignore_mask); +} + static int print_function(struct trace_seq *s, const char *format, void *data, int size, struct tep_event *event, struct tep_print_arg *arg) diff --git a/src/event-parse.h b/src/event-parse.h index d4a876f..08dcbd8 100644 --- a/src/event-parse.h +++ b/src/event-parse.h @@ -545,6 +545,13 @@ int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline); void tep_print_field(struct trace_seq *s, void *data, struct tep_format_field *field); +void tep_record_print_fields(struct trace_seq *s, + struct tep_record *record, + struct tep_event *event); +void tep_record_print_selected_fields(struct trace_seq *s, + struct tep_record *record, + struct tep_event *event, + unsigned long long ignore_mask); void tep_print_fields(struct trace_seq *s, void *data, int size __maybe_unused, struct tep_event *event); int tep_strerror(struct tep_handle *tep, enum tep_errno errnum, From patchwork Mon Aug 23 09:56:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12452249 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.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,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 71F10C4338F for ; Mon, 23 Aug 2021 09:56:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F7836137A for ; Mon, 23 Aug 2021 09:56:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233281AbhHWJ5S (ORCPT ); Mon, 23 Aug 2021 05:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235905AbhHWJ5R (ORCPT ); Mon, 23 Aug 2021 05:57:17 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4C53C061757 for ; Mon, 23 Aug 2021 02:56:34 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id u3so35816734ejz.1 for ; Mon, 23 Aug 2021 02:56:34 -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=U3MQE2AamaoVBbnPfL+qk1s9Z6NP0o6v1lmi+5EDpJo=; b=XVXNpg80AWPi/EF7szD+3DKzAy6qeJowrj+uob/OQdbnAoSDoSx0uu7Ih41REmttTe GwwLRUlQoqIixN3HHUB9VlT+hW2CHYRH/GTkwXgtdEMWw2nDWFxLDO1X26WebbbiFMRm cmDP7fFDDtmI7VRhqfB+QghTHf6bLmpDRB6V0QpmbT4zK9eD5O/h/fXUkFbSwXKZBsll KsLv8RpqExCF6bd3l25g2mXUhwAiQpu5XUwuN82AwCs1Q/Z42DJj/uT+YbQm6B+9xmUp 3BAoWlz+NoT84fkN62S0yshhfgNqIHE48UG5RY+JmX2DEFAgpIhZCCt7XXO4m/nwSuBj Op5w== 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=U3MQE2AamaoVBbnPfL+qk1s9Z6NP0o6v1lmi+5EDpJo=; b=tWhtrH/eaU/PuXzJFaIiXCpBDEL/jlcWBx2BCOPleEdkOLBXUhz2T43m66uERDyNM+ ikJ1Wd4M48FczhmR9lmhAhiNJ0LiUWXL/xqz7RnERXKS3Jkpp3HGgbB4GUvKpHXlP3NS LpfH0r7S7KPWe+Io+IS/jc17FtFewu8rVzXL3E0vwhzGCJ3jD59qs06w/M7HvDhHRgFb guJs1mz838TZ68eG/MozC8Nip0puGHGqKKz+64z+21DKa6B4E+U0WhBbXGjivTMAAe1R A7EriiYWhyiJ9YAXb0uI6DXHLNUUNGu1bvO0KH6ES+5wNqHYxunq+tUwtqyVERHDRspv AIxg== X-Gm-Message-State: AOAM532IuMzAld5xlQRa7O+Xvqw3Mxz6UWC+10WUqMzmNpKTPycilXAn jeW8w8Z8zWLWndh68xXPi/0= X-Google-Smtp-Source: ABdhPJzYVkFuOHItcalJ5V/YfbvyK+WZXbLbrTKi46jK1dp5omUv5OWDkkXuOfnThUoWYBMLrgIBKw== X-Received: by 2002:a17:907:1b1b:: with SMTP id mp27mr34058936ejc.538.1629712593482; Mon, 23 Aug 2021 02:56:33 -0700 (PDT) Received: from crow.. ([95.87.199.109]) by smtp.gmail.com with ESMTPSA id y23sm7047831ejp.115.2021.08.23.02.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 02:56:33 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v7 4/4] libtraceevent: Add documentation for the new printing APIs Date: Mon, 23 Aug 2021 12:56:18 +0300 Message-Id: <20210823095618.138887-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823095618.138887-1-y.karadz@gmail.com> References: <20210823095618.138887-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 'tep_record_print_fields()' and 'tep_record_print_selected_fields()' are documented. Signed-off-by: Yordan Karadzhov (VMware) --- Documentation/libtraceevent-field_print.txt | 11 ++++++++++- Documentation/libtraceevent.txt | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/libtraceevent-field_print.txt b/Documentation/libtraceevent-field_print.txt index 2c2cf6c..2b001e3 100644 --- a/Documentation/libtraceevent-field_print.txt +++ b/Documentation/libtraceevent-field_print.txt @@ -3,7 +3,7 @@ libtraceevent(3) NAME ---- -tep_print_field, tep_print_fields, tep_print_num_field, tep_print_func_field - +tep_print_field, tep_print_fields, tep_record_print_fields, tep_record_print_selected_fields, tep_print_num_field, tep_print_func_field - Print the field content. SYNOPSIS @@ -15,6 +15,8 @@ SYNOPSIS void *tep_print_field*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, struct tep_format_field pass:[*]_field_); void *tep_print_fields*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, int _size_, struct tep_event pass:[*]_event_); +void *tep_record_print_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_); +void *tep_record_print_selected_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_, int _ignore_mask_); int *tep_print_num_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_); int *tep_print_func_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_); -- @@ -35,6 +37,13 @@ value according to the field's type: It iterates all fields of the _event_, and calls _tep_print_field()_ for each of them. +The _tep_print_selected_fields()_ prints the field's name followed by its value +for all record's field. + +The _tep_print_selected_fields()_ prints the field's name followed by its value +for selected subset of record field. The fields to be excluded from printing +are defined by the _ignore_mask_ bit mask. + The _tep_print_num_field()_ function prints a numeric field with given format string. A search is performed in the _event_ for a field with _name_. If such field is found, its value is extracted from the _record_ and is printed in the diff --git a/Documentation/libtraceevent.txt b/Documentation/libtraceevent.txt index d42b5c9..2d7318e 100644 --- a/Documentation/libtraceevent.txt +++ b/Documentation/libtraceevent.txt @@ -78,6 +78,8 @@ APIs related to fields from event's format files: Event fields printing: void *tep_print_field*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, struct tep_format_field pass:[*]_field_); void *tep_print_fields*(struct trace_seq pass:[*]_s_, void pass:[*]_data_, int _size_, struct tep_event pass:[*]_event_); + void *tep_record_print_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_); + void *tep_record_print_selected_fields*(struct trace_seq pass:[*]_s_, struct tep_record pass:[*]_record_, struct tep_event pass:[*]_event_, int _ignore_mask_); int *tep_print_num_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_); int *tep_print_func_field*(struct trace_seq pass:[*]_s_, const char pass:[*]_fmt_, struct tep_event pass:[*]_event_, const char pass:[*]_name_, struct tep_record pass:[*]_record_, int _err_);