From patchwork Thu Aug 12 08:59:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12432947 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,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 EF305C4320E for ; Thu, 12 Aug 2021 08:59:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D15276103E for ; Thu, 12 Aug 2021 08:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235563AbhHLJAL (ORCPT ); Thu, 12 Aug 2021 05:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235554AbhHLJAK (ORCPT ); Thu, 12 Aug 2021 05:00:10 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72FD6C061765 for ; Thu, 12 Aug 2021 01:59:45 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id f12-20020a05600c4e8c00b002e6bdd6ffe2so721754wmq.5 for ; Thu, 12 Aug 2021 01:59:45 -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=QtkJ6ZALgTNSy7VLgL2PDkX1XgyDCXzQ65ibXDKaNfk=; b=HNnU8M8/hSiYqKqwIT24R245akN18PELZoYnWiEA/xIRsIF9Nx/4nSKD07/aKTuuEj PPOqm9l2TbhU8LSEgYmX6bNKGXIIeKEpBUYJk+qMgLp4C/C01HzeunpWVX4EhLB3Zf4c 8f6CbRrVhmvhx2zp5DFbbF2ylisYcZB1Zcra3UZWZ6Lhhhx41x23bS87aNBIj6wCiRoZ 9vl9w+0o6DuodumJuNx/lw82pYrB8XUXgxokLWtdCfah9Jcu+H0Hze8auwLow3wc3FmW GYlZGA/1w3UnGnfKM9IAMtGHwGK/wJ54SzLrGs1isXv7LY80Kgwqq+3+7jovTICNTnUg OPaQ== 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=QtkJ6ZALgTNSy7VLgL2PDkX1XgyDCXzQ65ibXDKaNfk=; b=l5nHE0lawA618WTX7Ff/IQAMOwOxcDqFraCiuELQjlPEwFtkpaPKF7N6W3s7mvVpkV XONTgpBBuFdXvxnQi21vkcINkZJVM0VhxSQ8zOGh43ceMJT7iq92Q+9qKnj+TS9xYw2f tpKb4sGYuxTcJ2pM5r4QZqBEYwzp2ei1zougKPIrdZsgG44GTUyvbGnCodt/gOzrgzLp YIuwJ5q2TQ5RT59QI4v8j7hgxv1/HhSNXsZxcDxXkvdyo/ZMGA8ORrYa1ZGClU2IaKEH 1hJGwBIOEXTOmKwljheQf/6o26ifYYpE0Am/Hd6wGQQQc6PfFW7Q8e/JNPLf+KPAKxVL 3ImQ== X-Gm-Message-State: AOAM530TS5+xdj65MS0Ec8bwNtvy0e6uh8P/ncVwlCANeBAYL4PautPT 3zKNJmAK9ZS9058a1IQAxgs= X-Google-Smtp-Source: ABdhPJz+1vSjH/QdbWw1D2snp+krxKpA+KW+22/HDBxJNOp+6MROFp/Nb9Y6YyMzqcOf/xkaLrMe8A== X-Received: by 2002:a1c:5411:: with SMTP id i17mr2749632wmb.183.1628758784071; Thu, 12 Aug 2021 01:59:44 -0700 (PDT) Received: from crow.. ([146.247.46.131]) by smtp.gmail.com with ESMTPSA id m10sm936683wro.63.2021.08.12.01.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 01:59:43 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v6 1/5] libtraceevent: Add dynamic_offset() Date: Thu, 12 Aug 2021 11:59:25 +0300 Message-Id: <20210812085929.54832-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812085929.54832-1-y.karadz@gmail.com> References: <20210812085929.54832-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The total allocated length of the dynamic array is stored in the top half of the corresponding 32 bit field and the offset is in the bottom half of the same field. Since the decoding of the length and offset is performed in multiple locations is the code, we define a static helper function to replace/cleanup the existing open coded conversions. Suggested-by: Steven Rostedt Signed-off-by: Yordan Karadzhov (VMware) --- src/event-parse.c | 133 +++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 71 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index f42ae38..62b56bb 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -3858,6 +3858,36 @@ static unsigned long long test_for_symbol(struct tep_handle *tep, return val; } +#define TEP_OFFSET_LEN_MASK 0xffff +#define TEP_LEN_SHIFT 16 + +static void dynamic_offset(struct tep_handle *tep, int size, void *data, + unsigned int *offset, unsigned int *len) +{ + unsigned long long val; + + /* + * The total allocated length of the dynamic array is + * stored in the top half of the field and the offset + * is in the bottom half of the 32 bit field. + */ + val = tep_read_number(tep, data, size); + + if (offset) + *offset = (unsigned int)(val & TEP_OFFSET_LEN_MASK); + if (len) + *len = (unsigned int)((val >> TEP_LEN_SHIFT) & TEP_OFFSET_LEN_MASK); +} + +static inline void dynamic_offset_field(struct tep_handle *tep, + struct tep_format_field *field, + void *data, + unsigned int *offset, + unsigned int *len) +{ + dynamic_offset(tep, field->size, data + field->offset, offset, len); +} + static unsigned long long eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg *arg) { @@ -3866,7 +3896,7 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg unsigned long long left, right; struct tep_print_arg *typearg = NULL; struct tep_print_arg *larg; - unsigned long offset; + unsigned int offset; unsigned int field_size; switch (arg->type) { @@ -3930,18 +3960,11 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg switch (larg->type) { case TEP_PRINT_DYNAMIC_ARRAY: - offset = tep_read_number(tep, - data + larg->dynarray.field->offset, - larg->dynarray.field->size); + dynamic_offset_field(tep, larg->dynarray.field, data, + &offset, NULL); + offset += right; if (larg->dynarray.field->elementsize) field_size = larg->dynarray.field->elementsize; - /* - * The actual length of the dynamic array is stored - * in the top half of the field, and the offset - * is in the bottom half of the 32 bit field. - */ - offset &= 0xffff; - offset += right; break; case TEP_PRINT_FIELD: if (!larg->field.field) { @@ -4060,28 +4083,16 @@ eval_num_arg(void *data, int size, struct tep_event *event, struct tep_print_arg } break; case TEP_PRINT_DYNAMIC_ARRAY_LEN: - offset = tep_read_number(tep, - data + arg->dynarray.field->offset, - arg->dynarray.field->size); - /* - * The total allocated length of the dynamic array is - * stored in the top half of the field, and the offset - * is in the bottom half of the 32 bit field. - */ - val = (unsigned long long)(offset >> 16); + dynamic_offset_field(tep, arg->dynarray.field, data, + NULL, &field_size); + val = field_size; break; case TEP_PRINT_DYNAMIC_ARRAY: /* Without [], we pass the address to the dynamic data */ - offset = tep_read_number(tep, - data + arg->dynarray.field->offset, - arg->dynarray.field->size); - /* - * The total allocated length of the dynamic array is - * stored in the top half of the field, and the offset - * is in the bottom half of the 32 bit field. - */ - offset &= 0xffff; + dynamic_offset_field(tep, arg->dynarray.field, data, + &offset, NULL); val = (unsigned long long)((unsigned long)data + offset); + val = (unsigned long)data + offset; break; default: /* not sure what to do there */ return 0; @@ -4209,12 +4220,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, struct tep_print_flag_sym *flag; struct tep_format_field *field; struct printk_map *printk; + unsigned int offset, len; long long val, fval; unsigned long long addr; char *str; unsigned char *hex; int print; - int i, len; + int i; switch (arg->type) { case TEP_PRINT_NULL: @@ -4318,11 +4330,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, case TEP_PRINT_HEX: case TEP_PRINT_HEX_STR: if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) { - unsigned long offset; - offset = tep_read_number(tep, - data + arg->hex.field->dynarray.field->offset, - arg->hex.field->dynarray.field->size); - hex = data + (offset & 0xffff); + dynamic_offset_field(tep, arg->hex.field->dynarray.field, data, + &offset, NULL); + hex = data + offset; } else { field = arg->hex.field->field.field; if (!field) { @@ -4347,13 +4357,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, int el_size; if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) { - unsigned long offset; - struct tep_format_field *field = - arg->int_array.field->dynarray.field; - offset = tep_read_number(tep, - data + field->offset, - field->size); - num = data + (offset & 0xffff); + dynamic_offset_field(tep, arg->int_array.field->dynarray.field, data, + &offset, NULL); + num = data + offset; } else { field = arg->int_array.field->field.field; if (!field) { @@ -4393,42 +4399,32 @@ static void print_str_arg(struct trace_seq *s, void *data, int size, case TEP_PRINT_TYPE: break; case TEP_PRINT_STRING: { - int str_offset; - int len; - if (arg->string.offset == -1) { struct tep_format_field *f; f = tep_find_any_field(event, arg->string.string); arg->string.offset = f->offset; } - str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset)); - len = (str_offset >> 16) & 0xffff; + dynamic_offset(tep, 4, data + arg->string.offset, &offset, &len); /* Do not attempt to save zero length dynamic strings */ if (!len) break; - str_offset &= 0xffff; - print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset); + print_str_to_seq(s, format, len_arg, ((char *)data) + offset); break; } case TEP_PRINT_BSTRING: print_str_to_seq(s, format, len_arg, arg->string.string); break; case TEP_PRINT_BITMASK: { - int bitmask_offset; - int bitmask_size; - if (arg->bitmask.offset == -1) { struct tep_format_field *f; f = tep_find_any_field(event, arg->bitmask.bitmask); arg->bitmask.offset = f->offset; } - bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset)); - bitmask_size = bitmask_offset >> 16; - bitmask_offset &= 0xffff; + dynamic_offset(tep, 4, data + arg->bitmask.offset, &offset, &len); print_bitmask_to_seq(tep, s, format, len_arg, - data + bitmask_offset, bitmask_size); + data + offset, len); break; } case TEP_PRINT_OP: @@ -5271,13 +5267,12 @@ static int print_raw_buff_arg(struct trace_seq *s, const char *ptr, void *data, int size, struct tep_event *event, struct tep_print_arg *arg, int print_len) { + unsigned int offset, arr_len; int plen = print_len; char *delim = " "; int ret = 0; char *buf; int i; - unsigned long offset; - int arr_len; switch (*(ptr + 1)) { case 'C': @@ -5304,11 +5299,9 @@ static int print_raw_buff_arg(struct trace_seq *s, const char *ptr, return ret; } - offset = tep_read_number(event->tep, - data + arg->dynarray.field->offset, - arg->dynarray.field->size); - arr_len = (unsigned long long)(offset >> 16); - buf = data + (offset & 0xffff); + dynamic_offset_field(event->tep, arg->dynarray.field, data, + &offset, &arr_len); + buf = data + offset; if (arr_len < plen) plen = arr_len; @@ -5336,18 +5329,16 @@ static int is_printable_array(char *p, unsigned int len) void tep_print_field(struct trace_seq *s, void *data, struct tep_format_field *field) { - unsigned long long val; - unsigned int offset, len, i; struct tep_handle *tep = field->event->tep; + unsigned int offset, len, i; + unsigned long long val; if (field->flags & TEP_FIELD_IS_ARRAY) { - offset = field->offset; - len = field->size; if (field->flags & TEP_FIELD_IS_DYNAMIC) { - val = tep_read_number(tep, data + offset, len); - offset = val; - len = offset >> 16; - offset &= 0xffff; + dynamic_offset_field(tep, field, data, &offset, &len); + } else { + offset = field->offset; + len = field->size; } if (field->flags & TEP_FIELD_IS_STRING && is_printable_array(data + offset, len)) { From patchwork Thu Aug 12 08:59:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12432945 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,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 8055FC43214 for ; Thu, 12 Aug 2021 08:59:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56BFD6108C for ; Thu, 12 Aug 2021 08:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235559AbhHLJAL (ORCPT ); Thu, 12 Aug 2021 05:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235566AbhHLJAL (ORCPT ); Thu, 12 Aug 2021 05:00:11 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F020C061765 for ; Thu, 12 Aug 2021 01:59:46 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id k29so7193839wrd.7 for ; Thu, 12 Aug 2021 01:59:46 -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=ZeMg1CH8uTrgXIBuHu2Gci6pzh1HB3V82fxaxaegB7w=; b=LHQ+yR32SOrOl5yYKVxNe8KospLtZA7qbhdfkV0g2KrmgJlAhzm9L6hUy2/QiwcE43 hPDcRE5KR+ykklfiQnAA5ADDWIB2M63NlyXuc7X/xHEMPxtTnmlCtxpRDgLJLttGLZ1G APfPKdyq5LtkKwiOzAvCzgQGpi7I3ZXpLj1fBKPFTux1AS13mdztpy1bR/Yhi9TRm0Gr 9T4jlcm/dFKfGjk3um6GqmIKw3wFsZna1zmNWtvCBrAHRJxRcv9A4F8Otc69C8E/YXeq ak9cIOdwbbLgSGhUMTVJrVvpq0JPoLfIdjXMbQ7DjpBh74ueh5ClykJXoFq3i17anUcI pv+A== 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=ZeMg1CH8uTrgXIBuHu2Gci6pzh1HB3V82fxaxaegB7w=; b=Aa12AiAtpRXzCfpGIh/kUHnIMPVSIyfVJEfCKoRAqN969aygKAXCjyHgtiNoCwwnWv LBnlh7LpSwhdsQK2b6i9v4wsEAlHDNrwhPPECyyQZQ0JQTmVgKwfrXRhn2o0kZBLvegH tmsEJG5B/HDAbMN9ygLJ0+KqPThFa5KW085hcFVfQFjTlwXLj542WjSG5oDr0/negikP OcjoFx03yoQK/BCoWXQg4LSKLbEo8ITnizAUVXcwjmKu+Xs0I1eOSdN+oPWHQirbC29m 0qPAUzU+9YrxqBVeTOCvwhX1/MzCBH+OJ0SY74nb34xRoidaGdgVRbb+8aBbIkjcq6q1 qk8Q== X-Gm-Message-State: AOAM533Bc1R3Bg7cErTjUbZQigUMCBrp/zhhgjCP2cfoHOq7TAJ6Uide aR9+uY7aqN2blYo0zqhpUKQ= X-Google-Smtp-Source: ABdhPJx23jUpn36HJZyxdFQrZomvTVRFVOdnh+k2bX4rkW5PFicvsCqOOT6ncOidJS1S8IgkJtEn+A== X-Received: by 2002:a5d:59aa:: with SMTP id p10mr2833108wrr.0.1628758784874; Thu, 12 Aug 2021 01:59:44 -0700 (PDT) Received: from crow.. ([146.247.46.131]) by smtp.gmail.com with ESMTPSA id m10sm936683wro.63.2021.08.12.01.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 01:59:44 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v6 2/5] libtraceevent: Have all field args point to the field they represent Date: Thu, 12 Aug 2021 11:59:26 +0300 Message-Id: <20210812085929.54832-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812085929.54832-1-y.karadz@gmail.com> References: <20210812085929.54832-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: Steven Rostedt In order to have tep_print_field() print the field closer to the way it is printed via the "pretty_print" method, all field args, must keep a pointer to the field it represents. Signed-off-by: Steven Rostedt (VMware) --- src/event-parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 62b56bb..02ec677 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -2334,12 +2334,12 @@ process_entry(struct tep_event *event __maybe_unused, struct tep_print_arg *arg, arg->type = TEP_PRINT_FIELD; arg->field.name = field; + arg->field.field = tep_find_any_field(event, arg->field.name); + if (is_flag_field) { - arg->field.field = tep_find_any_field(event, arg->field.name); arg->field.field->flags |= TEP_FIELD_IS_FLAG; is_flag_field = 0; } else if (is_symbolic_field) { - arg->field.field = tep_find_any_field(event, arg->field.name); arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC; is_symbolic_field = 0; } From patchwork Thu Aug 12 08:59:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12432949 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,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 58083C4338F for ; Thu, 12 Aug 2021 08:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FD596109F for ; Thu, 12 Aug 2021 08:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235576AbhHLJAM (ORCPT ); Thu, 12 Aug 2021 05:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235565AbhHLJAM (ORCPT ); Thu, 12 Aug 2021 05:00:12 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED4BEC061765 for ; Thu, 12 Aug 2021 01:59:46 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id x12so7181255wrr.11 for ; Thu, 12 Aug 2021 01:59:46 -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=SIBLTYvJPHen1mAC44ubeKZgPZiJLiQt3s/cP7c8bhw=; b=GEMRSa9HF7GR0LwiwSR20McFGiRpjtFMPF0aAqdagFRAIwKYewNtm4EUFIqIPz3DtU vbWIxN2nigmzbuptFo6f6ghz3mA+ZHQR6P6lBzDPpCpswdNVf/BuZyGj3Q164V/lJ4Bs 7TQLr+BzuoAw1TZIBxTtwm//nZX3b2XiK7A9hd9I43N2+MFp2OSS7C0MBtvMYVjhbm2g 3uARdeJmJdH5uzvHppSDmZZrjvMRuTUxA9UvZ3sTOPbLFPQghppdGl1tpcO6cFaBASoV PT10jNaBFXxMUxmkGJ2d28fuzI2ynabf+P12AfFEO1qQ2yasxRjAVeP1TKCR18UHJBBt hY0A== 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=SIBLTYvJPHen1mAC44ubeKZgPZiJLiQt3s/cP7c8bhw=; b=Mdes9levqFn9F7wNDfBh/CLwEyWhZLY1ABlX7xwh+QoqFg5uPYEviuhjn8QKosfDvo ofbIJB6rqArkIEiOI9lmTl/tgK+dquv5D/MGr76VRWghDE2OhmdVxfwiE2bnvgw6rbDa N+UjhoeS6Z1R/qXMnAjp8tIAxlUzBppY0xHmhRr921dxOAhRiaI8n7dqUfRLbWCzbhvd DDM/MxTecg9zyQjcB92bCL616QR9aanrXtb/jj9HGrpJwa3gHfn9/9oq+wg0KgTOrX+d ZLRV2TeioOUwuRNoTPYQUJA9tJghIm9P8x2yyZVSFOONeoYCFVPo0ie9+5QvopivC8SA FU/A== X-Gm-Message-State: AOAM530ALoXeaHLZclhQ4rjmB8kZh0FiC5l62/T5n+fsglN9TBtZryDt hz3ij9nAzi21WW9W3jdkikS7BftA+oI= X-Google-Smtp-Source: ABdhPJzcfqO47u5WpF7fNNBviCEVlCr3yDbIATLSYHw38cZph4xfQBvPzrWwfHB5TBM7yXNlryzxtA== X-Received: by 2002:a5d:4885:: with SMTP id g5mr2843079wrq.29.1628758785626; Thu, 12 Aug 2021 01:59:45 -0700 (PDT) Received: from crow.. ([146.247.46.131]) by smtp.gmail.com with ESMTPSA id m10sm936683wro.63.2021.08.12.01.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 01:59:45 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v6 3/5] libtraceevent: Improve tep_print_field() Date: Thu, 12 Aug 2021 11:59:27 +0300 Message-Id: <20210812085929.54832-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812085929.54832-1-y.karadz@gmail.com> References: <20210812085929.54832-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..ff7337f 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 tep_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. */ + tep_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 Thu Aug 12 08:59:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12432951 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 A869EC432BE for ; Thu, 12 Aug 2021 08:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C5D96103E for ; Thu, 12 Aug 2021 08:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235578AbhHLJAN (ORCPT ); Thu, 12 Aug 2021 05:00:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235567AbhHLJAM (ORCPT ); Thu, 12 Aug 2021 05:00:12 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9C0C0613D5 for ; Thu, 12 Aug 2021 01:59:47 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id i10-20020a05600c354ab029025a0f317abfso6516964wmq.3 for ; Thu, 12 Aug 2021 01:59:47 -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=qYZPyw4p6o7JrMMISIi2KHjbnWHm2hnnIklxRm3d0KM=; b=rMheq6/MR6iQn3JrrUJss9Fzyah56n1jl6FgYKfTxTwc0JtaPosN0FPtDrX0wxlNNQ X25SviDuLPrphNtPuf4tbKa8TiESbSctNePC8RFDsBnzhfTmMz3zfwTfQGpF701iKi0t DATAuiDgm3veVZJhheZl+H9BP9dUQUGx3COEZa2eOEeL2MTT35Mur0nSBXLFKxW2ICv2 pV6+NYdNSCpJBldS/EOxHHhtZmUMyGeFEMCGO0PLyeZZ0keLzT3L+ESfRupzahf8++on 8YpjtMA0tCnMwfoPamPu5am/aeRwtqCWw5EM2r8HNNKbQ1Jeoa8sBXRrUq347pQO6NZ5 /cXA== 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=qYZPyw4p6o7JrMMISIi2KHjbnWHm2hnnIklxRm3d0KM=; b=IrrzAHNsl3z6Ucsgg/bRm2CAVeyjtVlhQ02jGMcevyp7EUfCR8LckVGfp3rYA5BOX7 MMmFBDqRbZRjzet8wmTXOkP8VGXKYqPb4ZqwhjrDCE4OudpYP0pzd9SGwQ2uIrJzAoXP bFH7ZAUzqhxljRIE3skFhCzNeC1jWwyHa3n9qtxIEYqG7tJTrV5G0vksgz1E6+47VMq9 fKCO4ms00+OeS73+U8crKRCaaPV4fg2XJQYAZSwJJyTZRXK2n5EJzTtxv8PpAPoZXvml 9FLe5nmksGXQdUNdMmC5DCWwFvmsUomPYEGFYg20TmN5EuoQ2WaZHIpyNbSCy1nSohF9 u6Uw== X-Gm-Message-State: AOAM530Hbqe5oBptNkuUq9836TPGVj3ohocurVR4FsJFo6l30AoMm38/ 22jPSkaIgudf/zqJq96ZD5k= X-Google-Smtp-Source: ABdhPJyl9tMMVXiJZgw47aGsIbmcS+64HvPKZZF5xfhGR52OZ9cedbXCDn25KJkgTLGSAJyBrylmwg== X-Received: by 2002:a7b:cf21:: with SMTP id m1mr14054634wmg.35.1628758786293; Thu, 12 Aug 2021 01:59:46 -0700 (PDT) Received: from crow.. ([146.247.46.131]) by smtp.gmail.com with ESMTPSA id m10sm936683wro.63.2021.08.12.01.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 01:59:46 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v6 4/5] libtraceevent: Optimize tep_print_fields() Date: Thu, 12 Aug 2021 11:59:28 +0300 Message-Id: <20210812085929.54832-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812085929.54832-1-y.karadz@gmail.com> References: <20210812085929.54832-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 ff7337f..0795135 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5391,22 +5391,25 @@ static void tep_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 _tep_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. */ tep_print_field_raw(s, data, field); } +void tep_print_field(struct trace_seq *s, void *data, + struct tep_format_field *field) +{ + _tep_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); + _tep_print_field(s, data, field, &parse); field = field->next; } } From patchwork Thu Aug 12 08:59:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12432953 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 8AAD6C04FE3 for ; Thu, 12 Aug 2021 08:59:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D5C16103A for ; Thu, 12 Aug 2021 08:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235554AbhHLJAP (ORCPT ); Thu, 12 Aug 2021 05:00:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235565AbhHLJAN (ORCPT ); Thu, 12 Aug 2021 05:00:13 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B555C0613D3 for ; Thu, 12 Aug 2021 01:59:48 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q11so7195480wrr.9 for ; Thu, 12 Aug 2021 01:59:48 -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=crsc3dqZeDy4sTG57qneVCoYVmUYscYcQDH1CTj/L00=; b=uL5MoaQrkpbNYB0lPZ3y490KlNgJSd/r8b9pOjVAi2IvwKxaNuTMcnN8QiTANRUfVp 3Mr5px3E65/kUCmaHAf6n0JKDJ6A9lVDnpVukf5zvMH0Ii36pBvVR7gUZ1JFHOGK9n8M DCyidxLCM+4xDJm/psSZKKRTHRjuUvAY2vvfdTHbxaBe5Rw2N1t89KuYUFW5BDYtcHeJ C3Ob3khixwFHN+kR7nemACX/1scmYFf7GhYwP9TsoE4yo20nqMIquvJXHYfOyZc+o83S 1rsTZIYb7f3lJVgRwhA52L14IL0Wn3NeTzpqi56SXXcY19jnXc/MjhoyNzrfheZ6Rt5/ FQLQ== 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=crsc3dqZeDy4sTG57qneVCoYVmUYscYcQDH1CTj/L00=; b=bfZfR/2wFMWpeWn6Fq2V1LBbhfVPKImGC7EGNh/GRRU5XaXnHULTwYTIiND2Gk3mvN Chk1vKUESQZb5dwYlfzM1wC6i2RgFWt3WyrheHbFJTlV21y7mAJJ9lvaq7et7G+vm9mf +AQfK9GljbJhmkVAVIntVXyU/v/zAOzc2RGvPenjhkt8yJrSrUWAakwS6IgOmkSsEx1x WGvk43/v7mbvR6FR+2DRf0dt9WTxEiaOZxOE3sGIfwKBNN0AaNiIoaPQlKae1+5d7cbE CSyvCxaW5WpI4KUENlkt4dvJDmGazjaAhP+sCd48+SV3Pal9FAyTeSc8uJJhUbHNh6HM zkow== X-Gm-Message-State: AOAM5311NPAtyYELBSVosW90HqwReJzLKYw71Tns1pgBKwLFyq6iXGoE zsM51eEJblgJ50eChEhmDDKxTcpdlqs= X-Google-Smtp-Source: ABdhPJxtxiMSH5tk65SGoklbzysX/z9xk7q3OxJqDASuP9r5hNyTWGQTsGekVTK6gr02FqljKj0JYQ== X-Received: by 2002:a5d:42cf:: with SMTP id t15mr531373wrr.275.1628758787186; Thu, 12 Aug 2021 01:59:47 -0700 (PDT) Received: from crow.. ([146.247.46.131]) by smtp.gmail.com with ESMTPSA id m10sm936683wro.63.2021.08.12.01.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 01:59:46 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v6 5/5] libtraceevent: Add tep_print_selected_fields() Date: Thu, 12 Aug 2021 11:59:29 +0300 Message-Id: <20210812085929.54832-6-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210812085929.54832-1-y.karadz@gmail.com> References: <20210812085929.54832-1-y.karadz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new method can print only a subset of the unique data 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 | 26 ++++++++++++++++++++++---- src/event-parse.h | 3 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 0795135..645506e 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5455,20 +5455,38 @@ void tep_print_field(struct trace_seq *s, void *data, _tep_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 *= 2) { + if (field_mask & ignore_mask) + continue; + trace_seq_printf(s, " %s=", field->name); _tep_print_field(s, data, field, &parse); - field = field->next; } } +void tep_print_selected_fields(struct trace_seq *s, void *data, + struct tep_event *event, + unsigned long long ignore_mask) +{ + print_selected_fields(s, data, event, ignore_mask); +} + +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); +} + 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..e3638cf 100644 --- a/src/event-parse.h +++ b/src/event-parse.h @@ -545,6 +545,9 @@ 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_print_selected_fields(struct trace_seq *s, void *data, + 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,