From patchwork Wed Aug 11 12:11:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12431029 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 19CF2C4338F for ; Wed, 11 Aug 2021 12:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1F0F60041 for ; Wed, 11 Aug 2021 12:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237496AbhHKMMk (ORCPT ); Wed, 11 Aug 2021 08:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237466AbhHKMMk (ORCPT ); Wed, 11 Aug 2021 08:12:40 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A603EC061765 for ; Wed, 11 Aug 2021 05:12:16 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id b13so2760712wrs.3 for ; Wed, 11 Aug 2021 05:12:16 -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=i2H4wpRx0wJUzv3eEjGTSHgcJ1CIjxFeb0CK+qzl27A=; b=UrDNgdTZa9KnNnIGBiT5v1nEB86OwYFF5dq+6ENIUp8ROh9Iw1r0WIHc6QUJJPKW+x J+rBsYePtHaRpMpXvycmFyPYXGBXeadWCLJT99Pzmg5GBGjKT9ryOSiCP+nrb9y5WkEM u+xSOesmyyNspyEYlsclAYnYZO0Uk4vvPL4hMzss+IRrD5b8F39uuaV3jotinsqcXodf bRpHmGo1PRqLrLxKoQyEzshfaTP8NeAMI8QxwGNKOUmQigKMGJIe7meYagGJArcJbFBL itj5gUxIsEwfTpp5B2aCFG2c4yQsrxRe/J39KATnA5v+4l4fIFhr4KaN616/LmzyAT+K Zv1Q== 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=i2H4wpRx0wJUzv3eEjGTSHgcJ1CIjxFeb0CK+qzl27A=; b=FU9qAmsrFokbm8Xa1CW5rYVCqJ+hvw+A4qSZSfm9PC9mucLTU5AtPyFkdLlcPajedt lV3atJlMt2fUuwQbWIu8Phpc/+Vby5TGqeNow2V6kv3wIeHoSCZ5+V75rfYY1K9Y9HyU K5hPjHQuCiscd6QMJJI7IPJCpSSuzZ/yqnqbPsbyrLjQQhpEMZIwozbHVsnpiE69Jqs0 slTYA7CXsFqHDidyFNIwd02MT3GtxKfsyPMKoXNC7Mu0wXzTJzBiCrSuxXYjrbTXs4Yu JQvYThZmXZrGjnC0QyQMVoiaXcOl/TOw64lKlMtXIiyJ2R3seJvKrFO/YU6sXsifT/S6 kufA== X-Gm-Message-State: AOAM530iYBDMos8/adtE6zIrt+BJWwfD+obTZd7bU0qWwnuGDKZxbJNh Rx4/B3bdlEjbFOx3a8IrV1c= X-Google-Smtp-Source: ABdhPJxFqiQSl5HFEYeClozUYo4Q6vfAB7ACvaPi5ngXQNe3yy34vDL+MLdJGiNUVdyT/B4B/zq/pQ== X-Received: by 2002:a5d:694f:: with SMTP id r15mr22211737wrw.86.1628683935193; Wed, 11 Aug 2021 05:12:15 -0700 (PDT) Received: from crow.eng.vmware.com ([146.247.46.133]) by smtp.gmail.com with ESMTPSA id k1sm27104011wrz.61.2021.08.11.05.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:12:14 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v5 1/5] libtraceevent: Add dynamic_offset() Date: Wed, 11 Aug 2021 15:11:59 +0300 Message-Id: <20210811121203.29123-2-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210811121203.29123-1-y.karadz@gmail.com> References: <20210811121203.29123-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 | 134 ++++++++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 71 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index f42ae38..fd6d916 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,27 +4083,14 @@ 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 = (unsigned long long) 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); break; default: /* not sure what to do there */ @@ -4209,12 +4219,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 +4329,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 +4356,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 +4398,33 @@ 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); + offset &= TEP_OFFSET_LEN_MASK; + 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,19 +5329,18 @@ 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)) { trace_seq_printf(s, "%s", (char *)data + offset); From patchwork Wed Aug 11 12:12:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12431031 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 BEBB7C4320A for ; Wed, 11 Aug 2021 12:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FD7B60F56 for ; Wed, 11 Aug 2021 12:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237395AbhHKMMl (ORCPT ); Wed, 11 Aug 2021 08:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237466AbhHKMMl (ORCPT ); Wed, 11 Aug 2021 08:12:41 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 789F4C061765 for ; Wed, 11 Aug 2021 05:12:17 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 203-20020a1c00d40000b02902e6a4e244e4so1798594wma.4 for ; Wed, 11 Aug 2021 05:12:17 -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=xVHdHGYjX9UVBzG4KqE24R9p9HjA9/m50lIgXZE/w7M=; b=cvAKRIXw98+/UbgLmcrNY1Hz3vxSpQwvNy/tWthJn/3klGL0a+d5TbUk2CLAE1uFN3 ckRHg1zOTPD1ZvyMEd0aSa4yRVRK8cM+ELvsFkkxAvB3Z1G9MCoVUzAk78mYFOAapJqC DRNLrM3woHwzl5t9j0sq5ZxVT5udVICgqENtLiE7bxtq8sAdGXqVqeBWvkVOTNq6gn9H ygSzysBvgO63xuzhZIJvmhXAuFst9RGq0Z7BmiQ5Ks3OrXpZFeAQQoXD23JBDe2tjlw0 qaGoffrXX3I+14Vv+OVFh8AM2hvZ0MwMJU4bLtJWJDS/jYx77OAT9Lz09oN47hQWtiPh c6ew== 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=xVHdHGYjX9UVBzG4KqE24R9p9HjA9/m50lIgXZE/w7M=; b=afoiM4r95PJgyCapAjrTlsF5b7pcWRtFLGntdXligNaG492399BnSxqP6lRKu/sXqa M2u/g7mDuuonGxnk7aGzGsrVDU88mr1WYHGw7SSDdTAooASn2bfOXBB7QGRXNmYvw+Ni GLCDP0Ez3bT/aBOSC6qodDsnBZ2YVSLsxUYy+J/q7CxhgQ0LE8pjHWE2qYxrtQ/c6Fyj oXhBB9u73bvCIbRfwuV1aAtZUpO3/qqJUQwSU/w+2qf4L4PLu/pPwtU5a9DBZIaQqiEY LmigoFzp8CvKcX11aHmfs99ZKxampST6IsmgAnSuxHFzhNhCDC4YCMcAi0K6WJmA3KMv gLBA== X-Gm-Message-State: AOAM531MEPxeX+F8WENUnIll44bicxnDYxF+N7OF6oGS3RKhOdcKiSAc jgWkYc/+sXM3z1Wlhuby2s8= X-Google-Smtp-Source: ABdhPJxdXPLIY72fRMKg0G76AGawAZy7mx/COalJ66S1CUOs8DvSbl49paavyM8ekuq/NPpuZX6utQ== X-Received: by 2002:a05:600c:4f83:: with SMTP id n3mr9707043wmq.123.1628683936137; Wed, 11 Aug 2021 05:12:16 -0700 (PDT) Received: from crow.eng.vmware.com ([146.247.46.133]) by smtp.gmail.com with ESMTPSA id k1sm27104011wrz.61.2021.08.11.05.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:12:15 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v5 2/5] libtraceevent: Have all field args point to the field they represent Date: Wed, 11 Aug 2021 15:12:00 +0300 Message-Id: <20210811121203.29123-3-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210811121203.29123-1-y.karadz@gmail.com> References: <20210811121203.29123-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 fd6d916..1a8cc54 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 Wed Aug 11 12:12:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12431035 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 A5D71C4338F for ; Wed, 11 Aug 2021 12:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D7F560041 for ; Wed, 11 Aug 2021 12:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237482AbhHKMMn (ORCPT ); Wed, 11 Aug 2021 08:12:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237466AbhHKMMl (ORCPT ); Wed, 11 Aug 2021 08:12:41 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F7D4C061765 for ; Wed, 11 Aug 2021 05:12:18 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id m36-20020a05600c3b24b02902e67543e17aso3681721wms.0 for ; Wed, 11 Aug 2021 05:12:18 -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=a1rctMg0OfsquAGyMiM/bNxFekwE/wso2d1Z7nrnst0=; b=b/L9ZWuWiHYeG7EjvjqMrTG6lcCm3/FcouT872oYlr8H5p4qN23B370SpOogOPxECw RzvLWUkZXJufgVkvT6Rm+vkLvTiD+tW9wA5HPIvR61VOuY3aQ6rUMA3F0IboGFc2F2FR sdykcKthVqoNEflMYoqfBkVON9PRqAEHdJ00thZhusQDVFKmcHqZkPSDnH8qOVf5nlNf lNjIkReOxY/UtHVXlw+K/cDSPXWSOQazPTkOhsl2TnOkatpu7i6xdmAE5/Jf5cHpzgMB lAH5TuunRhNRrXmWOGcS+uV6Dhwq+vhM0JBDhV6fJZeNLhz/o+wu68buUVMefwEVMmed n59g== 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=a1rctMg0OfsquAGyMiM/bNxFekwE/wso2d1Z7nrnst0=; b=f3bg1xS5IwkF/nr4LxzhWI1X/0KMbIvVo+sznpMaR7fECq4mgL6ml/CPZCYP1vNit/ KvSSR3SK4LO0qv672A3Pohfw7uGisAYh05vx+Wfo5LrLvVDYtNY6IIDTuj538dzyBjXI t8o2xJTb9qOoaJ0g7u93mVvK62cgyKCrbINu8xG/TwcgqpQ/xgHdfJbIkFOdyMpLtn/3 9Vq8y980vHOK3rOwNABu2MmUtTHRJt3+YLxwZZla8msUvhlwAKP8Xlv/+R35F0VWcA3v RRWq7uqWav92hX4oD/pZ1rRt0de9cpptc8n+rhQsVAFfxBtmDM1LYvdHCVAwnAvBMdxG DixQ== X-Gm-Message-State: AOAM532ZbDoNlI6cPSVwF2eEyMIilqRkOqCCfJR/IRs31QyfNex64xma rF56SeABvg9Q56azgea5lJ0= X-Google-Smtp-Source: ABdhPJx0UtE9Dcq/EK+d8TYaglKKf+kjP/esoeUjd+IA0fWaFJLkYxhVe1//ip9CVFNcSy35wxHTEQ== X-Received: by 2002:a7b:cc14:: with SMTP id f20mr9546746wmh.38.1628683936941; Wed, 11 Aug 2021 05:12:16 -0700 (PDT) Received: from crow.eng.vmware.com ([146.247.46.133]) by smtp.gmail.com with ESMTPSA id k1sm27104011wrz.61.2021.08.11.05.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:12:16 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v5 3/5] libtraceevent: Improve tep_print_field() Date: Wed, 11 Aug 2021 15:12:01 +0300 Message-Id: <20210811121203.29123-4-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210811121203.29123-1-y.karadz@gmail.com> References: <20210811121203.29123-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 1a8cc54..9399555 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; @@ -5390,6 +5389,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) { @@ -5909,35 +5958,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 Wed Aug 11 12:12:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12431033 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 D7DFAC43214 for ; Wed, 11 Aug 2021 12:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB51A60041 for ; Wed, 11 Aug 2021 12:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237487AbhHKMMn (ORCPT ); Wed, 11 Aug 2021 08:12:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237498AbhHKMMm (ORCPT ); Wed, 11 Aug 2021 08:12:42 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 495F2C0613D3 for ; Wed, 11 Aug 2021 05:12:19 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c9so2713577wri.8 for ; Wed, 11 Aug 2021 05:12:19 -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=aN7mzu/MTj3+cF47VT4Edvs9x7wxfAW5P2w2A2tkPdo=; b=mnfeFOuSxRzjRgzOHFUOgteJx/P41Q38jDLhNRZ4xWhCdn4V37cjj/PekU5yl3mOn1 bPQGqT5VCB2vBdELEXQgUUkBiuKmzYeJ5M8uq5x7t5hZZtWsHoFh969GTXNHZ63C/mYt sNOSgGVcOF7EWVHqbl6n2HsZn3Y/Y4/z4nXF1JKUmTdehHAillO7rjQImK29YLXpx10A 6cFgFXH5pKM2gwZL8U6UJ3kZGKpx0jPDVWols/cXx7sD00nsrUbZhxB2lAoLflBIdmUq jQg+QLhdSOfp5K6oG7aYp5MEbD/Lsr6GSl566yAeF3UX4zZyyuWvy8R1U4OVSJn//ZjF JZEA== 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=aN7mzu/MTj3+cF47VT4Edvs9x7wxfAW5P2w2A2tkPdo=; b=T6X4eipzYepZAd0GfgwdNFIvGs5TSFZGlvqU3B4CanHfjG5SW8MjzISuZ9Kxhnqg+j qOdftWFbHuU62YWjkkOhFX7OOw3vIhqegwmuCo2oTAjbOT/Zd3W4gNHcN0fUoN9gEV5x IPR4aUThNzW5gU+WsjNdDi0PrAVLh8fuMpCH70AOhyzHIKR+hHYFrqdg25QXOiyHonkj HjvXERBj/8njCU3Ha7AwmIJPS41AcQqeEu3VGhS2xRmSBsmaiMoGkf2x9v+YSe/uubmL KiktheVqI07M6qViuZP+5I4XMCEi9yQNb+VzweOLWE05X1Ne6PAexxRvFvyjgiRCsbaO Eepg== X-Gm-Message-State: AOAM533RJRqKqKhGN7EaHEHReokkjD6/aTVr4Bggs3JzrhiNyNkN+Dfn p+ZYYApNx2I5G1GIUdDLjEI= X-Google-Smtp-Source: ABdhPJxxtEIA1v4ZzMz/Kvubk/UBZj/OTl7iR/NcjnXUQgap50j431IIC3NT946V0Lm/esnJ2hOhBg== X-Received: by 2002:a05:6000:251:: with SMTP id m17mr3662615wrz.68.1628683937938; Wed, 11 Aug 2021 05:12:17 -0700 (PDT) Received: from crow.eng.vmware.com ([146.247.46.133]) by smtp.gmail.com with ESMTPSA id k1sm27104011wrz.61.2021.08.11.05.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:12:17 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v5 4/5] libtraceevent: Optimize tep_print_fields() Date: Wed, 11 Aug 2021 15:12:02 +0300 Message-Id: <20210811121203.29123-5-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210811121203.29123-1-y.karadz@gmail.com> References: <20210811121203.29123-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. Signed-off-by: Yordan Karadzhov (VMware) --- src/event-parse.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/event-parse.c b/src/event-parse.c index 9399555..7831e74 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5392,14 +5392,15 @@ 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 *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) goto out; @@ -5407,7 +5408,7 @@ void tep_print_field(struct trace_seq *s, void *data, if (field->flags & (TEP_FIELD_IS_ARRAY || TEP_FIELD_IS_STRING)) goto out; - for (;parse; parse = parse->next) { + while (parse) { if (parse->type == PRINT_FMT_STRING) { int len = strlen(parse->format); @@ -5417,21 +5418,29 @@ 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; } out: @@ -5439,15 +5448,22 @@ void tep_print_field(struct trace_seq *s, void *data, 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 Wed Aug 11 12:12:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yordan Karadzhov X-Patchwork-Id: 12431037 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 AD2C3C432BE for ; Wed, 11 Aug 2021 12:12:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BEBD60041 for ; Wed, 11 Aug 2021 12:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237382AbhHKMMo (ORCPT ); Wed, 11 Aug 2021 08:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237466AbhHKMMn (ORCPT ); Wed, 11 Aug 2021 08:12:43 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CA7C061765 for ; Wed, 11 Aug 2021 05:12:20 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id k38-20020a05600c1ca6b029025af5e0f38bso4245988wms.5 for ; Wed, 11 Aug 2021 05:12:20 -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=W4Vh3v/PBBsbsJYbpaXK9DNgaUuDuK/o6GViHRy/bsA=; b=LvHD+K80Fz6qWWf/ReRmyBhDmIOJ/W2HbQvfBX2c7Jc0+5sEt1lw8J8bqj9hbLE0sC uuUkxrOvLqdnbLdxpyrlx/eINEUzbROgW52vk09OBMGiKLDONzKNjPCliPyK+MvjiDfF rNMdFdeZtnxgTnC2iVqWAzLuc1YcwknYIdWlDVYZyH35XXCuRPSjuuQjz1APyzmMXuhI aLQ0vudGyB/WE8xI9YB4TKp9hh83e5EDfelUZZsAb/FacyGoQVG4NU7EjhlD+AmpSCna nq3WoJSP0zwq4mUkPspsFQgnsBMYE9mtB6U+MPRxDHCnHn/STf/8pg41mMAM3D9BdXWu wlnQ== 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=W4Vh3v/PBBsbsJYbpaXK9DNgaUuDuK/o6GViHRy/bsA=; b=Ph+a/qHFUFtFvc4nOEKiRHANEPB2vE+h7eFFD9bM35Wdo4j57RqcDtZTQyDG9TCL05 9w/AqA/YykBTbfHq8ly6OV69VEp3ZDkcTbjW01ydHGmuEkMh8O3AHxxn7WGn2XFzUniR /3zyV/qyUEAugJTjGoEGwwTXbbW296osSms+HYzzveQT1lwAfeK7PTNJ9y6X8BI42JrQ J/bIDeef3EBbjI3mqK414+5HpX5TcN7tz2abvOGpbCA8Sja7Nq8JOUMDDPmNIeUhR98H ZWToBFr2dWAPh1mc8qeq5PQtYY+MKskyw5eRSAfsWN8DwaSYLA5TydDMJ9Nj/7QiqqDP cDTw== X-Gm-Message-State: AOAM530/Yyyo9CQ88nVLtbNUo3XDgk3QvplsSy1iTYTHbikLjPHJJyWy BsZFHd6hVhriL8WPSkct0e4= X-Google-Smtp-Source: ABdhPJzvkVZTVIjFs9cW+85HyVfjL80FVKI6jlyLXKqZ9RL8YbWdqpWo3s+pFmahOiyqo6VUo/62/g== X-Received: by 2002:a1c:7dd0:: with SMTP id y199mr2513032wmc.148.1628683938652; Wed, 11 Aug 2021 05:12:18 -0700 (PDT) Received: from crow.eng.vmware.com ([146.247.46.133]) by smtp.gmail.com with ESMTPSA id k1sm27104011wrz.61.2021.08.11.05.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Aug 2021 05:12:18 -0700 (PDT) From: "Yordan Karadzhov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, "Yordan Karadzhov (VMware)" Subject: [PATCH v5 5/5] libtraceevent: Add tep_print_selected_fields() Date: Wed, 11 Aug 2021 15:12:03 +0300 Message-Id: <20210811121203.29123-6-y.karadz@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210811121203.29123-1-y.karadz@gmail.com> References: <20210811121203.29123-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 7831e74..3b93138 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -5454,20 +5454,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,