Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp206428ybx; Tue, 5 Nov 2019 22:31:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyh/IeERNLzZd8qmY94gFdkD3xHkYIdOS2p90JYz5TIjkTGXtNJ4rP33PSpx0l/SrB1ORYb X-Received: by 2002:a50:cd14:: with SMTP id z20mr865546edi.226.1573021908034; Tue, 05 Nov 2019 22:31:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573021908; cv=none; d=google.com; s=arc-20160816; b=l51lZJhHwpyDzjgyBx9FCiQghHaTMAWcNt2HMEtpsd/SyarDJpS8EcaOTojRg7INKK 9ylnusJjNgiqxEAsP09GniqiHx4tvU211BL0QmgQj+34FRXqq9iWwx5EyUnc8sw+u5E3 i1kvn10XUik76ldUI/WwnoRbi4Ws6ZQlzQmOCaRVixV5J6oTnojkpa7FaOj6sX1Xfuld zjhp8skYrbABTITM50bd2r/I4Tk+INPiSUhtPVJ8Z559ov+gaXbA+xUykx/ErhwU6flV TO478O0YvtMZ6iXaqmQ3NL15XLdUtQebufOrIvwzY72YlMNkt7L5tn9yT6CA6Zg3atnc FFKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=jMoQq29zGJI7f5s7hmlkLjA/3AP/gFtwe+iNLgByPoE=; b=yteXbAIjdoganPd3c1vtER8lMZXRW6hDsfpT/1NHbxcPQxBj2Zs0E0mPYKqepEUhrE BEG6+PhFqtH6zcJnw1jfcUPX7vTCrxCtyc8f6KjpvedhszpZ85Ep5a9w1m1o2w5Pksr5 mShcnFfTsYGdJKcWbLhTzdQRS1WBI7LrUF1EUE+2jRe/Nw+jrf7THbwL5UBQsbtZiskR 6hj2HI079r5nwtmY7j5+se4PgGSQyEarfGuUpwBvR+iLDb+kfdHpw1mDwAaVN23yd/Jf XWarvURq5NjRykDn0rk/90mOIUjolIs0q+N422Yj7n9Ii/EUAT5dYwGh7kTFtzR+WEL7 2haw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si7897457ejr.30.2019.11.05.22.31.24; Tue, 05 Nov 2019 22:31:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730804AbfKFG35 (ORCPT + 99 others); Wed, 6 Nov 2019 01:29:57 -0500 Received: from mga11.intel.com ([192.55.52.93]:52106 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725806AbfKFG35 (ORCPT ); Wed, 6 Nov 2019 01:29:57 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2019 22:29:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,272,1569308400"; d="scan'208";a="376952057" Received: from test-hp-compaq-8100-elite-cmt-pc.igk.intel.com ([10.237.149.93]) by orsmga005.jf.intel.com with ESMTP; 05 Nov 2019 22:29:54 -0800 From: Piotr Maziarz To: linux-kernel@vger.kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, andriy.shevchenko@intel.com, cezary.rojewski@intel.com, gustaw.lewandowski@intel.com, Piotr Maziarz Subject: [PATCH 2/2] tracing: Use seq_buf_hex_dump() to dump buffers Date: Wed, 6 Nov 2019 07:27:40 +0100 Message-Id: <1573021660-30540-2-git-send-email-piotrx.maziarz@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1573021660-30540-1-git-send-email-piotrx.maziarz@linux.intel.com> References: <1573021660-30540-1-git-send-email-piotrx.maziarz@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Without this, buffers can be printed with __print_array macro that has no formatting options and can be hard to read. The other way is to mimic formatting capability with multiple calls of trace event with one call per row which gives performance impact and different timestamp in each row. Signed-off-by: Piotr Maziarz Signed-off-by: Cezary Rojewski --- include/linux/trace_events.h | 5 +++++ include/linux/trace_seq.h | 4 ++++ include/trace/trace_events.h | 6 ++++++ kernel/trace/trace_output.c | 15 +++++++++++++++ kernel/trace/trace_seq.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 30a8cdc..60a41b7 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -45,6 +45,11 @@ const char *trace_print_array_seq(struct trace_seq *p, const void *buf, int count, size_t el_size); +const char * +trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str, + int prefix_type, int rowsize, int groupsize, + const void *buf, size_t len, bool ascii); + struct trace_iterator; struct trace_event; diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h index 6609b39a..6c30508 100644 --- a/include/linux/trace_seq.h +++ b/include/linux/trace_seq.h @@ -92,6 +92,10 @@ extern int trace_seq_path(struct trace_seq *s, const struct path *path); extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, int nmaskbits); +extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str, + int prefix_type, int rowsize, int groupsize, + const void *buf, size_t len, bool ascii); + #else /* CONFIG_TRACING */ static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) { diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 4ecdfe2..7089760 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -340,6 +340,12 @@ TRACE_MAKE_SYSTEM_STR(); trace_print_array_seq(p, array, count, el_size); \ }) +#undef __print_hex_dump +#define __print_hex_dump(prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii) \ + trace_print_hex_dump_seq(p, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii) + #undef DECLARE_EVENT_CLASS #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ static notrace enum print_line_t \ diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index d54ce25..d9b4b7c 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -274,6 +274,21 @@ trace_print_array_seq(struct trace_seq *p, const void *buf, int count, } EXPORT_SYMBOL(trace_print_array_seq); +const char * +trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str, + int prefix_type, int rowsize, int groupsize, + const void *buf, size_t len, bool ascii) +{ + const char *ret = trace_seq_buffer_ptr(p); + + trace_seq_putc(p, '\n'); + trace_seq_hex_dump(p, prefix_str, prefix_type, + rowsize, groupsize, buf, len, ascii); + trace_seq_putc(p, 0); + return ret; +} +EXPORT_SYMBOL(trace_print_hex_dump_seq); + int trace_raw_output_prep(struct trace_iterator *iter, struct trace_event *trace_event) { diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c index 6b1c562..344e4c1 100644 --- a/kernel/trace/trace_seq.c +++ b/kernel/trace/trace_seq.c @@ -376,3 +376,33 @@ int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, int cnt) return seq_buf_to_user(&s->seq, ubuf, cnt); } EXPORT_SYMBOL_GPL(trace_seq_to_user); + +int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str, + int prefix_type, int rowsize, int groupsize, + const void *buf, size_t len, bool ascii) +{ + unsigned int save_len = s->seq.len; + + if (s->full) + return 0; + + __trace_seq_init(s); + + if (TRACE_SEQ_BUF_LEFT(s) < 1) { + s->full = 1; + return 0; + } + + seq_buf_hex_dump(&(s->seq), prefix_str, + prefix_type, rowsize, groupsize, + buf, len, ascii); + + if (unlikely(seq_buf_has_overflowed(&s->seq))) { + s->seq.len = save_len; + s->full = 1; + return 0; + } + + return 1; +} +EXPORT_SYMBOL(trace_seq_hex_dump); -- 2.7.4