From patchwork Tue Sep 14 13:14:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493243 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 2960DC433F5 for ; Tue, 14 Sep 2021 13:14:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F815610A6 for ; Tue, 14 Sep 2021 13:14:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233196AbhINNQA (ORCPT ); Tue, 14 Sep 2021 09:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233105AbhINNQA (ORCPT ); Tue, 14 Sep 2021 09:16:00 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2318C061574 for ; Tue, 14 Sep 2021 06:14:42 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id q26so20140016wrc.7 for ; Tue, 14 Sep 2021 06:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BZCtjHFPlHFe/7TFK53gM0VIBu7ki6VB+TSybcYxPsg=; b=bWXZy9xeB5f61Tix1fDrs+xQaqSWRFN3TClIOk34T4njW7MTyGFvUefRpv94nexBB6 Ub7oye1WCHcEunFDVyFw1c3Chp7LXVesQGk1vaRHMueDH3CInLlGXlsugXOOYhR4bF6f InC52jAWeRVl8lqRcRmJcjof/V70BMYpNMzqgkR+YywoIo+9keAFBpk+OQyQxmrK0EW9 7fMNR/aRzfhSsT41IXwrDRbDwCuOgBDX2HXRlCUZdAAOft9shF7mtZvMWOMVhSB4gPrQ iiBBp/2aPzVak+71T9JIcrlMiitoDg1f9eIYFRBJndzLBfugubtnklm84AzV+8g947zw 43dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BZCtjHFPlHFe/7TFK53gM0VIBu7ki6VB+TSybcYxPsg=; b=KJIPw5tl04ftKsk501KjCW4zI6uKnwdjh6Q7dJZTRZziDgDKBjHUj06zr+bjKTndNE Ryv77HWn63xnRBYSr68lW8dcotsOOvpDW2MIdgirqKQV7MxcnryFzNVjO9qCzSvYSdev md05oCUHjksPp6xTv2mJtaxNr0uc39Fl3v9w2d+XTOo0VcCcmeW6/tI19ZMj4fCW1Tl0 jeaK/SR8blPqzHuJtqv1rwz6WjBAOLu01S5x8f58Hp83VE/RkLw5qWzNApETvJWH7W80 pz+W2nJVramD/tdmBAECdiLCIKN+Vtj+mf8WqAaUmcgrV39wqJ9yz4OE7Nizj0o5jSF+ 1Ghg== X-Gm-Message-State: AOAM5335uPjeOIHHyQ1B0gLO20uqOvLw3kAr5wxLsjtiIeKquD06iO3/ m/3yksx9q7/8CtL6PHYVbFw6Kkz4KVs= X-Google-Smtp-Source: ABdhPJzSKsbBBJ+z6G9140odax+gyAQjrW/o0pppsMxSFevW9IwFEEdt8TFraat5YpOQYd7eKCjOKA== X-Received: by 2002:adf:82a8:: with SMTP id 37mr19052775wrc.409.1631625281454; Tue, 14 Sep 2021 06:14:41 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:40 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 01/25] trace-cmd library: Define trace file version 7 Date: Tue, 14 Sep 2021 16:14:14 +0300 Message-Id: <20210914131438.3965484-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added a define for file version 7, but keep the default file version to 6. Defined the new file version as the first version that supports trace file sections. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 6 ++++++ lib/trace-cmd/include/trace-cmd-local.h | 7 ------- lib/trace-cmd/trace-output.c | 4 +++- lib/trace-cmd/trace-util.c | 2 +- tracecmd/trace-record.c | 2 ++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 97cd82f8..e21bc3bf 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -31,6 +31,12 @@ struct tep_plugin_list *trace_load_plugins(struct tep_handle *tep, int flags); int *tracecmd_add_id(int *list, int id, int len); +#define FILE_VERSION_DEFAULT 6 +#define FILE_VERSION_MIN 6 +#define FILE_VERSION_MAX 7 + +#define FILE_VERSION_SECTIONS 7 + enum { RINGBUF_TYPE_PADDING = 29, RINGBUF_TYPE_TIME_EXTEND = 30, diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index 547ee5c3..e11dce58 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -14,13 +14,6 @@ void tracecmd_warning(const char *fmt, ...); void tracecmd_critical(const char *fmt, ...); void tracecmd_info(const char *fmt, ...); -/* trace.dat file format version */ -#define FILE_VERSION 6 - -#define _STR(x) #x -#define STR(x) _STR(x) -#define FILE_VERSION_STRING STR(FILE_VERSION) - #ifndef htonll # if __BYTE_ORDER == __LITTLE_ENDIAN #define htonll(x) __bswap_64(x) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index c1bfcb66..3d7c0e85 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -84,6 +84,8 @@ struct list_event_system { char *name; }; +#define HAS_SECTIONS(H) ((H)->file_version >= FILE_VERSION_SECTIONS) + static stsize_t do_write_check(struct tracecmd_output *handle, const void *data, tsize_t size) { @@ -919,7 +921,7 @@ struct tracecmd_output *tracecmd_output_allocate(int fd) handle->fd = fd; - handle->file_version = FILE_VERSION; + handle->file_version = FILE_VERSION_DEFAULT; handle->page_size = getpagesize(); diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index db7ce7ee..d28b6ec2 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -620,7 +620,7 @@ unsigned long long tracecmd_generate_traceid(void) bool tracecmd_is_version_supported(unsigned int version) { - if (version <= FILE_VERSION) + if (version >= FILE_VERSION_MIN && version <= FILE_VERSION_MAX) return true; return false; } diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 78b0f5ec..35d9ee5f 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -214,6 +214,7 @@ struct common_record_context { int topt; int run_command; int saved_cmdlines_size; + int file_version; }; static void add_reset_file(const char *file, const char *val, int prio) @@ -5974,6 +5975,7 @@ static void init_common_record_context(struct common_record_context *ctx, ctx->instance = &top_instance; ctx->curr_cmd = curr_cmd; local_cpu_count = tracecmd_count_cpus(); + ctx->file_version = FILE_VERSION_DEFAULT; init_top_instance(); } From patchwork Tue Sep 14 13:14:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493245 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 5126FC433EF for ; Tue, 14 Sep 2021 13:14:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34D16610A6 for ; Tue, 14 Sep 2021 13:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233105AbhINNQB (ORCPT ); Tue, 14 Sep 2021 09:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhINNQB (ORCPT ); Tue, 14 Sep 2021 09:16:01 -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 13BC2C061574 for ; Tue, 14 Sep 2021 06:14:44 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso2046963wme.4 for ; Tue, 14 Sep 2021 06:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HF0qifpXfevsRUolMoVFXZYZiYZgzeqDgEr++eKz43U=; b=Yqo2lINkhceXkd7GQaU+tRc/33G30skZ83ke0b0EDE9mhnG2PUyF3QPiFDwdFb7nO6 KPxDJ20hCc3/mWJBRqTpk56m+eXEdm6ky5dNR1zXwhmQZZyHk63nD/UXMsYeW7SsVXqW 7KodUM/GX2QYp9ktatFLyy8g9jLNCL4L8WXoPgaFkcIJdUCOhN5aQY3lVw/zZWICjpsj ELPnfUdu4q8DiqAt3FguCm5uOoBUJEa/pN3qhR20iYB+rQwl0E41vGNwFcxAaRhUq+JO ei6AcZwa4tkgGjkLnuAYkgxJvgkebMfKJRmrT6SjCugcKtvYvS7zcj7f13pyQomitSaX /20g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HF0qifpXfevsRUolMoVFXZYZiYZgzeqDgEr++eKz43U=; b=uw6rINwiEZh+MNlMOjl06wl0U3Kr3vep4Z4st8u8eizYvbShdJuh9hKvF7dsVQQYFc huU4LWZTI9hTcplE0DWkwpKWkKhkn8r3qpfDlRF4TeaoO/PdEkvKv1hjAZMQaY89Cflr SZxCMg7Zkj7DH9VTj38Di3na2yDv3GSqxKRj8EUZJHClHxm7bkNXhFbybjF6NyJtGJox Nw4JtctHdABD8lwcwOAMltxOMi3tuMbpfQJrK2Do/uMLIeeBQHjX9uSgL1xExqULlBEw fhOXHxQDUpyYe+2iPXfmZlDMiiog5Q1+8tJPnv5HgxjyAUDIKAZgSMo05JThv9x3chYY DyMg== X-Gm-Message-State: AOAM531p/Bg0JAUS9YU1qVp/4AOVcxKtgztAeFHMNMRRUuiQTstOwDeP TvxkWj7Q4Y4kGydrVmtmPWFVSpAyt6U= X-Google-Smtp-Source: ABdhPJx5YQWqatvx6/cz/JFC/7JtCUSvJdc2CHIkGLm4QDivX4W9UKZ/FtUAbK96T92q45pek28/9A== X-Received: by 2002:a7b:cf21:: with SMTP id m1mr2168607wmg.95.1631625282605; Tue, 14 Sep 2021 06:14:42 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:42 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 02/25] trace-cmd library: Add cache functionality to network message handler Date: Tue, 14 Sep 2021 16:14:15 +0300 Message-Id: <20210914131438.3965484-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Network message handler is used to send trace metadata through a network socket, instead writing it into a trace file. There are use cases, that could require to do a lseek() on the metadata. It is hard to implement lseek on a network socket, that's why for such use cases a cache to a local file is introduced. Once the metadata is constructed, the local cache is send to the socket. A new library API is used to enable the local cache: tracecmd_msg_handle_cache() The local cache is flushed on the socket when the tracecmd_msg_finish_sending_data() is called. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 5 + lib/trace-cmd/include/trace-cmd-local.h | 1 + lib/trace-cmd/trace-msg.c | 127 +++++++++++++----- lib/trace-cmd/trace-output.c | 45 ++++--- 4 files changed, 127 insertions(+), 51 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index e21bc3bf..460f8a5d 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -344,12 +344,16 @@ enum tracecmd_msg_flags { }; /* for both client and server */ +#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX" struct tracecmd_msg_handle { int fd; short cpu_count; short version; /* Current protocol version */ unsigned long flags; bool done; + bool cache; + int cfd; + char cfile[sizeof(MSG_CACHE_FILE)]; }; struct tracecmd_tsync_protos { @@ -358,6 +362,7 @@ struct tracecmd_tsync_protos { struct tracecmd_msg_handle * tracecmd_msg_handle_alloc(int fd, unsigned long flags); +int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle); /* Closes the socket and frees the handle */ void tracecmd_msg_handle_close(struct tracecmd_msg_handle *msg_handle); diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index e11dce58..362b9fc0 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -43,5 +43,6 @@ struct cpu_data_source { int out_write_cpu_data(struct tracecmd_output *handle, int cpus, struct cpu_data_source *data, const char *buff_name); +off64_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off_t offset, int whence); #endif /* _TRACE_CMD_LOCAL_H */ diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index 6667028e..4910ed5c 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -154,33 +154,55 @@ static inline int msg_buf_len(struct tracecmd_msg *msg) return ntohl(msg->hdr.size) - MSG_HDR_LEN - ntohl(msg->hdr.cmd_size); } -static int msg_write(int fd, struct tracecmd_msg *msg) +static int __msg_write(int fd, struct tracecmd_msg *msg, bool network) { - int cmd = ntohl(msg->hdr.cmd); int msg_size, data_size; int ret; - - if (cmd < 0 || cmd >= MSG_NR_COMMANDS) - return -EINVAL; - - dprint("msg send: %d (%s) [%d]\n", - cmd, cmd_to_name(cmd), ntohl(msg->hdr.size)); - + int cmd; + + if (network) { + cmd = ntohl(msg->hdr.cmd); + if (cmd < 0 || cmd >= MSG_NR_COMMANDS) + return -EINVAL; + dprint("msg send: %d (%s) [%d]\n", + cmd, cmd_to_name(cmd), ntohl(msg->hdr.size)); + } msg_size = MSG_HDR_LEN + ntohl(msg->hdr.cmd_size); data_size = ntohl(msg->hdr.size) - msg_size; if (data_size < 0) return -EINVAL; - ret = __do_write_check(fd, msg, msg_size); - if (ret < 0) - return ret; - + if (network) { + ret = __do_write_check(fd, msg, msg_size); + if (ret < 0) + return ret; + } if (!data_size) return 0; return __do_write_check(fd, msg->buf, data_size); } +__hidden off64_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off64_t offset, int whence) +{ + /* + * lseek works only if the handle is in cache mode, + * cannot seek on a network socket + */ + if (!msg_handle->cache || msg_handle->cfd < 0) + return (off64_t)-1; + return lseek64(msg_handle->cfd, offset, whence); +} + +static int msg_write(struct tracecmd_msg_handle *msg_handle, struct tracecmd_msg *msg) +{ + if (msg_handle->cache && msg_handle->cfd >= 0) + return __msg_write(msg_handle->cfd, msg, false); + + + return __msg_write(msg_handle->fd, msg, true); +} + enum msg_trace_flags { MSG_TRACE_USE_FIFOS = 1 << 0, }; @@ -274,11 +296,11 @@ static void msg_free(struct tracecmd_msg *msg) memset(msg, 0, sizeof(*msg)); } -static int tracecmd_msg_send(int fd, struct tracecmd_msg *msg) +static int tracecmd_msg_send(struct tracecmd_msg_handle *msg_handle, struct tracecmd_msg *msg) { int ret = 0; - ret = msg_write(fd, msg); + ret = msg_write(msg_handle, msg); if (ret < 0) ret = -ECOMM; @@ -287,11 +309,11 @@ static int tracecmd_msg_send(int fd, struct tracecmd_msg *msg) return ret; } -static int msg_send_nofree(int fd, struct tracecmd_msg *msg) +static int msg_send_nofree(struct tracecmd_msg_handle *msg_handle, struct tracecmd_msg *msg) { int ret = 0; - ret = msg_write(fd, msg); + ret = msg_write(msg_handle, msg); if (ret < 0) ret = -ECOMM; @@ -454,7 +476,7 @@ static int tracecmd_msg_send_notsupp(struct tracecmd_msg_handle *msg_handle) struct tracecmd_msg msg; tracecmd_msg_init(MSG_NOT_SUPP, &msg); - return tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle, &msg); } static int handle_unexpected_msg(struct tracecmd_msg_handle *msg_handle, @@ -472,7 +494,6 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, unsigned int **client_ports) { struct tracecmd_msg msg; - int fd = msg_handle->fd; unsigned int *ports; int i, cpus, ret; char *p, *buf_end; @@ -485,13 +506,13 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle, if (ret < 0) goto out; - ret = tracecmd_msg_send(fd, &msg); + ret = tracecmd_msg_send(msg_handle, &msg); if (ret < 0) goto out; msg_free(&msg); - ret = tracecmd_msg_wait_for_msg(fd, &msg); + ret = tracecmd_msg_wait_for_msg(msg_handle->fd, &msg); if (ret < 0) goto out; @@ -564,12 +585,53 @@ tracecmd_msg_handle_alloc(int fd, unsigned long flags) handle->fd = fd; handle->flags = flags; + handle->cfd = -1; + handle->cache = false; return handle; } +int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle) +{ + if (msg_handle->cfd < 0) { + strcpy(msg_handle->cfile, MSG_CACHE_FILE); + msg_handle->cfd = mkstemp(msg_handle->cfile); + if (msg_handle->cfd < 0) + return -1; + unlink(msg_handle->cfile); + } + msg_handle->cache = true; + return 0; +} + +static int flush_cache(struct tracecmd_msg_handle *msg_handle) +{ + char buf[MSG_MAX_DATA_LEN]; + int ret; + + if (!msg_handle->cache || msg_handle->cfd < 0) + return 0; + msg_handle->cache = false; + if (lseek64(msg_handle->cfd, 0, SEEK_SET) == (off64_t)-1) + return -1; + do { + ret = read(msg_handle->cfd, buf, MSG_MAX_DATA_LEN); + if (ret <= 0) + break; + ret = tracecmd_msg_data_send(msg_handle, buf, ret); + if (ret < 0) + break; + } while (ret >= 0); + + close(msg_handle->cfd); + msg_handle->cfd = -1; + return ret; +} + void tracecmd_msg_handle_close(struct tracecmd_msg_handle *msg_handle) { close(msg_handle->fd); + if (msg_handle->cfd >= 0) + close(msg_handle->cfd); free(msg_handle); } @@ -666,7 +728,7 @@ int tracecmd_msg_send_port_array(struct tracecmd_msg_handle *msg_handle, if (ret < 0) return ret; - ret = tracecmd_msg_send(msg_handle->fd, &msg); + ret = tracecmd_msg_send(msg_handle, &msg); if (ret < 0) return ret; @@ -678,7 +740,7 @@ int tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle) struct tracecmd_msg msg; tracecmd_msg_init(MSG_CLOSE, &msg); - return tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle, &msg); } int tracecmd_msg_send_close_resp_msg(struct tracecmd_msg_handle *msg_handle) @@ -686,14 +748,13 @@ int tracecmd_msg_send_close_resp_msg(struct tracecmd_msg_handle *msg_handle) struct tracecmd_msg msg; tracecmd_msg_init(MSG_CLOSE_RESP, &msg); - return tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle, &msg); } int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, const char *buf, int size) { struct tracecmd_msg msg; - int fd = msg_handle->fd; int n; int ret; int count = 0; @@ -721,7 +782,7 @@ int tracecmd_msg_data_send(struct tracecmd_msg_handle *msg_handle, memcpy(msg.buf, buf + count, n); n = 0; } - ret = msg_write(fd, &msg); + ret = msg_write(msg_handle, &msg); if (ret < 0) break; } @@ -735,8 +796,9 @@ int tracecmd_msg_finish_sending_data(struct tracecmd_msg_handle *msg_handle) struct tracecmd_msg msg; int ret; + flush_cache(msg_handle); tracecmd_msg_init(MSG_FIN_DATA, &msg); - ret = tracecmd_msg_send(msg_handle->fd, &msg); + ret = tracecmd_msg_send(msg_handle, &msg); if (ret < 0) return ret; return 0; @@ -752,10 +814,7 @@ int tracecmd_msg_read_data(struct tracecmd_msg_handle *msg_handle, int ofd) while (!tracecmd_msg_done(msg_handle)) { ret = tracecmd_msg_recv_wait(msg_handle->fd, &msg); if (ret < 0) { - if (ret == -ETIMEDOUT) - tracecmd_warning("Connection timed out\n"); - else - tracecmd_warning("reading client"); + tracecmd_warning("reading client %d (%s)", ret, strerror(ret)); return ret; } @@ -959,7 +1018,7 @@ int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle, if (ret < 0) return ret; - return tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle, &msg); } static int get_trace_req_protos(char *buf, int length, @@ -1151,7 +1210,7 @@ int tracecmd_msg_send_time_sync(struct tracecmd_msg_handle *msg_handle, msg.hdr.size = htonl(ntohl(msg.hdr.size) + payload_size); msg.buf = payload; - return msg_send_nofree(msg_handle->fd, &msg); + return msg_send_nofree(msg_handle, &msg); } /** @@ -1283,7 +1342,7 @@ int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle, if (ret < 0) return ret; - return tracecmd_msg_send(msg_handle->fd, &msg); + return tracecmd_msg_send(msg_handle, &msg); } int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 3d7c0e85..f48e6766 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -95,6 +95,14 @@ do_write_check(struct tracecmd_output *handle, const void *data, tsize_t size) return __do_write_check(handle->fd, data, size); } +static inline off64_t do_lseek(struct tracecmd_output *handle, off_t offset, int whence) +{ + if (handle->msg_handle) + return msg_lseek(handle->msg_handle, offset, whence); + else + return lseek64(handle->fd, offset, whence); +} + static short convert_endian_2(struct tracecmd_output *handle, short val) { if (!handle->pevent) @@ -957,6 +965,9 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg return -1; handler->msg_handle = msg_handle; + /* Force messages to be cached in a temp file before sending through the socket */ + if (handler->msg_handle && HAS_SECTIONS(handler)) + tracecmd_msg_handle_cache(handler->msg_handle); return 0; } @@ -1276,7 +1287,7 @@ int tracecmd_write_options(struct tracecmd_output *handle) return -1; /* Save the data location in case it needs to be updated */ - options->offset = lseek64(handle->fd, 0, SEEK_CUR); + options->offset = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, options->data, options->size)) @@ -1309,9 +1320,9 @@ int tracecmd_append_options(struct tracecmd_output *handle) if (handle->file_state != TRACECMD_FILE_OPTIONS) return -1; - if (lseek64(handle->fd, 0, SEEK_END) == (off_t)-1) + if (do_lseek(handle, 0, SEEK_END) == (off_t)-1) return -1; - offset = lseek64(handle->fd, -2, SEEK_CUR); + offset = do_lseek(handle, -2, SEEK_CUR); if (offset == (off_t)-1) return -1; @@ -1329,7 +1340,7 @@ int tracecmd_append_options(struct tracecmd_output *handle) return -1; /* Save the data location in case it needs to be updated */ - options->offset = lseek64(handle->fd, 0, SEEK_CUR); + options->offset = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, options->data, options->size)) @@ -1522,10 +1533,10 @@ static int update_buffer_cpu_offset(struct tracecmd_output *handle, tracecmd_warning("Cannot find description for buffer %s\n", name); return -1; } - current = lseek64(handle->fd, 0, SEEK_CUR); + current = do_lseek(handle, 0, SEEK_CUR); /* Go to the option data, where will write the offest */ - if (lseek64(handle->fd, b_offset, SEEK_SET) == (off64_t)-1) { + if (do_lseek(handle, b_offset, SEEK_SET) == (off64_t)-1) { tracecmd_warning("could not seek to %lld\n", b_offset); return -1; } @@ -1534,7 +1545,7 @@ static int update_buffer_cpu_offset(struct tracecmd_output *handle, return -1; /* Go back to end of file */ - if (lseek64(handle->fd, current, SEEK_SET) == (off64_t)-1) { + if (do_lseek(handle, current, SEEK_SET) == (off64_t)-1) { tracecmd_warning("could not seek to %lld\n", offset); return -1; } @@ -1583,7 +1594,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, goto out_free; } - data_offs = lseek64(handle->fd, 0, SEEK_CUR); + data_offs = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, "flyrecord", 10)) goto out_free; @@ -1595,10 +1606,10 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, data_files[i].file_size = data[i].size; /* Write 0 for trace data offset and size and store offsets of these fields */ endian8 = 0; - data_files[i].doffset = lseek64(handle->fd, 0, SEEK_CUR); + data_files[i].doffset = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, &endian8, 8)) goto out_free; - data_files[i].soffset = lseek64(handle->fd, 0, SEEK_CUR); + data_files[i].soffset = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, &endian8, 8)) goto out_free; } @@ -1608,10 +1619,10 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, if (clock && save_clock(handle, clock)) goto out_free; for (i = 0; i < cpus; i++) { - data_files[i].data_offset = lseek64(handle->fd, 0, SEEK_CUR); + data_files[i].data_offset = do_lseek(handle, 0, SEEK_CUR); /* Page align offset */ data_files[i].data_offset = (data_files[i].data_offset + (handle->page_size - 1)) & ~(handle->page_size - 1); - data_files[i].data_offset = lseek64(handle->fd, data_files[i].data_offset, SEEK_SET); + data_files[i].data_offset = do_lseek(handle, data_files[i].data_offset, SEEK_SET); if (data_files[i].data_offset == (off64_t)-1) goto out_free; if (!tracecmd_get_quiet(handle)) @@ -1633,26 +1644,26 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, } /* Write the real CPU data offset in the file */ - if (lseek64(handle->fd, data_files[i].doffset, SEEK_SET) == (off64_t)-1) + if (do_lseek(handle, data_files[i].doffset, SEEK_SET) == (off64_t)-1) goto out_free; endian8 = convert_endian_8(handle, data_files[i].data_offset); if (do_write_check(handle, &endian8, 8)) goto out_free; /* Write the real CPU data size in the file */ - if (lseek64(handle->fd, data_files[i].soffset, SEEK_SET) == (off64_t)-1) + if (do_lseek(handle, data_files[i].soffset, SEEK_SET) == (off64_t)-1) goto out_free; endian8 = convert_endian_8(handle, data_files[i].write_size); if (do_write_check(handle, &endian8, 8)) goto out_free; offset = data_files[i].data_offset + data_files[i].write_size; - if (lseek64(handle->fd, offset, SEEK_SET) == (off64_t)-1) + if (do_lseek(handle, offset, SEEK_SET) == (off64_t)-1) goto out_free; if (!tracecmd_get_quiet(handle)) fprintf(stderr, " %llu bytes in size\n", (unsigned long long)data_files[i].write_size); } - if (lseek64(handle->fd, 0, SEEK_END) == (off64_t)-1) + if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) goto out_free; free(data_files); @@ -1661,7 +1672,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, return 0; out_free: - lseek64(handle->fd, 0, SEEK_END); + do_lseek(handle, 0, SEEK_END); free(data_files); return -1; } From patchwork Tue Sep 14 13:14:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493247 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 709A2C433F5 for ; Tue, 14 Sep 2021 13:14:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CD3E610D1 for ; Tue, 14 Sep 2021 13:14:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233206AbhINNQD (ORCPT ); Tue, 14 Sep 2021 09:16:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhINNQC (ORCPT ); Tue, 14 Sep 2021 09:16:02 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02E14C061574 for ; Tue, 14 Sep 2021 06:14:45 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id u16so20154279wrn.5 for ; Tue, 14 Sep 2021 06:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0+AN1JM8fGNnbIsv8GFGkV3AJpi+3mBF3263o/EanhU=; b=ECAUnDPgagsv0KSm18OH5Bf5Gpa1aBPHP5t2PRC/LiH8QmAgv9PoyIGdGvOEoaG1qD dYqdUBZ4FYioWT3IaPBh6xosn5kXcjfQghWzGSafacUmap5UClLoQj4PdWe531elVzTt jHnZ+s3H7Bg9HTNc/oQZ7K5u4dkVq9H9ZEFvrhHQtw9Aol0rKtp8bo6kfk5sMM44ZHPP fMzIz/TIbSViq5eUkk7cwcj6OFynXD5/rlg5ypeKTnwg8LtB2avO787emcIkBwuGAWoa +U4skc3dBOKw0Yq4/1Y2EpEacHe432moChonqGQk35cexa/2xS0SgYb+cI5+uNupldRW EqEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0+AN1JM8fGNnbIsv8GFGkV3AJpi+3mBF3263o/EanhU=; b=msdOf+uvasp8mPM14V+u7OAYgZT5Q/5JH62sJ9SBse/Q6TFkSYNCJmwloibRMGH8Pq zZzt59tAgHd5r0p2e0ysIYWAqRDKpWilDNJuFngXprkYghvefQ5j4/YQMbwNIfj8U1wG UzvKMIluJHKGVlZXfToOT5pR9ivJbCti1VMPb0ygETtOfECPRkOUsu9n3lewPB7PYIru hgsUk4/0NftWpZnxjR1AuRXexl7/2mjPwB+Q6BSPhZVcbHS0oo5J93X6jhC3UMsHWHxg utVoYYakH/gYKNoh0a+HQFTw14FVvXPfTmlF0bugmiV9VxSlbcKqc6QrR2tSyAObc0J/ F6vg== X-Gm-Message-State: AOAM533v9onc1LrrzKW6eovqkkDWUfSAWXXZIzugHqZ203XhzbCpNjhp 4kRxhcYJzTt5stWwjAzoQELMMPy6SDA= X-Google-Smtp-Source: ABdhPJyUu0UmDOrsvdOHc6LGPnAnOeDHvnmufRxx5+v3zffDVLNLJ8bPmI+B8v7LQO08kpFbtX/8bA== X-Received: by 2002:adf:eec3:: with SMTP id a3mr17510611wrp.276.1631625283555; Tue, 14 Sep 2021 06:14:43 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:43 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 03/25] trace-cmd library: New APIs to get and set version of output handler Date: Tue, 14 Sep 2021 16:14:16 +0300 Message-Id: <20210914131438.3965484-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org There are cases where the version of the file, associated with given output handler must be get or set. Added new APIs for such use cases: tracecmd_get_out_file_version() tracecmd_output_set_version() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-output.c | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 460f8a5d..ae930c2f 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -281,6 +281,7 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler, int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir); int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms); int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle); +int tracecmd_output_set_version(struct tracecmd_output *handler, int file_version); int tracecmd_output_write_init(struct tracecmd_output *handler); int tracecmd_output_write_headers(struct tracecmd_output *handler, struct tracecmd_event_list *list); @@ -315,6 +316,7 @@ int tracecmd_append_cpu_data(struct tracecmd_output *handle, int tracecmd_append_buffer_cpu_data(struct tracecmd_output *handle, const char *name, int cpus, char * const *cpu_data_files); struct tracecmd_output *tracecmd_get_output_handle_fd(int fd); +unsigned long tracecmd_get_out_file_version(struct tracecmd_output *handle); /* --- Reading the Fly Recorder Trace --- */ diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index f48e6766..73e05d07 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1063,6 +1063,26 @@ int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct trace return 0; } +/** + * tracecmd_output_set_version - Set file version of the output handler + * @handle: output handler to a trace file. + * @file_version: desired file version + * + * This API must be called before tracecmd_output_write_init(). + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_set_version(struct tracecmd_output *handler, int file_version) +{ + if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + if (file_version < FILE_VERSION_MIN || file_version > FILE_VERSION_MAX) + return -1; + handler->file_version = file_version; + return 0; +} + + /** * tracecmd_output_write_init - Write the initial magics in the trace file * @handle: output handler to a trace file. @@ -1877,3 +1897,12 @@ __hidden bool check_out_state(struct tracecmd_output *handle, int new_state) { return check_file_state(handle->file_version, handle->file_state, new_state); } + +/** + * tracecmd_get_out_file_version - return the trace.dat file version + * @handle: output handle for the trace.dat file + */ +unsigned long tracecmd_get_out_file_version(struct tracecmd_output *handle) +{ + return handle->file_version; +} From patchwork Tue Sep 14 13:14:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493249 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 51392C433FE for ; Tue, 14 Sep 2021 13:14:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36A97610D1 for ; Tue, 14 Sep 2021 13:14:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233199AbhINNQD (ORCPT ); Tue, 14 Sep 2021 09:16:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhINNQD (ORCPT ); Tue, 14 Sep 2021 09:16:03 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A1F3C061574 for ; Tue, 14 Sep 2021 06:14:46 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id i3so9241770wmq.3 for ; Tue, 14 Sep 2021 06:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=85pfohYGbXwR6/110iSbSA2Yv/Hfu/2WNR5u/7SKQ04=; b=mK1rJYf1PoURrcQJ3GWPFbFpzTG7KRViUGEedSA8hv5pLmoOJgZ3AHF6CpkkAPFQaY lwpU4GHA9xxUk1BmnMckBpQLhRrvLZDTQYIsdC+8H0z1vS0Q7WEDa23znfK3kPxIsq1z AiqLaeVltznFqMCs8mveuCoTqVAfUChRb+5A12Wonyim9QD4BIhjhu6TYNl5t8I81+Jc +a83YshDTk1myjD0dmlKGw22Ou4trKF1n2SLS9OEtEnNT7JMndWyIAngSap8plP6/m0b zWonFopkFZtbDVP33vHEnAWr2zIxNK0AMpNuhxCxUJQ2/Sto31nM4Ov5zrkpplaEzwOt MBPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=85pfohYGbXwR6/110iSbSA2Yv/Hfu/2WNR5u/7SKQ04=; b=MFbIPyX8eTv5c0AfdjTAX6te4hGUUwLHZ/azVeuyXNNXY7V7R/nSKwkY7aQ5219HkG +AOGrQDP+0F6hDKC8jUz1LxsJGuYLvMJhb4ruaz4I+63Q5fV9f9teZvG7bWVWbR/FKZj RjV0N8mgaz7B8JW4zb2FRehMyqNlFGSie8QHTMk1S+vrgKZAzcRM+UcmDsQgwIXUuv8x +ZVMZHzFOSj36yyA7g3hw1IZrbRxfdhCFvs14Tns9eHG2SpPqPZitQNXcPvDmDcT2lTx mmFMXfVT6Of8KUFsRKSgIHJu3cEQsEy4YgW7vmC+N7WBcGT+cX0ThaiitZReVYJa0neu eCJg== X-Gm-Message-State: AOAM532w8OpF49NvJ22NUiVo4i1ObEvWR3mw55ein1xo+z/L697kn66v iiZDuP/tcamMuWSqARnL7To/KdWMZLg= X-Google-Smtp-Source: ABdhPJwyhTbpGywy4y4IAiAfbQN/JkJxI0UImzPyaXhTW2HRA+nMbXvacAjbSEz9uLpT4ibQKK3z+w== X-Received: by 2002:a05:600c:510a:: with SMTP id o10mr2139019wms.81.1631625284742; Tue, 14 Sep 2021 06:14:44 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:44 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 04/25] trace-cmd library: Add internal helper function for writing headers before file sections Date: Tue, 14 Sep 2021 16:14:17 +0300 Message-Id: <20210914131438.3965484-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Introduce headers before each file section, in trace file version 7. The section header has the following format: <2 bytes>, header ID , null terminated ASCII string, description of the header <2 bytes>, section flags: 1: the section is compressed <4 bytes>, size of the section Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 5 ++ .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/include/trace-cmd-local.h | 5 ++ lib/trace-cmd/trace-output.c | 68 +++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 7fea4e01..5d71e8ba 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -15,6 +15,11 @@ enum tracecmd_open_flags { TRACECMD_FL_LOAD_NO_PLUGINS = 1 << 0, /* Do not load plugins */ TRACECMD_FL_LOAD_NO_SYSTEM_PLUGINS = 1 << 1, /* Do not load system plugins */ }; + +enum tracecmd_section_flags { + TRACECMD_SEC_FL_COMPRESS = 1 << 0, /* the section is compressed */ +}; + struct tracecmd_input *tracecmd_open_head(const char *file, int flags); struct tracecmd_input *tracecmd_open(const char *file, int flags); struct tracecmd_input *tracecmd_open_fd(int fd, int flags); diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index ae930c2f..6d524c99 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -138,6 +138,7 @@ enum { TRACECMD_OPTION_TIME_SHIFT, TRACECMD_OPTION_GUEST, TRACECMD_OPTION_TSC2NSEC, + TRACECMD_OPTION_MAX, }; enum { diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index 362b9fc0..405b7dae 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -35,6 +35,11 @@ struct data_file_write { bool check_file_state(unsigned long file_version, int current_state, int new_state); bool check_out_state(struct tracecmd_output *handle, int new_state); +unsigned long long +out_write_section_header(struct tracecmd_output *handle, unsigned short header_id, + char *description, enum tracecmd_section_flags flags, bool option); +int out_update_section_header(struct tracecmd_output *handle, unsigned long long offset); + struct cpu_data_source { int fd; int size; diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 73e05d07..5deabfe3 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -332,6 +332,74 @@ int tracecmd_ftrace_enable(int set) return ret; } +__hidden unsigned long long +out_write_section_header(struct tracecmd_output *handle, unsigned short header_id, + char *description, enum tracecmd_section_flags flags, bool option) +{ + tsize_t endian8; + tsize_t offset; + short endian2; + int size; + + if (header_id >= TRACECMD_OPTION_MAX) + return -1; + if (!HAS_SECTIONS(handle)) + return 0; + offset = do_lseek(handle, 0, SEEK_CUR); + if (option) { + endian8 = convert_endian_8(handle, offset); + if (!tracecmd_add_option(handle, header_id, 8, &endian8)) + return -1; + } + /* Section ID */ + endian2 = convert_endian_2(handle, header_id); + if (do_write_check(handle, &endian2, 2)) + return (off_t)-1; + + /* Section description */ + if (do_write_check(handle, description, strlen(description) + 1)) + return (off_t)-1; + /* Section flags */ + endian2 = convert_endian_2(handle, flags); + if (do_write_check(handle, &endian2, 2)) + return (off_t)-1; + + offset = do_lseek(handle, 0, SEEK_CUR); + size = 0; + /* Reserve for section size */ + if (do_write_check(handle, &size, 4)) + return (off_t)-1; + return offset; +} + +__hidden int out_update_section_header(struct tracecmd_output *handle, unsigned long long offset) +{ + unsigned long long current; + unsigned int endian4; + int size; + + if (!HAS_SECTIONS(handle) || offset == 0) + return 0; + + current = do_lseek(handle, 0, SEEK_CUR); + /* The real size is the difference between the saved offset and + * the current offset - 4 bytes, the reserved space for the section size. + */ + size = current - offset; + if (size < 4) + return -1; + size -= 4; + if (do_lseek(handle, offset, SEEK_SET) == (off_t)-1) + return -1; + + endian4 = convert_endian_4(handle, size); + if (do_write_check(handle, &endian4, 4)) + return -1; + if (do_lseek(handle, current, SEEK_SET) == (off_t)-1) + return -1; + return 0; +} + static int read_header_files(struct tracecmd_output *handle) { tsize_t size, check_size, endian8; From patchwork Tue Sep 14 13:14:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493251 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 6C252C433F5 for ; Tue, 14 Sep 2021 13:14:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 598D0610E6 for ; Tue, 14 Sep 2021 13:14:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233207AbhINNQF (ORCPT ); Tue, 14 Sep 2021 09:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhINNQE (ORCPT ); Tue, 14 Sep 2021 09:16:04 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AECDC061574 for ; Tue, 14 Sep 2021 06:14:47 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id i23so20175557wrb.2 for ; Tue, 14 Sep 2021 06:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CCfKRGKW+rgbqdZ5QqTOyFlWtfS44UW1nom0Q4a+Wd0=; b=eOQuQIustM3TJIm2rZu3G/vcr/KuuSEuEGGj4J0mlG3xgYLIQQhwItsu/d/a3p821l dNf8Y0G/APVOiW/KgObkDw5WRcyh9+3UitoWujv7kzukXBsuC2I+3r0DX6ESOSrcJTSM poOMqSnctgJNiEEYmx/Wz14hQbfGOXyPycrU6ljJudcH1xvmTdPNqHPVbCWjVGOcBRS3 J3BbllJt3TRdvxSO6lkQhcBL2ZrnrwxsbcgxblXWuALtPdNgRjbDUYtAlq/7PGdyvuJg HKpZSlJE+ocUG7rzqLNQ86w4q9q+V+RwoVpEipMCMCg+DKmc2JuFbqrVAyRcirXFIKXs iyLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CCfKRGKW+rgbqdZ5QqTOyFlWtfS44UW1nom0Q4a+Wd0=; b=QIQZI2PQjHVTDlcvZc7tuV0s4alRgLzjorZM1Wt/lhuoapiZjbJQ20oACalIhhxzWK b3i9iXeAmFCboWwvLuSAgWYu7eXNUcU7Ayry9GpCw7XgYdxzUxlPOVs466BxnTsCzy4t j8qWdyNT5+YziVHejGWwKi/clmHwontU3YZM6UBaGLKibyb3JojV+0DUMb0pwuLLkA+r EDgvX/t9oPrUEMhZKB8GFtwbMMIePHwKWmrStyVOnRJmHax7ycO+UE/vqwqIdnwgi2Hk jL57RQy7chqjqFAwVCmBzmyWPGU8fuOPWfFocLienI2P6Y6Jmn9hyrwWp2mPEA+xYZYe VhUQ== X-Gm-Message-State: AOAM5320EDBmHyHpNUpMBtc3LxyIUGbl29FxlKgT9tJzA4DnIGXVyW0I +N4WI8Aftd2AW5ofQSLW6+estnTHUd0= X-Google-Smtp-Source: ABdhPJy5QHoBjxuj9MTZwJpwamVRijplT+72+og8HM64jZj8Xpy0+R8QVt2dC/lANw+vC2yXA7epTg== X-Received: by 2002:adf:e349:: with SMTP id n9mr19369528wrj.326.1631625285722; Tue, 14 Sep 2021 06:14:45 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:45 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 05/25] trace-cmd library: Write header before file sections Date: Tue, 14 Sep 2021 16:14:18 +0300 Message-Id: <20210914131438.3965484-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Headers are added before these file sections, in trace file version 7: - ftrace events format - format of recorded events - information of the mapping of function addresses to the function names - trace_printk() format strings - information of the mapping a PID to a process name New options are defined for each of these sections, holding the section's offset into the trace file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 6 + lib/trace-cmd/trace-output.c | 110 ++++++++++++++---- 2 files changed, 93 insertions(+), 23 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 6d524c99..d85a4b3b 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -138,6 +138,12 @@ enum { TRACECMD_OPTION_TIME_SHIFT, TRACECMD_OPTION_GUEST, TRACECMD_OPTION_TSC2NSEC, + TRACECMD_OPTION_HEADER_INFO, + TRACECMD_OPTION_FTRACE_EVENTS, + TRACECMD_OPTION_EVENT_FORMATS, + TRACECMD_OPTION_KALLSYMS, + TRACECMD_OPTION_PRINTK, + TRACECMD_OPTION_CMDLINES, TRACECMD_OPTION_MAX, }; diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 5deabfe3..11f3ea77 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -402,10 +402,12 @@ __hidden int out_update_section_header(struct tracecmd_output *handle, unsigned static int read_header_files(struct tracecmd_output *handle) { + enum tracecmd_section_flags flags = 0; tsize_t size, check_size, endian8; struct stat st; + tsize_t offset; char *path; - int fd; + int fd = -1; int ret; if (!check_out_state(handle, TRACECMD_FILE_HEADERS)) { @@ -418,26 +420,33 @@ static int read_header_files(struct tracecmd_output *handle) if (!path) return -1; + offset = out_write_section_header(handle, TRACECMD_OPTION_HEADER_INFO, + "headers", flags, true); + if (offset == (off64_t)-1) + return -1; + ret = stat(path, &st); if (ret < 0) { /* old style did not show this info, just add zero */ put_tracing_file(path); if (do_write_check(handle, "header_page", 12)) - return -1; + goto out_close; size = 0; if (do_write_check(handle, &size, 8)) - return -1; + goto out_close; if (do_write_check(handle, "header_event", 13)) - return -1; + goto out_close; if (do_write_check(handle, &size, 8)) - return -1; + goto out_close; + if (out_update_section_header(handle, offset)) + goto out_close; return 0; } fd = open(path, O_RDONLY); if (fd < 0) { tracecmd_warning("can't read '%s'", path); - return -1; + goto out_close; } /* unfortunately, you can not stat debugfs files for size */ @@ -453,18 +462,18 @@ static int read_header_files(struct tracecmd_output *handle) if (size != check_size) { tracecmd_warning("wrong size for '%s' size=%lld read=%lld", path, size, check_size); errno = EINVAL; - return -1; + goto out_close; } put_tracing_file(path); path = get_tracing_file(handle, "events/header_event"); if (!path) - return -1; + goto out_close; fd = open(path, O_RDONLY); if (fd < 0) { tracecmd_warning("can't read '%s'", path); - return -1; + goto out_close; } size = get_size_fd(fd); @@ -478,16 +487,18 @@ static int read_header_files(struct tracecmd_output *handle) close(fd); if (size != check_size) { tracecmd_warning("wrong size for '%s'", path); - return -1; + goto out_close; } put_tracing_file(path); - + if (out_update_section_header(handle, offset)) + goto out_close; handle->file_state = TRACECMD_FILE_HEADERS; return 0; out_close: - close(fd); + if (fd >= 0) + close(fd); return -1; } @@ -716,8 +727,10 @@ create_event_list_item(struct tracecmd_output *handle, static int read_ftrace_files(struct tracecmd_output *handle) { + enum tracecmd_section_flags flags = 0; struct list_event_system *systems = NULL; struct tracecmd_event_list list = { .glob = "ftrace/*" }; + tsize_t offset; int ret; if (!check_out_state(handle, TRACECMD_FILE_FTRACE_EVENTS)) { @@ -726,11 +739,20 @@ static int read_ftrace_files(struct tracecmd_output *handle) return -1; } + offset = out_write_section_header(handle, TRACECMD_OPTION_FTRACE_EVENTS, + "ftrace events", flags, true); + if (offset == (off64_t)-1) + return -1; + create_event_list_item(handle, &systems, &list); ret = copy_event_system(handle, systems); free_list_events(systems); + if (ret) + return ret; + if (out_update_section_header(handle, offset)) + return -1; handle->file_state = TRACECMD_FILE_FTRACE_EVENTS; @@ -753,11 +775,13 @@ create_event_list(struct tracecmd_output *handle, static int read_event_files(struct tracecmd_output *handle, struct tracecmd_event_list *event_list) { + enum tracecmd_section_flags flags = 0; struct list_event_system *systems; struct list_event_system *slist; struct tracecmd_event_list *list; struct tracecmd_event_list all_events = { .glob = "*/*" }; int count = 0; + tsize_t offset; int endian4; int ret; @@ -766,6 +790,11 @@ static int read_event_files(struct tracecmd_output *handle, handle->file_state); return -1; } + + offset = out_write_section_header(handle, TRACECMD_OPTION_EVENT_FORMATS, + "events format", flags, true); + if (offset == (off64_t)-1) + return -1; /* * If any of the list is the special keyword "all" then * just do all files. @@ -797,9 +826,14 @@ static int read_event_files(struct tracecmd_output *handle, } ret = copy_event_system(handle, slist); } + if (ret) + goto out_free; + ret = out_update_section_header(handle, offset); - handle->file_state = TRACECMD_FILE_ALL_EVENTS; out_free: + if (!ret) + handle->file_state = TRACECMD_FILE_ALL_EVENTS; + free_list_events(systems); return ret; @@ -847,8 +881,10 @@ err: static int read_proc_kallsyms(struct tracecmd_output *handle) { + enum tracecmd_section_flags flags = 0; unsigned int size, check_size, endian4; const char *path = "/proc/kallsyms"; + tsize_t offset; struct stat st; int ret; @@ -861,19 +897,24 @@ static int read_proc_kallsyms(struct tracecmd_output *handle) if (handle->kallsyms) path = handle->kallsyms; + offset = out_write_section_header(handle, TRACECMD_OPTION_KALLSYMS, + "kallsyms", flags, true); + if (offset == (off64_t)-1) + return -1; + ret = stat(path, &st); if (ret < 0) { /* not found */ size = 0; endian4 = convert_endian_4(handle, size); - if (do_write_check(handle, &endian4, 4)) - return -1; - return 0; + ret = do_write_check(handle, &endian4, 4); + goto out; } size = get_size(path); endian4 = convert_endian_4(handle, size); - if (do_write_check(handle, &endian4, 4)) - return -1; + ret = do_write_check(handle, &endian4, 4); + if (ret) + goto out; set_proc_kptr_restrict(0); check_size = copy_file(handle, path); @@ -881,18 +922,23 @@ static int read_proc_kallsyms(struct tracecmd_output *handle) errno = EINVAL; tracecmd_warning("error in size of file '%s'", path); set_proc_kptr_restrict(1); - return -1; + ret = -1; + goto out; } set_proc_kptr_restrict(1); - handle->file_state = TRACECMD_FILE_KALLSYMS; - - return 0; + ret = out_update_section_header(handle, offset); +out: + if (!ret) + handle->file_state = TRACECMD_FILE_KALLSYMS; + return ret; } static int read_ftrace_printk(struct tracecmd_output *handle) { + enum tracecmd_section_flags flags = 0; unsigned int size, check_size, endian4; + tsize_t offset; struct stat st; char *path; int ret; @@ -907,6 +953,10 @@ static int read_ftrace_printk(struct tracecmd_output *handle) if (!path) return -1; + offset = out_write_section_header(handle, TRACECMD_OPTION_PRINTK, "printk", flags, true); + if (offset == (off64_t)-1) + return -1; + ret = stat(path, &st); if (ret < 0) { /* not found */ @@ -928,8 +978,10 @@ static int read_ftrace_printk(struct tracecmd_output *handle) } out: - handle->file_state = TRACECMD_FILE_PRINTK; put_tracing_file(path); + if (out_update_section_header(handle, offset)) + return -1; + handle->file_state = TRACECMD_FILE_PRINTK; return 0; fail: put_tracing_file(path); @@ -1520,6 +1572,8 @@ static tsize_t get_buffer_file_offset(struct tracecmd_output *handle, const char int tracecmd_write_cmdlines(struct tracecmd_output *handle) { + enum tracecmd_section_flags flags = 0; + tsize_t offset; int ret; if (!check_out_state(handle, TRACECMD_FILE_CMD_LINES)) { @@ -1527,9 +1581,19 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle) handle->file_state); return -1; } + + offset = out_write_section_header(handle, TRACECMD_OPTION_CMDLINES, + "command lines", flags, true); + if (offset == (off64_t)-1) + return -1; + ret = save_tracing_file_data(handle, "saved_cmdlines"); if (ret < 0) return ret; + + if (out_update_section_header(handle, offset)) + return -1; + handle->file_state = TRACECMD_FILE_CMD_LINES; return 0; } From patchwork Tue Sep 14 13:14:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493253 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 E30BCC433FE for ; Tue, 14 Sep 2021 13:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBAF26113B for ; Tue, 14 Sep 2021 13:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbhINNQG (ORCPT ); Tue, 14 Sep 2021 09:16:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233216AbhINNQF (ORCPT ); Tue, 14 Sep 2021 09:16:05 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2592AC061574 for ; Tue, 14 Sep 2021 06:14:48 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id q26so20140523wrc.7 for ; Tue, 14 Sep 2021 06:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F6r2f6FJPEIMUbqyBzYjfCL0Ootu2RznxRVtIj5OCyg=; b=eQGjpXmcZURl6SYGDZsPPrHscBf+3Xi0zpkmqPQw6udWOkV9uCttPOywTJqYHu1BAU OF1Pje2MtrIXHNROGYgrWXMTVkhO9HmUQwzLVE1rPAIHM3UDFVwTbmNOuWE9nj841gQ7 JMz0Ff7A30BEweGJUgXFLLQ+6FH6q02fXG/b6MIuJQ2fkLQYTd8NHqUN1JoTA6sb8N4Z BkFX4FisDL5l438QEPn1pNtkjLZ/Dzvg6ZsbeRg77yO9prFH/Bt4+CuiPLIZyciVTtEd 80lWuW2dM5KEeC7Ko7hMjs/hBlwY11c5YUclXk1/rhZYr0EmDt40dkQ3Ty6m2hv8ZBta ZL4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F6r2f6FJPEIMUbqyBzYjfCL0Ootu2RznxRVtIj5OCyg=; b=tNEMyJUtZMblgmByC15+oBZs6uUSIR35Ji8w/2FjUBHx+se/5H95PortMTfZklboC3 /YrnsrL7BOEU9m9O2Nbse+dKXFCYOcce4s3E00GGBKGsr4MFuLp5e/5QxR5pC7T97SFf /G1yQzzz73WJiGVV6pXWBsgxcUEBcJmxo0Rv5dSQ46ht9jkbmLmP6v3ajVfU1e25qW+Q H/lgE9cUsGyN26FiIDqS972xC+qsAQjTW9L1C6CMY4TfHYBzaNuCO2D9CI+sTJ+gzUrl u5iNkmTEfNHVbIc1OxcgIyHpc1upEYzb4mfpwkMuIPeffDckgL+T6RmS0Z2L4mWH2w6Y L6Ew== X-Gm-Message-State: AOAM533+8LjWeuXBETjtSZZvJIpDR6qLpcbh0PVWPd1+2oduja7EB0Wd AXpUv5R64NjsXfZEE45K+3A5Pru5hQU= X-Google-Smtp-Source: ABdhPJzSTn6uHIaq1+9kTOMV6Sce1j7iteNVS8lUJOSB7VTuN4spQu1oMsNOrG6TPXNw8zvwYfOj3g== X-Received: by 2002:a5d:5408:: with SMTP id g8mr18994350wrv.34.1631625286714; Tue, 14 Sep 2021 06:14:46 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:46 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 06/25] trace-cmd library: Add multiple options sections in trace file version 7 Date: Tue, 14 Sep 2021 16:14:19 +0300 Message-Id: <20210914131438.3965484-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Introduced chain of options sections in trace file version 7. Extended the "DONE" option to hold the offset into the file to the next options section. Format of trace file version 7 is extended with a new mandatory field after the compression algorithm header: <8 bytes>, unsigned long long integer - offset into the trace file where the first options section is located. This allows to place this section anywhere in the file. As all other sections have corresponding options, describing their offsets into the trace file, this change makes the structure of trace file version 7 flexible. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 101 ++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 7 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 11f3ea77..28bfed32 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -63,7 +63,7 @@ struct tracecmd_output { bool quiet; unsigned long file_state; unsigned long file_version; - size_t options_start; + tsize_t options_start; bool big_endian; struct list_head options; @@ -1220,6 +1220,7 @@ int tracecmd_output_set_version(struct tracecmd_output *handler, int file_versio */ int tracecmd_output_write_init(struct tracecmd_output *handler) { + unsigned long long offset; char buf[BUFSIZ]; int endian4; @@ -1253,6 +1254,14 @@ int tracecmd_output_write_init(struct tracecmd_output *handler) endian4 = convert_endian_4(handler, handler->page_size); if (do_write_check(handler, &endian4, 4)) return -1; + if (HAS_SECTIONS(handler)) { + /* Write 0 as options offset and save its location */ + offset = 0; + handler->options_start = do_lseek(handler, 0, SEEK_CUR); + if (do_write_check(handler, &offset, 8)) + return -1; + } + handler->file_state = TRACECMD_FILE_INIT; return 0; } @@ -1321,7 +1330,7 @@ tracecmd_add_option_v(struct tracecmd_output *handle, * We can only add options before tracing data were written. * This may change in the future. */ - if (handle->file_state > TRACECMD_FILE_OPTIONS) + if (!HAS_SECTIONS(handle) && handle->file_state > TRACECMD_FILE_OPTIONS) return NULL; for (i = 0; i < count; i++) @@ -1334,8 +1343,7 @@ tracecmd_add_option_v(struct tracecmd_output *handle, return NULL; } } - - option = malloc(sizeof(*option)); + option = calloc(1, sizeof(*option)); if (!option) { tracecmd_warning("Could not allocate space for option"); free(data); @@ -1398,7 +1406,7 @@ int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus) return 0; } -int tracecmd_write_options(struct tracecmd_output *handle) +static int write_options_v6(struct tracecmd_output *handle) { struct tracecmd_option *options; unsigned short option; @@ -1416,7 +1424,7 @@ int tracecmd_write_options(struct tracecmd_output *handle) if (do_write_check(handle, "options ", 10)) return -1; - + handle->options_start = do_lseek(handle, 0, SEEK_CUR); list_for_each_entry(options, &handle->options, list) { endian2 = convert_endian_2(handle, options->id); if (do_write_check(handle, &endian2, 2)) @@ -1440,11 +1448,83 @@ int tracecmd_write_options(struct tracecmd_output *handle) return -1; handle->file_state = TRACECMD_FILE_OPTIONS; + return 0; +} + +static int write_options_v7(struct tracecmd_output *handle) +{ + struct tracecmd_option *options; + unsigned long long endian8; + unsigned short endian2; + unsigned int endian4; + bool new = false; + tsize_t offset; + + /* Check if there are unsaved options */ + list_for_each_entry(options, &handle->options, list) { + if (!options->offset) { + new = true; + break; + } + } + + if (!new) + return 0; + offset = do_lseek(handle, 0, SEEK_CUR); + /* Append to the previous options section, if any */ + if (handle->options_start) { + if (do_lseek(handle, handle->options_start, SEEK_SET) == (off64_t)-1) + return -1; + endian8 = convert_endian_8(handle, offset); + if (do_write_check(handle, &endian8, 8)) + return -1; + if (do_lseek(handle, offset, SEEK_SET) == (off_t)-1) + return -1; + } + offset = out_write_section_header(handle, TRACECMD_OPTION_DONE, "options", 0, false); + if (offset == (off_t)-1) + return -1; + list_for_each_entry(options, &handle->options, list) { + /* Option is already saved, skip it */ + if (options->offset) + continue; + endian2 = convert_endian_2(handle, options->id); + if (do_write_check(handle, &endian2, 2)) + return -1; + endian4 = convert_endian_4(handle, options->size); + if (do_write_check(handle, &endian4, 4)) + return -1; + /* Save the data location */ + options->offset = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, options->data, options->size)) + return -1; + } + + endian2 = convert_endian_2(handle, TRACECMD_OPTION_DONE); + if (do_write_check(handle, &endian2, 2)) + return -1; + endian4 = convert_endian_4(handle, 8); + if (do_write_check(handle, &endian4, 4)) + return -1; + endian8 = 0; + handle->options_start = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, &endian8, 8)) + return -1; + if (out_update_section_header(handle, offset)) + return -1; return 0; } -int tracecmd_append_options(struct tracecmd_output *handle) +int tracecmd_write_options(struct tracecmd_output *handle) +{ + if (!HAS_SECTIONS(handle)) + return write_options_v6(handle); + return write_options_v7(handle); +} + + +static int append_options_v6(struct tracecmd_output *handle) { struct tracecmd_option *options; unsigned short option; @@ -1495,6 +1575,13 @@ int tracecmd_append_options(struct tracecmd_output *handle) return 0; } +int tracecmd_append_options(struct tracecmd_output *handle) +{ + if (!HAS_SECTIONS(handle)) + return append_options_v6(handle); + return write_options_v7(handle); +} + static struct tracecmd_option * add_buffer_option(struct tracecmd_output *handle, const char *name, int cpus) { From patchwork Tue Sep 14 13:14:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493255 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 E417FC433F5 for ; Tue, 14 Sep 2021 13:14:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD38661130 for ; Tue, 14 Sep 2021 13:14:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233227AbhINNQH (ORCPT ); Tue, 14 Sep 2021 09:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233214AbhINNQG (ORCPT ); Tue, 14 Sep 2021 09:16:06 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF7AC061574 for ; Tue, 14 Sep 2021 06:14:49 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id x6so20128849wrv.13 for ; Tue, 14 Sep 2021 06:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=08pjarJ57TCo8MnXdaaZPrIHEI8NWlUNiEyQPylWnr4=; b=qNmH9Wenxu4quCs6S6xqi4sZf3vhs/G9GiAf4fEIeC+m/d/oN+C0OckB9olrNWMgMe yaPDzTzTeg6DbBcBXUikN0S4WVCjsuoxyG3yrQKKkCd/6mceA4wWNXcoEse9GIrNVvg4 x6xIkJfeFYq75VCjbvCcQth23U/dwcVkJuzegZb3/mbFIbteKKFBZhfCwA1GRJeHnqta ulBDI/jxpi57Z+OhYYkB0hkqmHPN9yAVQGrMOm/b58YLZUXzYIv6vK6fGbhd3PVRMwB7 iP9al4/7Cs50eCTIZ405/djbJWD1h1ZaLxISuat29vTuTwsG/bdwv9klfm7YIlcaofgK X4Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=08pjarJ57TCo8MnXdaaZPrIHEI8NWlUNiEyQPylWnr4=; b=uJBArEU+pXYgXkNG8Gbf00iaiu7WPxafeWV99SfNPY+5iI1BWOIAwtWQf2ge3anRsi 0XHeBPuaI25HRcDdTmV+LYDYtKVrybT7ta/LvWvwiz7o+eD3s2JZC6r9nFtwhhfeMJ6R KRTY0yIf9pxT6/kOMzTzmYoJof9r5Sbv/5R3MMdPe/ZZ3/mdhZqLWj3iQHp+YAsnRuSb ZBlto/2Fedp327YHYrQ5qC5XAIdFXpP6RVRM4NMA4sPP9dTd1g2vRlFTs9Z46mp/o3/x K7bfMCgkfGe9Bco6CXK3eng+AE8uZqVcr1kqOPIIjXCo5I1/YbzZq0J7mMkcffkd8bs2 EMGA== X-Gm-Message-State: AOAM53038DJl3mNpr1wixPgsd/UZUfJboEK6axaBiX0C96oZmisSjtJn rObU1FdEg9vvZVbb7K3wG7k= X-Google-Smtp-Source: ABdhPJyX6q+2p+uimx+RVb+ng2JRY3MdMU1oLHZLEs+s5I8pSYzO3SZmtwE1a7HKwyNdNnaD3ejwkw== X-Received: by 2002:adf:b348:: with SMTP id k8mr18776969wrd.123.1631625287803; Tue, 14 Sep 2021 06:14:47 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:47 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 07/25] trace-cmd library: Do not write CPU count section in trace files version 7 Date: Tue, 14 Sep 2021 16:14:20 +0300 Message-Id: <20210914131438.3965484-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Writing CPU count as a separate section in the trace file is redundant, as there is already an option for that. Use that option in trace files version 7. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 28bfed32..8bc995c7 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1398,10 +1398,16 @@ int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus) handle->file_state); return -1; } - cpus = convert_endian_4(handle, cpus); - ret = do_write_check(handle, &cpus, 4); - if (ret < 0) - return ret; + + if (!HAS_SECTIONS(handle)) { + cpus = convert_endian_4(handle, cpus); + ret = do_write_check(handle, &cpus, 4); + if (ret < 0) + return ret; + } else { + tracecmd_add_option(handle, TRACECMD_OPTION_CPUCOUNT, sizeof(int), &cpus); + } + handle->file_state = TRACECMD_FILE_CPU_COUNT; return 0; } From patchwork Tue Sep 14 13:14:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493257 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 C53BEC4332F for ; Tue, 14 Sep 2021 13:14:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B173D610D1 for ; Tue, 14 Sep 2021 13:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233218AbhINNQI (ORCPT ); Tue, 14 Sep 2021 09:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQH (ORCPT ); Tue, 14 Sep 2021 09:16:07 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4950BC061574 for ; Tue, 14 Sep 2021 06:14:50 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 192-20020a1c04c9000000b002f7a4ab0a49so1978441wme.0 for ; Tue, 14 Sep 2021 06:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uYbzqfK8SdLpGcCUm8lVEKofe44vQ9EzJmzia4J/yVs=; b=BX8UjLZpDbobENtr3ULCLQ/zBt1yfD8xCa7xD4v6xwCJSltbRRj5GseHCqfszpvmVL SyHedSadKsydlvXbXZ4ep8rMS3xB0AloA42GB4EJk2sCREWRnfFXNFghUd2RJZQcvxaI t3TvHFUXLOnYBB1o2ckyeaMS9UL1psZnaMp0FnqQ9Q2Gyg6uswhTDn+p+h37NOeVya23 6G//YdR8znzvm/ZdxX+lpE2xVCc5CJvY/F4js9RfY6aTjKhO9ZqwLrP1zzWeb9x8vifs 55CBikiNiMrVAe9MZ6fEqS0+FVts4XL+1GF1aiWPiDC/FQc/d5oz3/IjhGurw2hPMt7y DNeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uYbzqfK8SdLpGcCUm8lVEKofe44vQ9EzJmzia4J/yVs=; b=mHm4CDanabfxuDym0uajkzHxuZZ4KnE4oNlYNIxQKhQtjo3hybB79ozsMCUsT01eJr 3CFpFW5gMpj3ZEYCXStoUM+nu2UIh4lk9QEIiArZr/3N8H9cPrHHgv/9ZP0bJLczUOza xjPEmX9yGQUGR60wC8r6wUdYs2AshrG1+Kv32xlr5jkn7w7LRbQEi0mZpY19IZqko/gU oy9Usg9vJXaBvOPtd66qozfIUjhTQQ7lwQ7xEnUvy88XIXh27ErQYjJQU86T/gvRJVvc KG1sZGC6bM/qkoNyj9qB+urcYMwN5yywBrgewvCskl/4j4SGSPV92Trm6OfQdmk0Vufa 5qWA== X-Gm-Message-State: AOAM5320UhR/GWtT4MAHpmncSeCNQGcIw4jP5tOV/Y2uPvvbyr6HI9cE kM/SE6WRB5Eo3onhOIDwwhDgdTkqz3c= X-Google-Smtp-Source: ABdhPJxNnP20g/ySdq8CUx8VKSD7unM3p+3uaPTMsyajMQ7XgS/+9bjNy4tUuUbxGn47r6Qs7vaorQ== X-Received: by 2002:a1c:1fd3:: with SMTP id f202mr2161490wmf.44.1631625288905; Tue, 14 Sep 2021 06:14:48 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:48 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 08/25] trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file version 7 Date: Tue, 14 Sep 2021 16:14:21 +0300 Message-Id: <20210914131438.3965484-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Extended the BUFFER trace option in trace file version 7 with CPU flyrecord trace metadata. In the version 6 of the trace file, this metadata is located at several places in the file. Part of the metadata is only for the top trace instance, thus limiting per-instance configuration. Moving all CPU trace related metadata in the BUFFER option simplifies the parsing and makes per-instance configuration more flexible. In the new file structure, the top instance is treated as any other instances. The format of the extended BUFFER option is: - offset of the buffer in the trace file - name of the buffer - trace clock, used in this buffer for events timestamps - count of CPUs with trace data - array, describing each CPU with trace data: - CPU id - offset of CPU trace data in the trace file - size of the recorded CPU trace data Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 187 +++++++++++++++++++++++++---------- 1 file changed, 137 insertions(+), 50 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 8bc995c7..e2d03f1c 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1589,7 +1589,7 @@ int tracecmd_append_options(struct tracecmd_output *handle) } static struct tracecmd_option * -add_buffer_option(struct tracecmd_output *handle, const char *name, int cpus) +add_buffer_option_v6(struct tracecmd_output *handle, const char *name, int cpus) { struct tracecmd_option *option; char *buf; @@ -1639,8 +1639,11 @@ int tracecmd_write_buffer_info(struct tracecmd_output *handle) struct tracecmd_option *option; struct tracecmd_buffer *buf; + if (HAS_SECTIONS(handle)) + return 0; + list_for_each_entry(buf, &handle->buffers, list) { - option = add_buffer_option(handle, buf->name, buf->cpus); + option = add_buffer_option_v6(handle, buf->name, buf->cpus); if (!option) return -1; buf->option = option; @@ -1691,6 +1694,98 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle) return 0; } +static char *get_clock(struct tracecmd_output *handle) +{ + struct tracefs_instance *inst; + + if (handle->trace_clock) + return handle->trace_clock; + + /* + * If no clock is set on this handle, get the trace clock of + * the top instance in the handle's tracing dir + */ + inst = tracefs_instance_alloc(handle->tracing_dir, NULL); + if (!inst) + return NULL; + handle->trace_clock = tracefs_get_clock(inst); + tracefs_instance_free(inst); + return handle->trace_clock; +} + +__hidden struct tracecmd_option * +out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name, + unsigned short id, unsigned long long data_offset, + int cpus, struct data_file_write *cpu_data) +{ + struct tracecmd_option *option; + int i, j = 0, k = 0; + int *cpu_ids = NULL; + struct iovec *vect; + char *clock; + + if (!HAS_SECTIONS(handle)) + return NULL; + + clock = get_clock(handle); + + /* Buffer flyrecord option, v7: + * - trace data offset in the file + * - buffer name + * - buffer clock + * - CPU count + * - for each CPU: + * - CPU id + * - CPU trace data offset in the file + * - CPU trace data size + */ + + /* Buffer latency option, v7: + * - trace data offset in the file + * - buffer name + * - buffer clock + */ + + vect = calloc(5 + (cpus * 3), sizeof(struct iovec)); + if (!vect) + return NULL; + if (cpus) { + cpu_ids = calloc(cpus, sizeof(int)); + if (!cpu_ids) { + free(vect); + return NULL; + } + } + vect[j].iov_base = (void *) &data_offset; + vect[j++].iov_len = 8; + vect[j].iov_base = (void *) name; + vect[j++].iov_len = strlen(name) + 1; + vect[j].iov_base = (void *) clock; + vect[j++].iov_len = strlen(clock) + 1; + if (id == TRACECMD_OPTION_BUFFER) { + vect[j].iov_base = (void *) &k; + vect[j++].iov_len = 4; + for (i = 0; i < cpus; i++) { + if (!cpu_data[i].file_size) + continue; + cpu_ids[i] = i; + vect[j].iov_base = &cpu_ids[i]; + vect[j++].iov_len = 4; + vect[j].iov_base = &cpu_data[i].data_offset; + vect[j++].iov_len = 8; + vect[j].iov_base = &cpu_data[i].write_size; + vect[j++].iov_len = 8; + k++; + } + } + + option = tracecmd_add_option_v(handle, id, vect, j); + free(vect); + free(cpu_ids); + + return option; +} + struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) { struct tracecmd_output *handle; @@ -1767,8 +1862,8 @@ out: return ret; } -static int update_buffer_cpu_offset(struct tracecmd_output *handle, - const char *name, tsize_t offset) +static int update_buffer_cpu_offset_v6(struct tracecmd_output *handle, + const char *name, tsize_t offset) { tsize_t b_offset; tsize_t current; @@ -1797,26 +1892,6 @@ static int update_buffer_cpu_offset(struct tracecmd_output *handle, return 0; } - -static char *get_clock(struct tracecmd_output *handle) -{ - struct tracefs_instance *inst; - - if (handle->trace_clock) - return handle->trace_clock; - - /* - * If no clock is set on this handle, get the trace clock of - * the top instance in the handle's tracing dir - */ - inst = tracefs_instance_alloc(handle->tracing_dir, NULL); - if (!inst) - return NULL; - handle->trace_clock = tracefs_get_clock(inst); - tracefs_instance_free(inst); - return handle->trace_clock; -} - __hidden int out_write_cpu_data(struct tracecmd_output *handle, int cpus, struct cpu_data_source *data, const char *buff_name) { @@ -1840,7 +1915,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, } data_offs = do_lseek(handle, 0, SEEK_CUR); - if (do_write_check(handle, "flyrecord", 10)) + if (!HAS_SECTIONS(handle) && do_write_check(handle, "flyrecord", 10)) goto out_free; data_files = calloc(cpus, sizeof(struct data_file_write)); @@ -1850,19 +1925,24 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, for (i = 0; i < cpus; i++) { data_files[i].file_size = data[i].size; /* Write 0 for trace data offset and size and store offsets of these fields */ - endian8 = 0; - data_files[i].doffset = do_lseek(handle, 0, SEEK_CUR); - if (do_write_check(handle, &endian8, 8)) - goto out_free; - data_files[i].soffset = do_lseek(handle, 0, SEEK_CUR); - if (do_write_check(handle, &endian8, 8)) + if (!HAS_SECTIONS(handle)) { + endian8 = 0; + data_files[i].doffset = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, &endian8, 8)) + goto out_free; + data_files[i].soffset = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, &endian8, 8)) + goto out_free; + } + } + + if (!HAS_SECTIONS(handle)) { + update_buffer_cpu_offset_v6(handle, buff_name, data_offs); + clock = get_clock(handle); + if (clock && save_clock(handle, clock)) goto out_free; } - update_buffer_cpu_offset(handle, buff_name, data_offs); - clock = get_clock(handle); - if (clock && save_clock(handle, clock)) - goto out_free; for (i = 0; i < cpus; i++) { data_files[i].data_offset = do_lseek(handle, 0, SEEK_CUR); /* Page align offset */ @@ -1888,26 +1968,33 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, data_files[i].write_size = 0; } - /* Write the real CPU data offset in the file */ - if (do_lseek(handle, data_files[i].doffset, SEEK_SET) == (off64_t)-1) - goto out_free; - endian8 = convert_endian_8(handle, data_files[i].data_offset); - if (do_write_check(handle, &endian8, 8)) - goto out_free; - /* Write the real CPU data size in the file */ - if (do_lseek(handle, data_files[i].soffset, SEEK_SET) == (off64_t)-1) - goto out_free; - endian8 = convert_endian_8(handle, data_files[i].write_size); - if (do_write_check(handle, &endian8, 8)) - goto out_free; - offset = data_files[i].data_offset + data_files[i].write_size; - if (do_lseek(handle, offset, SEEK_SET) == (off64_t)-1) - goto out_free; + if (!HAS_SECTIONS(handle)) { + /* Write the real CPU data offset in the file */ + if (do_lseek(handle, data_files[i].doffset, SEEK_SET) == (off64_t)-1) + goto out_free; + endian8 = convert_endian_8(handle, data_files[i].data_offset); + if (do_write_check(handle, &endian8, 8)) + goto out_free; + /* Write the real CPU data size in the file */ + if (do_lseek(handle, data_files[i].soffset, SEEK_SET) == (off64_t)-1) + goto out_free; + endian8 = convert_endian_8(handle, data_files[i].write_size); + if (do_write_check(handle, &endian8, 8)) + goto out_free; + offset = data_files[i].data_offset + data_files[i].write_size; + if (do_lseek(handle, offset, SEEK_SET) == (off64_t)-1) + goto out_free; + } if (!tracecmd_get_quiet(handle)) fprintf(stderr, " %llu bytes in size\n", (unsigned long long)data_files[i].write_size); } + if (HAS_SECTIONS(handle) && + !out_add_buffer_option_v7(handle, buff_name, + TRACECMD_OPTION_BUFFER, data_offs, cpus, data_files)) + goto out_free; + if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) goto out_free; From patchwork Tue Sep 14 13:14:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493259 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 B0733C433F5 for ; Tue, 14 Sep 2021 13:14:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B2B1610F9 for ; Tue, 14 Sep 2021 13:14:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233237AbhINNQJ (ORCPT ); Tue, 14 Sep 2021 09:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQI (ORCPT ); Tue, 14 Sep 2021 09:16:08 -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 3B8AFC061574 for ; Tue, 14 Sep 2021 06:14:51 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 192-20020a1c04c9000000b002f7a4ab0a49so1978482wme.0 for ; Tue, 14 Sep 2021 06:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DyXosnBNVez1kJvwW8Z59R0UfU/8CDxTC6gV2dbJ+wA=; b=dAUyF/0DwZ6XmTQ7LyjatNtaaxiN9EoR1OvAIl4IbKX49iflLcCA31vm/VrRd8+hFD UWvF5FYjVvdicb5W/FzFmGUdsgsohG9SBA14PJoJ9uguLgM0EQq3Gj5fXIKJOe74kuy6 SH1AeXy82hAp8jn4oReIHCEeM/P/dLBLZ7N08R3RoXoFriIvhi6o0AEwndhA0QJoDF9Z c5Y1SnBHg/pfWwGhwsK6AuKbbLhRhQtTq85bybDRGMqK5iGz1RizqpVFsQjQlD1FN2oD 2brpZouNwOVGDmpjKoWgTJm47xJLtgQyNHFS0ICHfCDIk4CmPUnhDar9luo4gjicVmKL M1xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DyXosnBNVez1kJvwW8Z59R0UfU/8CDxTC6gV2dbJ+wA=; b=T1BqnQdxM23IRq2o5ELtBkPRjp2yuvXlkPdhRHYB4mwRL6Cf40nM1ggumX27tqagt0 GhpJfiJfoesrkEYoQYWCGKmU+StMF9zqL+AloJNbBO8PXOzWLfjgaiis0nl8bAcRO1of nE7XGNk7U4/eB2+isDWXO5D2hL79mHw1H/qhAjesXQHRmCC09io2I1sywryWogy3RRXP eCLbKrLoBSJk/I8hyLu5Jk/3wUJUPsPN5fxgTv9SgSGyvsfNNBIG1KTmLkIb6vyQm77X zp0LTglEoW+S9s/qQWTUdVO9gord1LSIxZjwgiutzogZDGbcX7haUBXr95qpwiUKSm0q bb2A== X-Gm-Message-State: AOAM532US1aq8Wu956kXIyyvbtXQGooXguIjSsXdS5CwEfZkQJU5rzmq Fm7IB18UOZPLRipUPdzcaqjqkbLexBw= X-Google-Smtp-Source: ABdhPJyYWgDNjIhpHgkkI78wFl3G0Wj4TqHJVylgpRgCd1AxDymvwUTVA/7BSVJvxhzuQOCKg0Ls2Q== X-Received: by 2002:a05:600c:2259:: with SMTP id a25mr2162618wmm.133.1631625289863; Tue, 14 Sep 2021 06:14:49 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:49 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 09/25] trace-cmd record: Append trace options after the trace data are written Date: Tue, 14 Sep 2021 16:14:22 +0300 Message-Id: <20210914131438.3965484-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7, the CPU trace metadata is saved in a trace option. As this metadata has file offsets, which depend on the CPU trace data, the option must be written in the file after the CPU trace data. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 35d9ee5f..879acb7c 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4449,6 +4449,9 @@ static void write_guest_file(struct buffer_instance *instance) if (tracecmd_write_cpu_data(handle, cpu_count, temp_files, "") < 0) die("failed to write CPU data"); + if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS) + tracecmd_write_options(handle); + tracecmd_output_close(handle); for (i = 0; i < cpu_count; i++) @@ -4597,7 +4600,8 @@ static void record_data(struct common_record_context *ctx) append_buffer(handle, instance, temp_files); } } - + if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS) + tracecmd_write_options(handle); free(temp_files); } if (!handle) From patchwork Tue Sep 14 13:14:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493261 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 6752AC433F5 for ; Tue, 14 Sep 2021 13:14:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51156610E6 for ; Tue, 14 Sep 2021 13:14:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233254AbhINNQL (ORCPT ); Tue, 14 Sep 2021 09:16:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQJ (ORCPT ); Tue, 14 Sep 2021 09:16:09 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 682BCC061574 for ; Tue, 14 Sep 2021 06:14:52 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id t18so20200207wrb.0 for ; Tue, 14 Sep 2021 06:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bZYW/4C9hB/Gnz9nbQ499Xz+kEDrIm9y7WAFhfj/BVU=; b=lpW2xKKoESggUjpj/GkMFUA1UbFe7zOEuqvKDSzvU6JyyG+jxP4Pzn2CXYieLCiSaT WgDXylMTug3Q5KMqImADY1ToGkKVuvvFb0ziDEoYpvx4qraGflBOhZH0uR/EF2OFUGRl fTr4SF4R+LH0uXFnASW1iSmRSvyx/eKltqtaKQKJwHQP7Bj9OvTDv4EHTIo/I5SEG65Z DKup0JL+xnALAPIqEqVS5HycNLW50UJrfuSPKF7dTlHrZTyEmwXXVp9bR60Pb04o31K8 zxeI5aNyrWeeWopuHaTwUYf4dH0vvF3yBq9ozZM9cXnw5S23kbbe+VD6xn8SEAu0RdJU Koww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bZYW/4C9hB/Gnz9nbQ499Xz+kEDrIm9y7WAFhfj/BVU=; b=PFUe34u10+X7g92LXtx6bUCdcH3i3KC4aRr/3PIjOhknwD7PyJY8vlnGr06Al5YrBs YLut8SGibiGXt5GekMn07SawAtJMxIu8m+B0F31uxidwVd0lDO+a/ClH26BXj57zlWoP 9qe4zzY/fsKovlI8Gvc5qt3SqIhtFnHV95BOGP3RxEZ8ijcq0o8+8wBYxkzSDpbiN7sF tRP01YyTHnL8BZw2Kpj4q4aMPiGiVSpokLY6Q2qpNhaLvL6RAZSteWfeIDljlRabLhRj vJJLPEzzTJFSmAUh32BzNTX2EIaxFz32MUHpTemsUW56AlGxfJpTGsxLn81pseapqzbb A3nA== X-Gm-Message-State: AOAM530V/T5mn+Xj6u3VbYXPX01d8pd7YgGgCaHofgI4tbV86vYhdhA6 onYi4jUQeUaUdug/wn9J8yH+OEQvXuk= X-Google-Smtp-Source: ABdhPJyPhfGZxr9U4NSmYeMaaNV/3YqGJAfOV1eHovwWNb7n4vbGQpLKyalp9ZuYTyLTtcozwpMTyg== X-Received: by 2002:adf:82a8:: with SMTP id 37mr19053925wrc.409.1631625290972; Tue, 14 Sep 2021 06:14:50 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:50 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 10/25] trace-cmd library: Add section header before flyrecord trace data Date: Tue, 14 Sep 2021 16:14:23 +0300 Message-Id: <20210914131438.3965484-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7, write a section header at the beginning of each section with flyrecord trace data. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index e2d03f1c..e0bdf47f 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1896,10 +1896,12 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, int cpus, struct cpu_data_source *data, const char *buff_name) { struct data_file_write *data_files = NULL; + enum tracecmd_section_flags flags = 0; tsize_t data_offs, offset; unsigned long long endian8; unsigned long long read_size; char *clock; + char *str; int ret; int i; @@ -1918,6 +1920,13 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, if (!HAS_SECTIONS(handle) && do_write_check(handle, "flyrecord", 10)) goto out_free; + if (asprintf(&str, "buffer flyrecord %s", buff_name) < 1) + goto out_free; + offset = out_write_section_header(handle, TRACECMD_OPTION_BUFFER, str, flags, false); + free(str); + if (offset == (off_t)-1) + goto out_free; + data_files = calloc(cpus, sizeof(struct data_file_write)); if (!data_files) goto out_free; @@ -1998,6 +2007,9 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) goto out_free; + if (out_update_section_header(handle, offset)) + goto out_free; + free(data_files); handle->file_state = TRACECMD_FILE_CPU_FLYRECORD; From patchwork Tue Sep 14 13:14:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493263 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 53591C433EF for ; Tue, 14 Sep 2021 13:14:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C2A7610D1 for ; Tue, 14 Sep 2021 13:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233239AbhINNQM (ORCPT ); Tue, 14 Sep 2021 09:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbhINNQL (ORCPT ); Tue, 14 Sep 2021 09:16:11 -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 9B664C061767 for ; Tue, 14 Sep 2021 06:14:53 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id b21-20020a1c8015000000b003049690d882so2039139wmd.5 for ; Tue, 14 Sep 2021 06:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ffE30IdThPAC8ILnbemopf/bsn2jueqRCO+D2m9I5Kc=; b=J9y9DxfPPh083n+yON9wiTVIJIw7EWmRfskLlFg/AD7SJWMEZuEhKZ13Ef5+EVRVHJ yfG+kZiEImfxPFMuPjnGI2bDxGE19q605VC3MMu0H7r5zNNkLAOkvdU1DQJX/MjmmRjE /g9x7xSU1V8JdqKLvCacKX/1PTAFcFQCdTvEOc/jvvX6DRk2EXKp0UGDE9JbaUAwB81F Ta8tmd75+pncG7bLtMsFuCvnf7fOfEDb6PCJLDEjDLP8Cb9APd+olw3QGO1h0wQ0tNfS Vo5io+gB2s5kMR3S6AefRMXFkip4Lt6josrA1Urkq8GEi77uZSmNh1c3mGMpuYFPkBC9 TahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ffE30IdThPAC8ILnbemopf/bsn2jueqRCO+D2m9I5Kc=; b=iFREYiT+hoBwvlhszM+PFs30zMo0I80q1a1bpac6FFqFA9YJaCRtO5XbULGXtX01we kLuQF7hcqYiD5Zp4sMzYlONBrjbRa0P17Vbomo4ZA2c/5J0gBNn+EdZe/xEKAs4z9DFB IrpcHPpbI1tVmLrlI5NAH6b184H71/SlR1MJG4SwUyfBDJjdX9syR1Rh2qmjl659jSbD e0jxh8e8d2qntWZI/CNgzvxaeNbUjYRrq9orZVJIGVBBVXnKpTVbJcUEWC4Nh6fflugc THrJCoY/1GILX0e4ESCd2J780utr8oqagcizInb6ZxYu7tMYMhj1IT9IFMvSlPG2ndwD s4EQ== X-Gm-Message-State: AOAM530cMyVexmoqUQJvLCnt3uODx2pdQWH1aekCQ9SKJN/M9pcqC4wK KR75iNITJyAWB4j75pNMAoeOT1yMnaU= X-Google-Smtp-Source: ABdhPJyJAMQxdjAga5v3w23Vn1/JkAednEN1hC/TIpER/prcUFZ1GUjXFPmIR9jyMrQYvZquRDmaig== X-Received: by 2002:a1c:a713:: with SMTP id q19mr2180774wme.42.1631625292230; Tue, 14 Sep 2021 06:14:52 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:51 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 11/25] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format Date: Tue, 14 Sep 2021 16:14:24 +0300 Message-Id: <20210914131438.3965484-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 format is based on sections. To fit the latency trace data in this structure, a new section and option for it is defined: BUFFER_TEXT It is similar to the BUFFER section which holds the flyrecord binary data, but has a latency specific design for text data. The BUFFER_TEXT section has: - section header, as all other sections - compression of the trace data, optional - corresponding trace option, pointing to the section Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index d85a4b3b..d8a981af 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -144,6 +144,7 @@ enum { TRACECMD_OPTION_KALLSYMS, TRACECMD_OPTION_PRINTK, TRACECMD_OPTION_CMDLINES, + TRACECMD_OPTION_BUFFER_TEXT, TRACECMD_OPTION_MAX, }; diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index e0bdf47f..c62fcfca 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1788,7 +1788,9 @@ out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name, struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) { + enum tracecmd_section_flags flags = 0; struct tracecmd_output *handle; + tsize_t offset; char *path; int fd; @@ -1811,7 +1813,8 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in if (tracecmd_write_cpus(handle, cpus) < 0) goto out_free; - + if (tracecmd_write_buffer_info(handle) < 0) + goto out_free; if (tracecmd_write_options(handle) < 0) goto out_free; @@ -1821,23 +1824,40 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in goto out_free; } - if (do_write_check(handle, "latency ", 10)) + if (!HAS_SECTIONS(handle) && do_write_check(handle, "latency ", 10)) goto out_free; path = get_tracing_file(handle, "trace"); if (!path) goto out_free; + offset = do_lseek(handle, 0, SEEK_CUR); + if (HAS_SECTIONS(handle) && + !out_add_buffer_option_v7(handle, "", TRACECMD_OPTION_BUFFER_TEXT, offset, 0, NULL)) + goto out_free; + + offset = out_write_section_header(handle, TRACECMD_OPTION_BUFFER_TEXT, + "buffer latency", flags, false); + copy_file(handle, path); + if (out_update_section_header(handle, offset)) + goto out_free; put_tracing_file(path); handle->file_state = TRACECMD_FILE_CPU_LATENCY; + if (HAS_SECTIONS(handle)) + tracecmd_write_options(handle); + return handle; out_free: - tracecmd_output_close(handle); + if (handle) + tracecmd_output_close(handle); + else + close(fd); + unlink(output_file); return NULL; } From patchwork Tue Sep 14 13:14:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493265 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 C85F2C433FE for ; Tue, 14 Sep 2021 13:14:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2F9B610E6 for ; Tue, 14 Sep 2021 13:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233240AbhINNQN (ORCPT ); Tue, 14 Sep 2021 09:16:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQM (ORCPT ); Tue, 14 Sep 2021 09:16:12 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BACFC061574 for ; Tue, 14 Sep 2021 06:14:55 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id i23so20176238wrb.2 for ; Tue, 14 Sep 2021 06:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h/pyTwtmdkmQfcEOK48Q4K0PQZdPSwZMcfx+gGOvG+0=; b=ePEd97874CBOR5dLnJJoq3dB2GeL+LGetHatpQXBCn9ocYZlbBuaq+Tzj3tut53Udd GssSC1EgAUmwyAVJGwKUlgbJ0WRjYlZL4zXz+W2b7huW85Zubcd6Os98pdTdi1rWGtun bZcN4h+9kafecuPvrYFsAmyhFu/v6rNFe0eV7+CczlP2F2Y8Z75EOvpVzvgyjsoXz9/L 3ya7loPbo4Ps8bOj2zlc4RJq/2H4vkxQluXsmpvxLRB5CLxB3oLs9vaHfMg8HsLWPkGq s2LHuorLmBICBkXZBMTbUXHX5jqdm/DvPwMCEu9+w75pfHnSPaG0NkWM1LRLUvE3lISx 18dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h/pyTwtmdkmQfcEOK48Q4K0PQZdPSwZMcfx+gGOvG+0=; b=wdg6a3CadtH/ub1w3ZuUzfVRmgqPzAvHgzKztaDD3fUzpSTGFiX9qVZmAeArqwUc8S lXQJnERiOryH5byhe3ipitHAJqw63fqTf19QWWo3h/dhfkTPztvzp2Dj0Lh0rznIFQCL YRuavxVl609EFBhOLb61irtdS4YgXQvNiJ37ZKcr9m9FbhfCJXxC2q8tPF/UGw4qhXcX g7K1VjHTw7RMzhYd5b+W1+YKCnTJ3OZdgO/R8SP34oBmQsUrmIaUkvM+A6fhdw/HOtjY WaNEkjKjn2SI0KkZiXgvXaA36OIcA1pBiy01aYxFnvQACaBBLSk1S6p15XFotHnBlAXd adZw== X-Gm-Message-State: AOAM531ZwsRt8F7kvP/9dMzMu5P1IL0+5EdC8EXMskSRBDLqsmaBq4l4 RzWN+qB87HjC4THuClWn8gmgdr2FMNY= X-Google-Smtp-Source: ABdhPJxQStRzuHdBRAurSFwGKq2BtcpKUO19K82Ay7oUKl/IsETQWDOPAuO4EQKqqY4Ztd0XX9jRzg== X-Received: by 2002:a5d:58c9:: with SMTP id o9mr19179727wrf.279.1631625293823; Tue, 14 Sep 2021 06:14:53 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:53 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 12/25] trace-cmd library: Do not write CPUs with empty trace data Date: Tue, 14 Sep 2021 16:14:25 +0300 Message-Id: <20210914131438.3965484-13-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 has more flexible design, which allows to write only CPUs with trace data in the file. If a CPU has no recorded trace data, do not put it in the trace file version 7. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index c62fcfca..87b85e0f 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2074,8 +2074,10 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, if (i < cpus) ret = -1; - else + else if (size || !HAS_SECTIONS(handle)) ret = out_write_cpu_data(handle, cpus, data, buff_name); + else + ret = 0; for (i = 0; i < cpus; i++) { if (data[i].fd >= 0) From patchwork Tue Sep 14 13:14:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493267 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 8C709C433EF for ; Tue, 14 Sep 2021 13:14:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75F7A610A6 for ; Tue, 14 Sep 2021 13:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233241AbhINNQQ (ORCPT ); Tue, 14 Sep 2021 09:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQO (ORCPT ); Tue, 14 Sep 2021 09:16:14 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 232E8C061574 for ; Tue, 14 Sep 2021 06:14:57 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w29so19379557wra.8 for ; Tue, 14 Sep 2021 06:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M8YlL1SlQNYrxnekGaIBaXbmG7rEz6Zt19sqQpUN2hk=; b=fpr+rgjZyjpiSSWWrxgrw88PV7oGoefAYnGovNDleuOH0AgB61ssa3eugkexSvQfL8 Skk8mfNV6jIZBBQLeTJdDgdAscTnTd8VPxaThsKvuRALP4NPaO+Bk/sc4Prb1tdBdNiS j8INd6UBHQa9Lmo+aR0GIbfA62ukRTO9rnldnCKHlKzAqsqaNZZVjG0tfUiPR+At6Guz SkL09y5gMXNLmJZSw9TGzsbhvx2GpzeauFQSKU6FfKUJ/Y+hEF/dF35NovP5rci0r6oF mCCHYzBl+dfj4esDHuH4VaK8+PooVNVO1HkYDNpW5XvdNSRhcivwuvCQFFFW1zxOmxkO 2JiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M8YlL1SlQNYrxnekGaIBaXbmG7rEz6Zt19sqQpUN2hk=; b=tsd/dMgwb4iW3WjyS2rkVKZMVP+aZKEugTkmm5cyPsUJ7z5oIbdwFsok/NMpbOsYu3 0pRfdG77T5DV9X8b6NlXKn6sLrTd/nykKMKW3PcrUCwAZ97CrrQYfiySYm/4zeVhtsZd VbrrF0YKWjhjNyrM8SeE5OLV88TTkIYu/n/PH5cdLt1tzU9A2WXBsrRViRdVATT5Mt9P pisPWbCTZwTCMjV6JnaEm3kXnpEOM8nERZtk6Na6fizIMZqWa+i/jjkXwJCuk11IGd+Q cWCFipApU0oOqtl5I2QR1fgqrr1xi61wm431FokxPcQus7oI63lwMn8D250GQC+2Z4ud 6tMw== X-Gm-Message-State: AOAM5311a2FEK1TaxYjRcYxCrh40pI7KJ6K5liXfK23RyzN3DOVhuc0K mSDrKQt9hVqLeanNNhpjNDJtFKZLeI8= X-Google-Smtp-Source: ABdhPJwcSKZ5y7RjI5rdE3JP+prVIv8BcjafEri57qF8/I9S9/i9j/j7JcTy2dRH+P47cHgAzQAWEw== X-Received: by 2002:a05:6000:1287:: with SMTP id f7mr19092348wrx.221.1631625295716; Tue, 14 Sep 2021 06:14:55 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:54 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 13/25] trace-cmd library: Add macro to check file state on reading Date: Tue, 14 Sep 2021 16:14:26 +0300 Message-Id: <20210914131438.3965484-14-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 has flexible structure. It allows reading almost any part of the file at any time, unlike the version 6 file when reading state must be validated at each step. Added a macro to handle these checks. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index de8e0d72..85100aa4 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -165,6 +165,8 @@ struct tracecmd_input { __thread struct tracecmd_input *tracecmd_curr_thread_handle; +#define CHECK_READ_STATE(H, S) ((H)->file_version < FILE_VERSION_SECTIONS && (H)->file_state >= (S)) + static int read_options_type(struct tracecmd_input *handle); void tracecmd_set_flag(struct tracecmd_input *handle, int flag) @@ -381,7 +383,7 @@ static int read_header_files(struct tracecmd_input *handle) char *header; char buf[BUFSIZ]; - if (handle->file_state >= TRACECMD_FILE_HEADERS) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_HEADERS)) return 0; if (do_read_check(handle, buf, 12)) @@ -587,7 +589,7 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex) int unique; int ret; - if (handle->file_state >= TRACECMD_FILE_FTRACE_EVENTS) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_FTRACE_EVENTS)) return 0; if (regex) { @@ -660,7 +662,7 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex) int unique; int ret; - if (handle->file_state >= TRACECMD_FILE_ALL_EVENTS) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_ALL_EVENTS)) return 0; if (regex) { @@ -745,7 +747,7 @@ static int read_proc_kallsyms(struct tracecmd_input *handle) char *buf = NULL; int ret; - if (handle->file_state >= TRACECMD_FILE_KALLSYMS) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS)) return 0; ret = read4(handle, &size); @@ -781,7 +783,7 @@ static int read_ftrace_printk(struct tracecmd_input *handle) char *buf = NULL; int ret; - if (handle->file_state >= TRACECMD_FILE_PRINTK) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK)) return 0; ret = read4(handle, &size); @@ -832,7 +834,7 @@ static int read_cpus(struct tracecmd_input *handle) { unsigned int cpus; - if (handle->file_state >= TRACECMD_FILE_CPU_COUNT) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_CPU_COUNT)) return 0; if (read4(handle, &cpus) < 0) @@ -2838,7 +2840,7 @@ static int read_options_type(struct tracecmd_input *handle) { char buf[10]; - if (handle->file_state >= TRACECMD_FILE_CPU_LATENCY) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_CPU_LATENCY)) return 0; if (do_read_check(handle, buf, 10)) @@ -3004,7 +3006,7 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle) char *cmdlines = NULL; int ret; - if (handle->file_state >= TRACECMD_FILE_CMD_LINES) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES)) return 0; ret = read_data_and_size(handle, &cmdlines, &size); From patchwork Tue Sep 14 13:14:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493269 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 52DAAC433EF for ; Tue, 14 Sep 2021 13:15:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AF01610CE for ; Tue, 14 Sep 2021 13:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbhINNQR (ORCPT ); Tue, 14 Sep 2021 09:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233235AbhINNQQ (ORCPT ); Tue, 14 Sep 2021 09:16:16 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5943C061760 for ; Tue, 14 Sep 2021 06:14:58 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id w29so19379678wra.8 for ; Tue, 14 Sep 2021 06:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gF9UzrkCpbQGU+P5Zr9zOkb81SGV9PwzYYl4jv5f5Kc=; b=lt6rn01r1294P13wboWE60OLzygdedhdwwlZ/brVnLhbSWy5bvSwexGu3F7Lg2qRLN aRgvdbTW6z//lW4QAiDAlpCymzKDiW6rynZufEN4/Q7aurnQUiGFk0OJHKOU15dtR8am L+3kgSWRtb+MTKUO+l7TpY8BcS49w9dC11nV8Nffg4CMuCLjUn/kkeGEqSCsAGXT2iS7 ASLHwRC5Zh38tX13AXfu2sTEucs9lwPZpwiL0lFaEFwFyqtLZ4zlV3k7lf+ZsETvYOUZ dWGMQId2EzrpUFjvSZc0Yp9mihPe5ktrTXMHvkCYH2r6CbfZqcb8jaaz8isjpz+lHTW0 Gw7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gF9UzrkCpbQGU+P5Zr9zOkb81SGV9PwzYYl4jv5f5Kc=; b=ODpP78AzvqD8KZFSbKRIo/j841IH8bAiExIbM/NJIj9GOUB29hsQ48lhfAX9QWVyyG IRV0U9UnLx05jlIJ3rcv+UxXexkvNjIpG4kqULsFcvi2cNMI5UQh+2dE6EdiW+n8VGHX BhVoCrqq9Qdm9bkJLwYWUpftLji3WQ3dHJtyzOqQbeSVIC0P1SZzJXGrZOMpukrWrady sm2H8V4ltud33tAaxMwgtYroZ1JHgWclJEddG0u2PULpTo0nK6NCkEqjJ+ruuMNBDg7o fddF1TLv5rea1NDm/tXvLSDwtMWCsWh2xrDOqKxz9WevOFBUEiTHX77gD/uKB0NSkQ5U gkNw== X-Gm-Message-State: AOAM532nWCFtffWEJWw8+CuUjUHKUPmheAke3flmNg4Wp+iKZ1w9sW0O 8129J/phOMXItBhNpv+Yj+N3+UxNm+Q= X-Google-Smtp-Source: ABdhPJzs5bKVgfR83meNqO1PbQCE/u6jzqLmMsjLg3USbpBkg58jCO6Hcdi07HCqCI4OscU0rIeDyw== X-Received: by 2002:adf:e108:: with SMTP id t8mr18501430wrz.84.1631625297422; Tue, 14 Sep 2021 06:14:57 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:56 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 14/25] trace-cmd library: Introduce sections in trace file reading logic Date: Tue, 14 Sep 2021 16:14:27 +0300 Message-Id: <20210914131438.3965484-15-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 is based on sections. Added an internal sections database and new helper functions to add, read, open and close file sections. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 85100aa4..978758c0 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -114,6 +114,14 @@ struct tsc2nsec { unsigned long long offset; }; +struct file_section { + int id; + unsigned long long section_offset; + unsigned long long data_offset; + enum tracecmd_section_flags flags; + struct file_section *next; +}; + struct tracecmd_input { struct tep_handle *pevent; unsigned long file_state; @@ -153,6 +161,7 @@ struct tracecmd_input { struct hook_list *hooks; struct pid_addr_maps *pid_maps; /* file information */ + struct file_section *sections; size_t header_files_start; size_t ftrace_files_start; size_t event_files_start; @@ -376,6 +385,58 @@ static int read8(struct tracecmd_input *handle, unsigned long long *size) return 0; } +static struct file_section *section_get(struct tracecmd_input *handle, int id) +{ + struct file_section *sec; + + for (sec = handle->sections; sec; sec = sec->next) { + if (sec->id == id) + return sec; + } + + return NULL; +} + +static struct file_section *section_open(struct tracecmd_input *handle, int id) +{ + struct file_section *sec = section_get(handle, id); + + if (!sec) + return NULL; + + if (lseek64(handle->fd, sec->data_offset, SEEK_SET) == (off64_t)-1) + return NULL; + return sec; +} + +static void section_close(struct tracecmd_input *handle, struct file_section *sec) +{ + /* To Do */ +} + +static int section_add_or_update(struct tracecmd_input *handle, int id, int flags, + unsigned long long section_offset, + unsigned long long data_offset) +{ + struct file_section *sec = section_get(handle, id); + + if (!sec) { + sec = calloc(1, sizeof(struct file_section)); + if (!sec) + return -1; + sec->next = handle->sections; + handle->sections = sec; + } + sec->id = id; + if (section_offset) + sec->section_offset = section_offset; + if (data_offset) + sec->data_offset = data_offset; + if (flags > 0) + sec->flags = flags; + return 0; +} + static int read_header_files(struct tracecmd_input *handle) { struct tep_handle *pevent = handle->pevent; @@ -3508,6 +3569,7 @@ void tracecmd_ref(struct tracecmd_input *handle) */ void tracecmd_close(struct tracecmd_input *handle) { + struct file_section *del_sec; int cpu; int i; @@ -3547,6 +3609,12 @@ void tracecmd_close(struct tracecmd_input *handle) free(handle->version); close(handle->fd); + while (handle->sections) { + del_sec = handle->sections; + handle->sections = handle->sections->next; + free(del_sec); + } + for (i = 0; i < handle->nr_buffers; i++) free(handle->buffers[i].name); free(handle->buffers); @@ -3991,6 +4059,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->nr_buffers = 0; new_handle->buffers = NULL; new_handle->version = NULL; + new_handle->sections = NULL; new_handle->guest = NULL; new_handle->ref = 1; if (handle->trace_clock) { From patchwork Tue Sep 14 13:14:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493271 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 255DDC433F5 for ; Tue, 14 Sep 2021 13:15:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05401610D1 for ; Tue, 14 Sep 2021 13:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233242AbhINNQS (ORCPT ); Tue, 14 Sep 2021 09:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbhINNQR (ORCPT ); Tue, 14 Sep 2021 09:16:17 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C8A6C061574 for ; Tue, 14 Sep 2021 06:15:00 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x6so20129734wrv.13 for ; Tue, 14 Sep 2021 06:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xP+T3hWSON7wU2+dz9tSwVvMuF5QsCbuc+E5tQxOSNk=; b=NQsc0aZeauTskltiMl5jGbTE85yQT1L9WD1v/ZHxbOc5N33j2G6JR0HEIBJZIzPPVL DVNjmjLu/fdtMDxbNfWTF22pSOrrkxvF5krH9JWMcny55rN8MAk+EVjIt7Dr5jFp+IoB CQBb8xRv7ZQpHhM5eECKDLWEDteUJ+WS9J7MN9Zi2+URJHLWjnZRtv4d2DLQsfVPaIB/ 2FULyAc/ktc2lC0rX78tcDoZRO0t4JElif6HHQzHDzrWfTWEdA7INBRFR8r1AYSUOpUA et0FO6KTz+HsxL96mMhI3aagbwdSUgjgERScYN3E4wPxbHmqvg6rmbfARoX3GoawN2qU 9F4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xP+T3hWSON7wU2+dz9tSwVvMuF5QsCbuc+E5tQxOSNk=; b=nygJs7z+UI1ula1yZXQq91A6hF3zV4C0W1jjTZcsgakEGpZgIsKiZm6AwMrOffWaUe YkN3OEzTYuLFbneoHzmzBPBo2rmfba2duAl//22fUWW2QRVvfHm9QjA4xfJ++Gt+BJII 4fT0a0VHeSY9ow9sSdJhGd+n6Ag9Qt1/BP08wbLIbX0iRE0YS96ZuEvruetA9W/9alOt PaZNqzoNOpX0+bmHyutuVHB+5YuvO2EmQlUrbISXhnPxXyT7jWtkKN8KxjasC2Qzpd90 xXzDRCWUcBA0l7BD9aU6HhQhFJL2Pt+JVufFq9CGEu98YAeikUwhQFl5Tqx7M6NJUp7o hqAQ== X-Gm-Message-State: AOAM533JTW4jsD81hvGxvPnpSYWBNAKRM/9x0Kb3toPMgZUA0zy1wtk8 0Zp0pQHA1Hm/n9slOG0Zab38e8eikDA= X-Google-Smtp-Source: ABdhPJwte+7gaVPH7QEb+90RYxPEf+TRa82X+bkRsRNq9W81aIOc1eNNktsDDjt6lvrXuumbXixipA== X-Received: by 2002:a5d:5408:: with SMTP id g8mr18995406wrv.34.1631625298927; Tue, 14 Sep 2021 06:14:58 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:58 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 15/25] trace-cmd library: Initialize internal sections database on file read Date: Tue, 14 Sep 2021 16:14:28 +0300 Message-Id: <20210914131438.3965484-16-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Add sections in internal database on file reading and parsing. In trace file version 7, sections are initialized when parsing corresponding trace options. In version 6 files, sections are retrieved on file reading, as there they are in a fixed position in the file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-input.c | 65 +++++++++++++++---- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index d8a981af..a08890df 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -153,6 +153,7 @@ enum { TRACECMD_FL_BUFFER_INSTANCE = (1 << 1), TRACECMD_FL_IN_USECS = (1 << 2), TRACECMD_FL_RAW_TS = (1 << 3), + TRACECMD_FL_SECTIONED = (1 << 4), }; struct tracecmd_ftrace { diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 978758c0..bc3bc5d2 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -164,8 +164,7 @@ struct tracecmd_input { struct file_section *sections; size_t header_files_start; size_t ftrace_files_start; - size_t event_files_start; - size_t options_start; + unsigned long long options_start; size_t total_file_size; /* For custom profilers. */ @@ -175,6 +174,7 @@ struct tracecmd_input { __thread struct tracecmd_input *tracecmd_curr_thread_handle; #define CHECK_READ_STATE(H, S) ((H)->file_version < FILE_VERSION_SECTIONS && (H)->file_state >= (S)) +#define HAS_SECTIONS(H) ((H)->flags & TRACECMD_FL_SECTIONED) static int read_options_type(struct tracecmd_input *handle); @@ -447,6 +447,10 @@ static int read_header_files(struct tracecmd_input *handle) if (CHECK_READ_STATE(handle, TRACECMD_FILE_HEADERS)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_HEADER_INFO, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + if (do_read_check(handle, buf, 12)) return -1; @@ -490,9 +494,6 @@ static int read_header_files(struct tracecmd_input *handle) free(header); - handle->ftrace_files_start = - lseek64(handle->fd, 0, SEEK_CUR); - handle->file_state = TRACECMD_FILE_HEADERS; return 0; @@ -653,6 +654,10 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex) if (CHECK_READ_STATE(handle, TRACECMD_FILE_FTRACE_EVENTS)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_FTRACE_EVENTS, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + if (regex) { sreg = &spreg; ereg = &epreg; @@ -693,8 +698,6 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex) goto out; } - handle->event_files_start = - lseek64(handle->fd, 0, SEEK_CUR); handle->file_state = TRACECMD_FILE_FTRACE_EVENTS; ret = 0; out: @@ -726,6 +729,10 @@ static int read_event_files(struct tracecmd_input *handle, const char *regex) if (CHECK_READ_STATE(handle, TRACECMD_FILE_ALL_EVENTS)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_EVENT_FORMATS, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + if (regex) { sreg = &spreg; ereg = &epreg; @@ -811,6 +818,10 @@ static int read_proc_kallsyms(struct tracecmd_input *handle) if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_KALLSYMS, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + ret = read4(handle, &size); if (ret < 0) goto out; @@ -847,6 +858,10 @@ static int read_ftrace_printk(struct tracecmd_input *handle) if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_PRINTK, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + ret = read4(handle, &size); if (ret < 0) goto out; @@ -2885,6 +2900,18 @@ static int handle_options(struct tracecmd_input *handle) handle->tsc_calc.offset = tep_read_number(handle->pevent, buf + 8, 8); break; + case TRACECMD_OPTION_HEADER_INFO: + case TRACECMD_OPTION_FTRACE_EVENTS: + case TRACECMD_OPTION_EVENT_FORMATS: + case TRACECMD_OPTION_KALLSYMS: + case TRACECMD_OPTION_PRINTK: + case TRACECMD_OPTION_CMDLINES: + if (size < 8) + break; + section_add_or_update(handle, option, -1, + tep_read_number(handle->pevent, buf, 8), 0); + break; + default: tracecmd_warning("unknown option %d", option); break; @@ -3070,6 +3097,10 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle) if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES)) return 0; + if (!HAS_SECTIONS(handle)) + section_add_or_update(handle, TRACECMD_OPTION_CMDLINES, 0, 0, + lseek64(handle->fd, 0, SEEK_CUR)); + ret = read_data_and_size(handle, &cmdlines, &size); if (ret < 0) goto out; @@ -3364,6 +3395,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) struct tracecmd_input *handle; char test[] = TRACECMD_MAGIC; unsigned int page_size; + size_t offset; char *version; char buf[BUFSIZ]; unsigned long ver; @@ -3403,6 +3435,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) handle->file_version = ver; free(version); + if (handle->file_version >= FILE_VERSION_SECTIONS) + handle->flags |= TRACECMD_FL_SECTIONED; + if (do_read_check(handle, buf, 1)) goto failed_read; @@ -3427,14 +3462,16 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) read4(handle, &page_size); handle->page_size = page_size; - handle->header_files_start = - lseek64(handle->fd, 0, SEEK_CUR); - - handle->total_file_size = - lseek64(handle->fd, 0, SEEK_END); + offset = lseek64(handle->fd, 0, SEEK_CUR); + handle->total_file_size = lseek64(handle->fd, 0, SEEK_END); + lseek64(handle->fd, offset, SEEK_SET); - handle->header_files_start = - lseek64(handle->fd, handle->header_files_start, SEEK_SET); + if (HAS_SECTIONS(handle)) { + if (read8(handle, &(handle->options_start))) { + tracecmd_warning("Filed to read the offset of the first option section"); + goto failed_read; + } + } handle->file_state = TRACECMD_FILE_INIT; From patchwork Tue Sep 14 13:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493273 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 1AFF7C433EF for ; Tue, 14 Sep 2021 13:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F91610A6 for ; Tue, 14 Sep 2021 13:15:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233243AbhINNQV (ORCPT ); Tue, 14 Sep 2021 09:16:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbhINNQT (ORCPT ); Tue, 14 Sep 2021 09:16:19 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6DE4C061574 for ; Tue, 14 Sep 2021 06:15:01 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l7-20020a1c2507000000b002e6be5d86b3so2507526wml.3 for ; Tue, 14 Sep 2021 06:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=37H7EkMF0fOQE7e1qQRM4zym8Bfjvfnp/V1oDS0mO3Y=; b=cOug94CY5wbSxPPLojsQq5eXfCZihLvnGFR/ZDj0fYs4Gxlx7kbuQbctlnbmD3r/eu HUgLycfijxcH4xx5IUDZ4SayPz0hn3ZUe72z6MuAyet3FW8Yevj8DdE8pR9Kp/RmUypb EvBOSIRmRb2UWWq1q6BgwRNaugOgOXBLnKTOI04OCAQ712FT7EttQqMpJAPz5zE5knEd MhqC+nFsGDn37KRi8EQZKtXP8F7zoZkw2jgTA1u8AxmHkQh+11BwkSYlHI7xD0TPIBy/ yEyeO/3kR7iOo9DfZ4Kana9LreAm74rpt4JS4ilAc+LeVTJ5rvIReGAjjttDqHfUNdAm F5Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=37H7EkMF0fOQE7e1qQRM4zym8Bfjvfnp/V1oDS0mO3Y=; b=TwTdvpckcNn56njOqoh2NJaJn0LbwxYdZjAUOW5G9nTNH8pBnpSz2YXbiJwEzVWAZX qWctLTj9GwkRgqwC/UEgpDTEi5h5neZb/Ly0YOYGd60YhvH55DdV11Ul1lOwBECInnSp DeAVQg+lqhvyb6YnWYPRtBE2FRQvDevnqgGVF4/TVGh9y2XBjFHT+JK/o2kHm/2XuOq8 QHvYBu4UmAw/g/CChcxBXx7utFSUsB8561VsZV6sp14B+J9DQrB6HbBbUGpOjWNjUiM7 sQmRTZvHBma1adJzDYPCqFHyoX4VC+drAu1snWC7bgvBJZZm7th79yDQntZI2p+dqsNx hAnw== X-Gm-Message-State: AOAM5336XD8MtBBF2rLZTv4EhCpcmfeYPtHTH6PBauvs7qoC9fmC7E26 1sSl2hxm0KlGeMQfvic5QsqGhODZs7M= X-Google-Smtp-Source: ABdhPJyZhdRKZIeFJ6ObcT1j8V+WwofUBwmIfoOMSgSp3+J3NKcDGcp1xYANWjZvKdUHYehfk9+kkg== X-Received: by 2002:a05:600c:4f53:: with SMTP id m19mr2187553wmq.2.1631625300527; Tue, 14 Sep 2021 06:15:00 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:14:59 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 16/25] trace-cmd library: Use sections database when reading parts of the trace file Date: Tue, 14 Sep 2021 16:14:29 +0300 Message-Id: <20210914131438.3965484-17-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Utilize the internal database with file sections, when reading parts of a trace file. This logic unifies the way trace file version 6 and 7 are processed. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index bc3bc5d2..785a1b93 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3283,21 +3283,26 @@ int tracecmd_make_pipe(struct tracecmd_input *handle, int cpu, int fd, int cpus) */ void tracecmd_print_events(struct tracecmd_input *handle, const char *regex) { - int ret; + struct file_section *sec; if (!regex) regex = ".*"; - if (!handle->ftrace_files_start) { - lseek64(handle->fd, handle->header_files_start, SEEK_SET); + sec = section_open(handle, TRACECMD_OPTION_HEADER_INFO); + if (sec) { read_header_files(handle); + section_close(handle, sec); + } + sec = section_open(handle, TRACECMD_OPTION_FTRACE_EVENTS); + if (sec) { + read_ftrace_files(handle, regex); + section_close(handle, sec); + } + sec = section_open(handle, TRACECMD_OPTION_EVENT_FORMATS); + if (sec) { + read_event_files(handle, regex); + section_close(handle, sec); } - ret = read_ftrace_files(handle, regex); - if (ret < 0) - return; - - read_event_files(handle, regex); - return; } /* Show the cpu data stats */ @@ -3901,6 +3906,7 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd, enum tracecmd_file_states start_state, enum tracecmd_file_states end_state) { + struct file_section *sec; int ret; if (!start_state) @@ -3916,13 +3922,17 @@ int tracecmd_copy_headers(struct tracecmd_input *handle, int fd, if (handle->file_state >= start_state) { /* Set the handle to just before the start state */ - lseek64(handle->fd, handle->header_files_start, SEEK_SET); + sec = section_open(handle, TRACECMD_OPTION_HEADER_INFO); + if (!sec) + return -1; /* Now that the file handle has moved, change its state */ handle->file_state = TRACECMD_FILE_INIT; } /* Try to bring the input up to the start state - 1 */ ret = tracecmd_read_headers(handle, start_state - 1); + if (sec) + section_close(handle, sec); if (ret < 0) goto out; From patchwork Tue Sep 14 13:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493275 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 ABD34C433F5 for ; Tue, 14 Sep 2021 13:15:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 930A6610E6 for ; Tue, 14 Sep 2021 13:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233263AbhINNQX (ORCPT ); Tue, 14 Sep 2021 09:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhINNQU (ORCPT ); Tue, 14 Sep 2021 09:16:20 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDCCC061760 for ; Tue, 14 Sep 2021 06:15:03 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id b6so20138172wrh.10 for ; Tue, 14 Sep 2021 06:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xNattvz/J11LjzAivA6IFJjNMkWHPy25Olv8iAQWFFA=; b=l61Pei02tbXFoRTkdOiPQkWQMchVDoDDWdZuefaTVNiRb1mpDpfo6Wp6KsxE5JBW6h xjs0V+oiEPmg/CHR6nGQAsiqcfZaOru2ceiWjY1H6hstz0TrJKFeu2TSCN7q3TcAmXNN 2s70cm1ReqFIvM7Y3y9y/zsmeuOl5xYjwpJzeMAtIYc8RAm/ATyZfiJMJedJA+3h/CM3 BsDO3dhtP6HvC/Z9Kr0BSRzyeGXfsFlFh8i/sgl1NhazM9Td40wb7anvssBX3rJ/lBvu oSqKBtkWjy7yH5ZEKG8OcWOJVodkP2yizguwhUsCrZekhnpzbeCwtFc/o6Xe2b1VtW8Z qEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xNattvz/J11LjzAivA6IFJjNMkWHPy25Olv8iAQWFFA=; b=H21Fpe1eSl2mWN6m/2fz2HS6sh1VtsNLWh71Wyb80SdxBY6fGZGl+nt40Z1pN51aiq Wczc8diNkfZ/YiR3+P2g8zMi1bF2JOboY0moZLe3CMaWsZinGwg/An2Vg6lF2C1p0RSz 0Zuo9uKYKNk+8XjNqXH8Xa4PWWwDt5JCfzA/X7HIAJEOZn6sDrIBANCPXt2/pumXRDSC /Iui3DIVWI3ftZcglN1J5x6yxLBM3RAuF3VjYHjBfiTTSwNfYlE0RTnkkw29iEStCSgv qc9AgBQrG3qkCrdJaQf7nXeZFMPnhPgsW4Vh9VbijXOvGeuNGh8jEtXxKmryKu9EdYcc hjhw== X-Gm-Message-State: AOAM5325WYXa4SYxXVB1lgoi9N+0Mlv44w0EPfyKNoTxGfTf/NA22waX RyAr8iQJ++BwcsecgiG7eUgjryeS9Yc= X-Google-Smtp-Source: ABdhPJyzypYoKmN3HqxX1/GvnIm3mNdplmCw29S9PIyP5+rU/BXhHVaAfSBnFh7QRyzRnpB/rcqmOg== X-Received: by 2002:adf:e603:: with SMTP id p3mr18429780wrm.357.1631625302123; Tue, 14 Sep 2021 06:15:02 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:01 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 17/25] trace-cmd library: Read headers from trace file version 7 Date: Tue, 14 Sep 2021 16:14:30 +0300 Message-Id: <20210914131438.3965484-18-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 has more flexible structure than version 6, headers are not located at fixed position in the file. A new logic is implemented to read and parse the headers from this new format. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 145 ++++++++++++++++++++++++++++++++---- 1 file changed, 130 insertions(+), 15 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 785a1b93..686655bd 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -162,8 +162,7 @@ struct tracecmd_input { struct pid_addr_maps *pid_maps; /* file information */ struct file_section *sections; - size_t header_files_start; - size_t ftrace_files_start; + bool options_init; unsigned long long options_start; size_t total_file_size; @@ -924,19 +923,7 @@ static int read_cpus(struct tracecmd_input *handle) return 0; } -/** - * tracecmd_read_headers - read the header information from trace.dat - * @handle: input handle for the trace.dat file - * @state: The state to read up to or zero to read up to options. - * - * This reads the trace.dat file for various information. Like the - * format of the ring buffer, event formats, ftrace formats, kallsyms - * and printk. This may be called multiple times with different @state - * values, to read partial data at a time. It will always continue - * where it left off. - */ -int tracecmd_read_headers(struct tracecmd_input *handle, - enum tracecmd_file_states state) +static int read_headers_v6(struct tracecmd_input *handle, enum tracecmd_file_states state) { int ret; @@ -1002,6 +989,134 @@ int tracecmd_read_headers(struct tracecmd_input *handle, return 0; } +static int handle_options(struct tracecmd_input *handle); + +static int read_section_header(struct tracecmd_input *handle, unsigned short *id, + unsigned short *flags, unsigned int *size, char **description) +{ + unsigned short fl; + char *desc = NULL; + unsigned short sec_id; + unsigned int sz; + + if (read2(handle, &sec_id)) + return -1; + desc = read_string(handle); + if (!desc) + return -1; + if (read2(handle, &fl)) + goto error; + if (read4(handle, &sz)) + goto error; + + if (id) + *id = sec_id; + if (flags) + *flags = fl; + if (size) + *size = sz; + if (description) + *description = desc; + else + free(desc); + return 0; + +error: + free(desc); + return -1; +} + +static int handle_section(struct tracecmd_input *handle, struct file_section *section) +{ + unsigned short id, flags; + unsigned int size; + int ret; + + if (lseek64(handle->fd, section->section_offset, SEEK_SET) == (off_t)-1) + return -1; + if (read_section_header(handle, &id, &flags, &size, NULL)) + return -1; + section->flags = flags; + if (id != section->id) + return -1; + + section->data_offset = lseek64(handle->fd, 0, SEEK_CUR); + + switch (section->id) { + case TRACECMD_OPTION_HEADER_INFO: + ret = read_header_files(handle); + break; + case TRACECMD_OPTION_FTRACE_EVENTS: + ret = read_ftrace_files(handle, NULL); + break; + case TRACECMD_OPTION_EVENT_FORMATS: + ret = read_event_files(handle, NULL); + break; + case TRACECMD_OPTION_KALLSYMS: + ret = read_proc_kallsyms(handle); + break; + case TRACECMD_OPTION_PRINTK: + ret = read_ftrace_printk(handle); + break; + case TRACECMD_OPTION_CMDLINES: + ret = read_and_parse_cmdlines(handle); + break; + default: + ret = 0; + break; + } + + return ret; +} + +static int read_headers_v7(struct tracecmd_input *handle) +{ + struct file_section *section; + + if (handle->options_init) + return 0; + + if (!handle->options_start) + return -1; + + if (lseek64(handle->fd, handle->options_start, SEEK_SET) == (off64_t)-1) { + tracecmd_warning("Filed to goto options offset %lld", handle->options_start); + return -1; + } + + if (handle_options(handle)) + return -1; + + section = handle->sections; + while (section) { + if (handle_section(handle, section)) + return -1; + section = section->next; + } + + handle->options_init = true; + return 0; +} + +/** + * tracecmd_read_headers - read the header information from trace.dat + * @handle: input handle for the trace.dat file + * @state: The state to read up to or zero to read up to options. + * + * This reads the trace.dat file for various information. Like the + * format of the ring buffer, event formats, ftrace formats, kallsyms + * and printk. This may be called multiple times with different @state + * values, to read partial data at a time. It will always continue + * where it left off. + */ +int tracecmd_read_headers(struct tracecmd_input *handle, + enum tracecmd_file_states state) +{ + if (!HAS_SECTIONS(handle)) + return read_headers_v6(handle, state); + return read_headers_v7(handle); +} + static unsigned long long calc_page_offset(struct tracecmd_input *handle, unsigned long long offset) { From patchwork Tue Sep 14 13:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493277 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 0281DC433FE for ; Tue, 14 Sep 2021 13:15:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E10DF610E6 for ; Tue, 14 Sep 2021 13:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233235AbhINNQX (ORCPT ); Tue, 14 Sep 2021 09:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbhINNQW (ORCPT ); Tue, 14 Sep 2021 09:16:22 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2426CC061574 for ; Tue, 14 Sep 2021 06:15:05 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso2064282wmb.2 for ; Tue, 14 Sep 2021 06:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pk5yii1uor0m9PDb3jjwY3FBwvwX0jb9UI4BGT2BEJE=; b=ERk74uyiqACwexjdOJ9vb3GyW9ceNSl2bF5zMXEzxGly+0zZeMzrx+lriJWCWrCoFf Ilzoy0gLnGyz12cXosWh4aUZ8pwZk202Cj3YOKUgW52YtB9Scy9jxAVOZUCCmOsotEWQ o4cDvryKtiH3lvrLr+h3ThSPvtr+gdZ4kiAiokUKEFxUh5JHLZwUJusYX8Q4LNZlZBiI 1UZUPVothsLlEKN1RkW9Mbkm6jPlNIUh2Bt1o5/kIN+GKehdJmjvVlDkMW2oA1TeH+o7 jr/mBym+NznkzBXuqVkL4jmwkHnDFciLgMB06M9qzbjPDSOCnqOYQfWEJihus5rhQoWY gkZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pk5yii1uor0m9PDb3jjwY3FBwvwX0jb9UI4BGT2BEJE=; b=E5K1Ni4FTo99YgdVFDsbq6VRhuQnc0HLJfHrP3ci8lZfi2IXkRt7zG3HEEnAIor8km C3NEsKYUNMMoz2SPhOq4MlPa43uLFKpVHyBla6at77RYtQZy6uy7dy50gGbT6uu+Evs6 ve8A6vAUvDb5Y8x1SfkgFP8idSsfo6vZQvMX2/y90ZPqV4eXQSjCMSfAr/9qFt91726/ BfD9cQT1IU5aCekPLLt/K6/V+jxltJG3hgR6XwHtp0vZe2yIFhJeInAvRgIYe8mDtp7P jxbMStBt1Wl6Q41AQXxSWYZIUTdyS4FoUQuCOSK5qQC7DT3Fg6KHA7+GspHi3TVqK/dE vpGQ== X-Gm-Message-State: AOAM5328Tpp916K9XDJxJykCQWDm+UZY99tlgO+qrAnyzWXpfbNux8Ad rDbiyoWsBXDjOR2g5t0NZjykWsKwsmc= X-Google-Smtp-Source: ABdhPJyaLHWEyq14zjYPd1YqrGzRZLU7DOGhI1SrIeQmaFlBbbItFUR3SjeekYbbtko7zUIKHdGSHw== X-Received: by 2002:a1c:1fd3:: with SMTP id f202mr2162694wmf.44.1631625303636; Tue, 14 Sep 2021 06:15:03 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:03 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 18/25] trace-cmd library: Read extended BUFFER option Date: Tue, 14 Sep 2021 16:14:31 +0300 Message-Id: <20210914131438.3965484-19-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The BUFFER option is extended in trace file version 7. It holds CPU metadata related to the recorded CPU traces. Also, there is a new BUFFER_TEXT option for describing the latency trace data. A new logic is implemented for these new options. In trace file version 7, the top buffer is saved as other buffers in the file, no special treatment. But saving the top buffer in the list of buffers in the input handler causes problems. It breaks the legacy logic of trace-cmd library users, which have special logic for trace buffers processing. That's why "top_buffer" member is added in the input handler structure, to hold the top buffer. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 139 +++++++++++++++++++++++++++++++----- 1 file changed, 122 insertions(+), 17 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 686655bd..914ec82d 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -74,9 +74,19 @@ struct cpu_data { int pipe_fd; }; +struct cpu_file_data { + int cpu; + unsigned long long offset; + unsigned long long size; +}; + struct input_buffer_instance { char *name; size_t offset; + char *clock; + bool latency; + int cpus; + struct cpu_file_data *cpu_data; }; struct ts_offset_sample { @@ -152,6 +162,7 @@ struct tracecmd_input { char * uname; char * version; char * trace_clock; + struct input_buffer_instance top_buffer; struct input_buffer_instance *buffers; int parsing_failures; struct guest_trace_info *guest; @@ -2860,13 +2871,109 @@ tracecmd_search_task_map(struct tracecmd_input *handle, return lib; } +static inline int save_read_number(struct tep_handle *tep, char *data, int *data_size, + int *read_pos, int bytes, unsigned long long *num) +{ + if (bytes > *data_size) + return -1; + *num = tep_read_number(tep, (data + *read_pos), bytes); + *read_pos += bytes; + *data_size -= bytes; + return 0; +} + +static inline char *save_read_string(char *data, int *data_size, int *read_pos) +{ + char *str; + + if (*data_size < 1) + return NULL; + str = strdup(data + *read_pos); + if (!str) + return NULL; + *data_size -= (strlen(str) + 1); + if (*data_size < 0) { + free(str); + return NULL; + } + *read_pos += (strlen(str) + 1); + + return str; +} + +static int handle_buffer_option(struct tracecmd_input *handle, + unsigned short id, char *data, int size) +{ + struct input_buffer_instance *buff; + unsigned long long tmp; + int rsize = 0; + char *name; + int i; + + if (save_read_number(handle->pevent, data, &size, &rsize, 8, &tmp)) + return -1; + name = save_read_string(data, &size, &rsize); + if (!name) + return -1; + + if (*name == '\0') { + /* top buffer */ + buff = &handle->top_buffer; + } else { + buff = realloc(handle->buffers, sizeof(*handle->buffers) * (handle->nr_buffers + 1)); + if (!buff) { + free(name); + return -1; + } + handle->buffers = buff; + handle->nr_buffers++; + + buff = &handle->buffers[handle->nr_buffers - 1]; + } + memset(buff, 0, sizeof(struct input_buffer_instance)); + buff->name = name; + buff->offset = tmp; + if (!HAS_SECTIONS(handle)) + return 0; + + /* file sections specific data */ + buff->clock = save_read_string(data, &size, &rsize); + if (!buff->clock) + return -1; + if (*name == '\0' && !handle->trace_clock) + handle->trace_clock = strdup(buff->clock); + if (id == TRACECMD_OPTION_BUFFER) { + if (save_read_number(handle->pevent, data, &size, &rsize, 4, &tmp)) + return -1; + buff->cpus = tmp; + if (!buff->cpus) + return 0; + buff->cpu_data = calloc(buff->cpus, sizeof(struct cpu_file_data)); + if (!buff->cpu_data) + return -1; + for (i = 0; i < buff->cpus; i++) { + if (save_read_number(handle->pevent, data, &size, &rsize, 4, &tmp)) + return -1; + buff->cpu_data[i].cpu = tmp; + if (save_read_number(handle->pevent, data, + &size, &rsize, 8, &buff->cpu_data[i].offset)) + return -1; + if (save_read_number(handle->pevent, data, + &size, &rsize, 8, &buff->cpu_data[i].size)) + return -1; + } + } else { + buff->latency = true; + } + return 0; +} + static int handle_options(struct tracecmd_input *handle) { long long offset; unsigned short option; unsigned int size; char *cpustats = NULL; - struct input_buffer_instance *buffer; struct hook_list *hook; char *buf; int cpus; @@ -2955,21 +3062,10 @@ static int handle_options(struct tracecmd_input *handle) handle->cpustats = cpustats; break; case TRACECMD_OPTION_BUFFER: - /* A buffer instance is saved at the end of the file */ - handle->nr_buffers++; - handle->buffers = realloc(handle->buffers, - sizeof(*handle->buffers) * handle->nr_buffers); - if (!handle->buffers) - return -ENOMEM; - buffer = &handle->buffers[handle->nr_buffers - 1]; - buffer->name = strdup(buf + 8); - if (!buffer->name) { - free(handle->buffers); - handle->buffers = NULL; - return -ENOMEM; - } - offset = *(unsigned long long *)buf; - buffer->offset = tep_read_number(handle->pevent, &offset, 8); + case TRACECMD_OPTION_BUFFER_TEXT: + ret = handle_buffer_option(handle, option, buf, size); + if (ret < 0) + return ret; break; case TRACECMD_OPTION_TRACECLOCK: if (!handle->ts2secs) @@ -3717,6 +3813,13 @@ void tracecmd_ref(struct tracecmd_input *handle) handle->ref++; } +static inline void free_buffer(struct input_buffer_instance *buf) +{ + free(buf->name); + free(buf->clock); + free(buf->cpu_data); +} + /** * tracecmd_close - close and free the trace.dat handle * @handle: input handle for the trace.dat file @@ -3772,8 +3875,9 @@ void tracecmd_close(struct tracecmd_input *handle) free(del_sec); } + free_buffer(&handle->top_buffer); for (i = 0; i < handle->nr_buffers; i++) - free(handle->buffers[i].name); + free_buffer(&handle->buffers[i]); free(handle->buffers); tracecmd_free_hooks(handle->hooks); @@ -4217,6 +4321,7 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) return NULL; *new_handle = *handle; + memset(&new_handle->top_buffer, 0, sizeof(new_handle->top_buffer)); new_handle->cpu_data = NULL; new_handle->nr_buffers = 0; new_handle->buffers = NULL; From patchwork Tue Sep 14 13:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493279 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 978FCC433F5 for ; Tue, 14 Sep 2021 13:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83C11610CE for ; Tue, 14 Sep 2021 13:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233135AbhINNQZ (ORCPT ); Tue, 14 Sep 2021 09:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbhINNQY (ORCPT ); Tue, 14 Sep 2021 09:16:24 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF4CDC061574 for ; Tue, 14 Sep 2021 06:15:06 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso2064318wmb.2 for ; Tue, 14 Sep 2021 06:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t5fYfiiAyArLxhJrdJsGVtZUrB+kCPqXH3IdaP3ulWQ=; b=FPR0HcmVomQr+0GhtmK1DeUwqQdbFRA/HDOJyGrXSHrS1FLXFZfiVB9JFa6faXU+xi JdIn/DsYGJz/xYxtqVaoQ30VC2zu1PmGK9fJ/Dtkf48ogOsSMJPjjSzqJ0MHNoSe83vT XJQHG2DODUZ/AEuQQSiQKaBRhavOu9pm75vz212Ax2dn7w7FEfzxUTErPMc0t6dN6aMC 0WP+j26jVv25dtHgKd1whnKVkZkNvy3ptcAXo8zzaUG+2IMfijWKQ6l497iSBxXyoncI SY6s/l7GWagWVZbuAPaujrUQYqrxpXcCp3SPYzyc3q/KDV+apMSkXYihIDHiUTJwLWLj +Gqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t5fYfiiAyArLxhJrdJsGVtZUrB+kCPqXH3IdaP3ulWQ=; b=sGfABhP2n8Ankr8h7Nsod8UYfK1Hgap6J3rGwnMeW8GbaSe7iY5dGpzOgNbJOyIxnE gfgHOI6bDfFk/eJDhwA2/1hOU091qV2cp0FAJXIUEhVhNPiBZlq05Y/5nS7cvJPCEI+W uTy5q8r6f5sLA2ADsOuHtTZv0pgdpeY/K/T4+OrPuWVUcjDfPPSYsbngVOY3hAVHO2qq PmQ+LnIA4iElNMm23b/puWqVoDLMFft3LNEYwkXeSPvhclfsa4jvHFWPIxWJwjXtL03P T4X2qhQ3hDlLjLsCgS/407YLV6knKEa41nk1o30BNtPphQr1l0zCRdT7pz/9IGDfg099 f7Sg== X-Gm-Message-State: AOAM5309DdnoukKqHrNz5rAmiDENu3zdkNSQeSHGqG7q40EyoosJxmts m0P3hzPuSO/d78r/BzuuaqppWSYM0DM= X-Google-Smtp-Source: ABdhPJxAi2DV0hwfiNmkT1w4qAKTo59Y2zwI3fVwWPLJdizSmREPWiSd72J9CeemdrOqJdVlI5B2YA== X-Received: by 2002:a1c:80c7:: with SMTP id b190mr2147988wmd.87.1631625304613; Tue, 14 Sep 2021 06:15:04 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:04 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 19/25] trace-cmd library: Handle the extended DONE option Date: Tue, 14 Sep 2021 16:14:32 +0300 Message-Id: <20210914131438.3965484-20-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7 the DONE option is extended to store the offset in the file to the next options section. This way a list of options sections can be stored in the file. Added logic to recursively read all option sections from the file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/trace-cmd-local.h | 1 + lib/trace-cmd/trace-input.c | 42 +++++++++++++++++++++++-- lib/trace-cmd/trace-output.c | 2 +- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index 405b7dae..b29236dc 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -49,5 +49,6 @@ struct cpu_data_source { int out_write_cpu_data(struct tracecmd_output *handle, int cpus, struct cpu_data_source *data, const char *buff_name); off64_t msg_lseek(struct tracecmd_msg_handle *msg_handle, off_t offset, int whence); +unsigned long long get_last_option_offset(struct tracecmd_input *handle); #endif /* _TRACE_CMD_LOCAL_H */ diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 914ec82d..d9ec9c73 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -175,6 +175,7 @@ struct tracecmd_input { struct file_section *sections; bool options_init; unsigned long long options_start; + unsigned long long options_last_offset; size_t total_file_size; /* For custom profilers. */ @@ -2871,6 +2872,30 @@ tracecmd_search_task_map(struct tracecmd_input *handle, return lib; } +__hidden unsigned long long get_last_option_offset(struct tracecmd_input *handle) +{ + return handle->options_last_offset; +} + +static int handle_option_done(struct tracecmd_input *handle, char *buf, int size) +{ + unsigned long long offset; + + if (size < 8) + return -1; + offset = lseek64(handle->fd, 0, SEEK_CUR); + if (offset >= size) + handle->options_last_offset = offset - size; + offset = tep_read_number(handle->pevent, buf, 8); + if (!offset) + return 0; + + if (lseek64(handle->fd, offset, SEEK_SET) == (off_t)-1) + return -1; + + return handle_options(handle); +} + static inline int save_read_number(struct tep_handle *tep, char *data, int *data_size, int *read_pos, int bytes, unsigned long long *num) { @@ -2973,19 +2998,27 @@ static int handle_options(struct tracecmd_input *handle) long long offset; unsigned short option; unsigned int size; + unsigned short id, flags; char *cpustats = NULL; struct hook_list *hook; char *buf; int cpus; int ret; - handle->options_start = lseek64(handle->fd, 0, SEEK_CUR); + if (!HAS_SECTIONS(handle)) { + handle->options_start = lseek64(handle->fd, 0, SEEK_CUR); + } else { + if (read_section_header(handle, &id, &flags, NULL, NULL)) + return -1; + if (id != TRACECMD_OPTION_DONE) + return -1; + } for (;;) { if (read2(handle, &option)) return -1; - if (option == TRACECMD_OPTION_DONE) + if (!HAS_SECTIONS(handle) && option == TRACECMD_OPTION_DONE) break; /* next 4 bytes is the size of the option */ @@ -3122,7 +3155,10 @@ static int handle_options(struct tracecmd_input *handle) section_add_or_update(handle, option, -1, tep_read_number(handle->pevent, buf, 8), 0); break; - + case TRACECMD_OPTION_DONE: + ret = handle_option_done(handle, buf, size); + free(buf); + return ret; default: tracecmd_warning("unknown option %d", option); break; diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 87b85e0f..b3904204 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2150,7 +2150,7 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) tep_ref(handle->pevent); handle->page_size = tracecmd_page_size(ihandle); handle->file_version = tracecmd_get_in_file_version(ihandle); - handle->options_start = tracecmd_get_options_offset(ihandle); + handle->options_start = get_last_option_offset(ihandle); list_head_init(&handle->options); list_head_init(&handle->buffers); From patchwork Tue Sep 14 13:14:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493281 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 C02B3C433EF for ; Tue, 14 Sep 2021 13:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2879610D1 for ; Tue, 14 Sep 2021 13:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233077AbhINNQZ (ORCPT ); Tue, 14 Sep 2021 09:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhINNQY (ORCPT ); Tue, 14 Sep 2021 09:16:24 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4166FC061760 for ; Tue, 14 Sep 2021 06:15:07 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id u16so20156342wrn.5 for ; Tue, 14 Sep 2021 06:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4k6UllQ6r51Rn/QF3Nuu+ooKQr2L/0+79bpAFfkplsY=; b=dn8phBRqv14OoU8sTT3jccSDmQSw/cnB8M/mb2N2fhoiL0ONbPJtMWh3oW/wbfxLCc l0ub5pzv4ze+XrdgCbKsnx8IEcjLpy6DeetH+Mcvbd6i/NWTD333Oge/omRTz/0b4ruz uaCK+lNrCaf9rmgYm2pTL+yGWJnkY32tOWTw6MmDeBs7RGdNziVeP5v4wmX2zIvmuAWB u9jXf5pPENIw50yXRQurQKY24c7W8zK3caVofL6PnnnS0VODm/+ho+vv4zKErMItDSza KVXU9z+gkxGjd8zKjGPSIo0BLjbBPK/KRNLDKFdaohoDtCWrh/8AklEpnnEpSj+Ao+ij riww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4k6UllQ6r51Rn/QF3Nuu+ooKQr2L/0+79bpAFfkplsY=; b=n2yRHk4fg5+vBW+r34pFGWIBC9rtzqyM/FyU4XBzCG9mN11uxj9nZx+r+/1stvrl8m FbPKc8jplsHzSLq8sz3HNY1JW+jvXL0dzxuZ0hNgFyigGlrWzPNurt07BtmKj0hKY/jN Nv1yOkILpYG3mab5LhCjW5lYdELHLcLA0EnVjmvR4BQjYdk9CgvfaMXbk0AjfKijUIKR ABftojETIjqPqB18x9j4HJmoin7sWEGD1xUcv8AoamO7FFYIbQrSZdOr2gbKDGsyuAoa K+he43V18e3AG7OT+W14AM4VTHjhKOG5dQ6Bi1+h99vMqBYXRtIfB/IRkDt5EmDOoo1i XYXQ== X-Gm-Message-State: AOAM530KQHvoPX23pYJTDs73tuLWJ6XWrBClibgTIIlLFeZte/wR1hNI IRDShR/V0dx1zUiY7PvnDFHN4V24cNk= X-Google-Smtp-Source: ABdhPJzFCaAMmDYA4bICYoP8HKJl26HSnaFaNMnq3V9CcgAMkq8I92rcwKyG6Mu2oCmfj25XBVQ+Ng== X-Received: by 2002:a05:6000:363:: with SMTP id f3mr18845157wrf.142.1631625305780; Tue, 14 Sep 2021 06:15:05 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:05 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 20/25] trace-cmd library: Initialize CPU data for reading from version 7 trace files Date: Tue, 14 Sep 2021 16:14:33 +0300 Message-Id: <20210914131438.3965484-21-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In version 7 trace files, CPU trace data is written in slightly different way than in version 6 files. Added new CPU data initialization flow, to handle version 7 files: - the top trace instance is saved in the same way as the other trace instances. - per CPU trace metadata is stored in the buffer option. - trace data section has section header. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 178 +++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 55 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index d9ec9c73..87c33423 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3203,34 +3203,18 @@ static int read_options_type(struct tracecmd_input *handle) return 0; } -static int read_cpu_data(struct tracecmd_input *handle) +static int init_cpu_data(struct tracecmd_input *handle) { - struct tep_handle *pevent = handle->pevent; enum kbuffer_long_size long_size; enum kbuffer_endian endian; - unsigned long long size; unsigned long long max_size = 0; unsigned long long pages; - int cpus; int cpu; - /* - * Check if this is a latency report or not. - */ - if (handle->file_state == TRACECMD_FILE_CPU_LATENCY) - return 1; - /* We expect this to be flyrecord */ if (handle->file_state != TRACECMD_FILE_CPU_FLYRECORD) return -1; - cpus = handle->cpus; - - handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus); - if (!handle->cpu_data) - return -1; - memset(handle->cpu_data, 0, sizeof(*handle->cpu_data) * handle->cpus); - if (force_read) handle->read_page = true; @@ -3245,32 +3229,14 @@ static int read_cpu_data(struct tracecmd_input *handle) endian = KBUFFER_ENDIAN_LITTLE; for (cpu = 0; cpu < handle->cpus; cpu++) { - unsigned long long offset; - - handle->cpu_data[cpu].cpu = cpu; - handle->cpu_data[cpu].kbuf = kbuffer_alloc(long_size, endian); if (!handle->cpu_data[cpu].kbuf) goto out_free; - if (tep_is_old_format(pevent)) + if (tep_is_old_format(handle->pevent)) kbuffer_set_old_format(handle->cpu_data[cpu].kbuf); - read8(handle, &offset); - read8(handle, &size); - - handle->cpu_data[cpu].file_offset = offset; - handle->cpu_data[cpu].file_size = size; - if (size > max_size) - max_size = size; - - if (size && (offset + size > handle->total_file_size)) { - /* this happens if the file got truncated */ - printf("File possibly truncated. " - "Need at least %llu, but file size is %zu.\n", - offset + size, handle->total_file_size); - errno = EINVAL; - goto out_free; - } + if (handle->cpu_data[cpu].file_size > max_size) + max_size = handle->cpu_data[cpu].file_size; } /* Calculate about a meg of pages for buffering */ @@ -3288,6 +3254,101 @@ static int read_cpu_data(struct tracecmd_input *handle) goto out_free; } + return 0; + + out_free: + for ( ; cpu >= 0; cpu--) { + free_page(handle, cpu); + kbuffer_free(handle->cpu_data[cpu].kbuf); + handle->cpu_data[cpu].kbuf = NULL; + } + return -1; +} + +static int init_buffer_cpu_data(struct tracecmd_input *handle, struct input_buffer_instance *buffer) +{ + unsigned long long offset; + unsigned long long size; + unsigned short id, flags; + int cpu; + + if (handle->cpu_data) + return -1; + + if (lseek64(handle->fd, buffer->offset, SEEK_SET) == (off_t)-1) + return -1; + if (read_section_header(handle, &id, &flags, NULL, NULL)) + return -1; + + handle->file_state = TRACECMD_FILE_CPU_FLYRECORD; + handle->cpus = buffer->cpus; + if (handle->max_cpu < handle->cpus) + handle->max_cpu = handle->cpus; + + handle->cpu_data = calloc(handle->cpus, sizeof(*handle->cpu_data)); + if (!handle->cpu_data) + return -1; + + for (cpu = 0; cpu < handle->cpus; cpu++) { + handle->cpu_data[cpu].cpu = buffer->cpu_data[cpu].cpu; + offset = buffer->cpu_data[cpu].offset; + size = buffer->cpu_data[cpu].size; + handle->cpu_data[cpu].file_offset = offset; + handle->cpu_data[cpu].file_size = size; + if (size && (offset + size > handle->total_file_size)) { + /* this happens if the file got truncated */ + printf("File possibly truncated. " + "Need at least %llu, but file size is %zu.\n", + offset + size, handle->total_file_size); + errno = EINVAL; + return -1; + } + } + + return init_cpu_data(handle); +} + +static int read_cpu_data(struct tracecmd_input *handle) +{ + unsigned long long size; + int cpus; + int cpu; + + /* + * Check if this is a latency report or not. + */ + if (handle->file_state == TRACECMD_FILE_CPU_LATENCY) + return 1; + + /* We expect this to be flyrecord */ + if (handle->file_state != TRACECMD_FILE_CPU_FLYRECORD) + return -1; + + cpus = handle->cpus; + + handle->cpu_data = malloc(sizeof(*handle->cpu_data) * handle->cpus); + if (!handle->cpu_data) + return -1; + memset(handle->cpu_data, 0, sizeof(*handle->cpu_data) * handle->cpus); + + for (cpu = 0; cpu < handle->cpus; cpu++) { + unsigned long long offset; + + handle->cpu_data[cpu].cpu = cpu; + read8(handle, &offset); + read8(handle, &size); + handle->cpu_data[cpu].file_offset = offset; + handle->cpu_data[cpu].file_size = size; + if (size && (offset + size > handle->total_file_size)) { + /* this happens if the file got truncated */ + printf("File possibly truncated. " + "Need at least %llu, but file size is %zu.\n", + offset + size, handle->total_file_size); + errno = EINVAL; + return -1; + } + } + /* * It is possible that an option changed the number of CPUs. * If that happened, then there's "empty" cpu data saved for @@ -3307,15 +3368,7 @@ static int read_cpu_data(struct tracecmd_input *handle) } } - return 0; - - out_free: - for ( ; cpu >= 0; cpu--) { - free_page(handle, cpu); - kbuffer_free(handle->cpu_data[cpu].kbuf); - handle->cpu_data[cpu].kbuf = NULL; - } - return -1; + return init_cpu_data(handle); } static int read_data_and_size(struct tracecmd_input *handle, @@ -3418,14 +3471,7 @@ static int read_and_parse_trace_clock(struct tracecmd_input *handle, return 0; } -/** - * tracecmd_init_data - prepare reading the data from trace.dat - * @handle: input handle for the trace.dat file - * - * This prepares reading the data from trace.dat. This is called - * after tracecmd_read_headers() and before tracecmd_read_data(). - */ -int tracecmd_init_data(struct tracecmd_input *handle) +static int init_data_v6(struct tracecmd_input *handle) { struct tep_handle *pevent = handle->pevent; int ret; @@ -3447,7 +3493,29 @@ int tracecmd_init_data(struct tracecmd_input *handle) tracecmd_parse_trace_clock(handle, clock, 8); } } + return ret; +} + +static int init_data_v7(struct tracecmd_input *handle) +{ + return init_buffer_cpu_data(handle, &handle->top_buffer); +} +/** + * tracecmd_init_data - prepare reading the data from trace.dat + * @handle: input handle for the trace.dat file + * + * This prepares reading the data from trace.dat. This is called + * after tracecmd_read_headers() and before tracecmd_read_data(). + */ +int tracecmd_init_data(struct tracecmd_input *handle) +{ + int ret; + + if (!HAS_SECTIONS(handle)) + ret = init_data_v6(handle); + else + ret = init_data_v7(handle); tracecmd_blk_hack(handle); return ret; From patchwork Tue Sep 14 13:14:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493283 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 05380C4332F for ; Tue, 14 Sep 2021 13:15:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3B1A610D1 for ; Tue, 14 Sep 2021 13:15:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233247AbhINNQ0 (ORCPT ); Tue, 14 Sep 2021 09:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbhINNQ0 (ORCPT ); Tue, 14 Sep 2021 09:16:26 -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 C3359C061574 for ; Tue, 14 Sep 2021 06:15:08 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d6so20139901wrc.11 for ; Tue, 14 Sep 2021 06:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lNiHFGAi6rFItmFwzhQM7pzcHo1dNW3NyHEcsDYYd/E=; b=HkX/qDd1YkLZu8byfaQdhcCr2C1NNyPWpz5IQeYPfMH6B2YqmBmZ+ZWhTBOQORxbfz bARL6MaSkbba1FqkWVOxEL1kMY85D1xTavLoVLi9zTg7YuMMPnzBsiSxDa/+u2LDi9Pw l+JUCrRzPk0ybAyMh6mAr5CURlCY335fsoW1W4a96tt1M4ZsOu/F3Z97Ue3DMBtTPVnH i4h6EndwLeJLUxRm3vumKesLXUiPZYz56jHU7+fkhPS89ShdhG9uIjZ0rnmrN5+jGsad 6QS2oVVd919d5PfoBGGfClC8ENA2A6q354freoZf5smM7kWRknu5nt2WJx0mWpiU7jzF 57fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lNiHFGAi6rFItmFwzhQM7pzcHo1dNW3NyHEcsDYYd/E=; b=cuafA8nde9fCApB3hB3yWYQh3jLse0bCTJLRfSoMG3AdDU6J4vYAMn+QvtD/9fSFVX RnSA1rPK9/T8WvawWx02K5m+FHP8S5Lhlr3y8SDty99etWDKFUkZR9zqjkHUt+YJKbq3 kGrOoTUh1hXKS3YxjaQeI/k8UsG/L7ZCP9bwlo3ocTJl+YYq5yF33GJoVBs0Aywu9IXK 8uj8zzrE2WAtfVy64D8+sphxkWi3a4X/rxWlQ/AevdwZdBW4OHGAGOqsXOwI6oBgXhqc 8TLhJW2ccsuLbNOjr4jj46QJHBj9V7hocTZ5Z23iXcA27AuzLIKrd8bqeOqQt+oD31vb kPdw== X-Gm-Message-State: AOAM531rOn1Prq5TqlfeY6sbMqeNFvchnFiy2Csvix/Nws0lNk7ywLfb t2u7PMGw8tjYnyf3UH/XGdAARFMWWUs= X-Google-Smtp-Source: ABdhPJzgBBBUnV4i3Eu1HY69SAJCuD29bQ1RwXXDicMQxARTIwwQnQX2wKz1m5yNdquVdgxAjw6mNg== X-Received: by 2002:a5d:4bc8:: with SMTP id l8mr19288416wrt.105.1631625307447; Tue, 14 Sep 2021 06:15:07 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:06 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 21/25] trace-cmd library: Handle latency trace in version 7 files Date: Tue, 14 Sep 2021 16:14:34 +0300 Message-Id: <20210914131438.3965484-22-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Latency trace data is saved the same was as flyrecord buffer data in trace files version 7. There is a BUFFER_TEXT option which holds the latency specific trace metadata and points to the section in the file with the trace data. A new API is added to read latency data: tracecmd_latency_data_read() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 5 +++- lib/trace-cmd/trace-input.c | 29 ++++++++++++++++++- lib/trace-cmd/trace-output.c | 5 +++- tracecmd/trace-record.c | 3 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index a08890df..045fd5a1 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -221,6 +221,8 @@ tracecmd_peek_data_ref(struct tracecmd_input *handle, int cpu) return rec; } +int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size); + struct tep_record * tracecmd_read_prev(struct tracecmd_input *handle, struct tep_record *record); @@ -295,7 +297,8 @@ int tracecmd_output_write_init(struct tracecmd_output *handler); int tracecmd_output_write_headers(struct tracecmd_output *handler, struct tracecmd_event_list *list); -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + int file_version); struct tracecmd_output *tracecmd_create_init_fd(int fd); struct tracecmd_output *tracecmd_create_init_file(const char *output_file); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 87c33423..1b4a4d6b 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3203,6 +3203,24 @@ static int read_options_type(struct tracecmd_input *handle) return 0; } +int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size) +{ + if (!handle || !buf || !size) + return -1; + if (handle->file_state != TRACECMD_FILE_CPU_LATENCY) + return -1; + + /* Read data from a file */ + if (!(*buf)) { + *size = BUFSIZ; + *buf = malloc(*size); + if (!(*buf)) + return -1; + } + + return do_read(handle, *buf, *size); +} + static int init_cpu_data(struct tracecmd_input *handle) { enum kbuffer_long_size long_size; @@ -3265,6 +3283,12 @@ static int init_cpu_data(struct tracecmd_input *handle) return -1; } +int init_latency_data(struct tracecmd_input *handle) +{ + /* To do */ + return 0; +} + static int init_buffer_cpu_data(struct tracecmd_input *handle, struct input_buffer_instance *buffer) { unsigned long long offset; @@ -3279,7 +3303,10 @@ static int init_buffer_cpu_data(struct tracecmd_input *handle, struct input_buff return -1; if (read_section_header(handle, &id, &flags, NULL, NULL)) return -1; - + if (buffer->latency) { + handle->file_state = TRACECMD_FILE_CPU_LATENCY; + return init_latency_data(handle) == 0 ? 1 : -1; + } handle->file_state = TRACECMD_FILE_CPU_FLYRECORD; handle->cpus = buffer->cpus; if (handle->max_cpu < handle->cpus) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index b3904204..645a8ab7 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1786,7 +1786,8 @@ out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name, return option; } -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + int file_version) { enum tracecmd_section_flags flags = 0; struct tracecmd_output *handle; @@ -1801,6 +1802,8 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in handle = tracecmd_output_allocate(fd); if (!handle) goto out_free; + if (file_version && tracecmd_output_set_version(handle, file_version)) + goto out_free; if (tracecmd_output_write_init(handle)) goto out_free; if (tracecmd_output_write_headers(handle, NULL)) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 879acb7c..af7f332c 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4505,7 +4505,8 @@ static void record_data(struct common_record_context *ctx) return; if (latency) { - handle = tracecmd_create_file_latency(ctx->output, local_cpu_count); + handle = tracecmd_create_file_latency(ctx->output, local_cpu_count, + ctx->file_version); tracecmd_set_quiet(handle, quiet); } else { if (!local_cpu_count) From patchwork Tue Sep 14 13:14:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493285 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 36337C433F5 for ; Tue, 14 Sep 2021 13:15:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20966610CE for ; Tue, 14 Sep 2021 13:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233181AbhINNQ1 (ORCPT ); Tue, 14 Sep 2021 09:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhINNQ1 (ORCPT ); Tue, 14 Sep 2021 09:16:27 -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 E0B04C061574 for ; Tue, 14 Sep 2021 06:15:09 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id q26so20142393wrc.7 for ; Tue, 14 Sep 2021 06:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0qAKbxtjAIFzjl3AZiA9q3wc6jSusXtRRz1WPI5jw/Y=; b=NOk8R/mHv/qcEYjcGOKJ5mgavaksIWuUpVwEMdJJqT6b7AdFiFCYIdceBMPQ235llC /LkxfxLRUOuNbsOXHByLPcLvSsnCSALpggVsQY70GbRbWQoSnxZt4lsfbOcO6UgFFdey +FZeuufnVY4h8kZJ3kf+hSVdxe9UBKR7KtGRAXPejCsrP/9Q7BpIKFR3cj3qn+2UQo+i 5NNDFz0kz9rrxWTn8MfI3o4zE7r/lWCWf8vtzDNpa0gKSZJjwzx1ax+eH02qu0QmSNfH fyicNwSD22suPe6xJUhoUPX7J+Qt1ApKGN9rWu/DS4vo4/P9vIAQhsCN3v7WBbm5mtAj +9mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0qAKbxtjAIFzjl3AZiA9q3wc6jSusXtRRz1WPI5jw/Y=; b=xn6WpVab5fdNS7/kvc68jwpowL0sVfuOqzixEunNL64SmgKFKIT33iUWRF5MQbKEmI 7Fkk6lZ/WGWyanWtK6M9vd27qYXDonZbEzYx48R54uLED8QcE4mNiX+mLZ594yGJ/yFp C/KoxSg10H/Kbu2JkrqXl6kChPgiuw0V7M+3rem4Cqe4R6IYkTvX+q9Y3VaYVOAuTggE hR7CjrWgnPeOXIV/4aeznsm/pYkfBbBmfUNEeWQE13daxFp72aohMzq1ELhJD0J4STOZ cBwMTAmWTYZUcEmIsD/N2xNyM868LKhAb5+ufgH/C5LFjgkY0iwx//3jQLr5Y7x42j6l i7oA== X-Gm-Message-State: AOAM5318IQmavG41nCCYCJxfvdLc9M6yljgKte7t64viymvicdMO1uNc SOSdnO0i6I8M6pu4/dZpscffKUWnzVo= X-Google-Smtp-Source: ABdhPJyccK+zTcdeo9mAScRI+ClI5LcbIxqgLZymrY3tg8MdTkcDo9yWO+HM6eMEECTjZw2RyLIqUA== X-Received: by 2002:a5d:5408:: with SMTP id g8mr18996378wrv.34.1631625308511; Tue, 14 Sep 2021 06:15:08 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:08 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 22/25] trace-cmd library: Handle buffer trace data init for version 7 files Date: Tue, 14 Sep 2021 16:14:35 +0300 Message-Id: <20210914131438.3965484-23-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org CPU data initialization is different for trace files version 6 and 7. When a new input handler to trace buffer is created, initialize the CPU data according to the file version. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 55 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 1b4a4d6b..222b9c89 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -4481,34 +4481,37 @@ tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx) new_handle->flags |= TRACECMD_FL_BUFFER_INSTANCE; new_handle->pid_maps = NULL; + if (!HAS_SECTIONS(handle)) { + /* Save where we currently are */ + offset = lseek64(handle->fd, 0, SEEK_CUR); - /* Save where we currently are */ - offset = lseek64(handle->fd, 0, SEEK_CUR); - - ret = lseek64(handle->fd, buffer->offset, SEEK_SET); - if (ret < 0) { - tracecmd_warning("could not seek to buffer %s offset %ld\n", - buffer->name, buffer->offset); - goto error; - } - - /* - * read_options_type() is called right after the CPU count so update - * file state accordingly. - */ - new_handle->file_state = TRACECMD_FILE_CPU_COUNT; - ret = read_options_type(new_handle); - if (!ret) - ret = read_cpu_data(new_handle); - if (ret < 0) { - tracecmd_warning("failed to read sub buffer %s\n", buffer->name); - goto error; - } + ret = lseek64(handle->fd, buffer->offset, SEEK_SET); + if (ret == (off64_t)-1) { + tracecmd_warning("could not seek to buffer %s offset %ld\n", + buffer->name, buffer->offset); + goto error; + } + /* + * read_options_type() is called right after the CPU count so update + * file state accordingly. + */ + new_handle->file_state = TRACECMD_FILE_CPU_COUNT; + ret = read_options_type(new_handle); + if (!ret) + ret = read_cpu_data(new_handle); - ret = lseek64(handle->fd, offset, SEEK_SET); - if (ret < 0) { - tracecmd_warning("could not seek to back to offset %ld\n", offset); - goto error; + if (ret < 0) { + tracecmd_warning("failed to read sub buffer %s\n", buffer->name); + goto error; + } + ret = lseek64(handle->fd, offset, SEEK_SET); + if (ret < 0) { + tracecmd_warning("could not seek to back to offset %ld\n", offset); + goto error; + } + } else { + if (init_buffer_cpu_data(new_handle, buffer) < 0) + goto error; } return new_handle; From patchwork Tue Sep 14 13:14:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493287 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=-12.9 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,UNWANTED_LANGUAGE_BODY, 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 662C6C433FE for ; Tue, 14 Sep 2021 13:15:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ED97610E6 for ; Tue, 14 Sep 2021 13:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233199AbhINNQ2 (ORCPT ); Tue, 14 Sep 2021 09:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbhINNQ2 (ORCPT ); Tue, 14 Sep 2021 09:16:28 -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 0DC9AC061574 for ; Tue, 14 Sep 2021 06:15:11 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id g16so20192732wrb.3 for ; Tue, 14 Sep 2021 06:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3tPykFm2R2AzWLPxwlstSRNlrsQRpaeRcBxHgbq+Eck=; b=RctipOVnAUP+9V7fYfAOBcUeLNiynBoIllWnwF6lsB+jAMjdYHAIabx0fqS7fNCjnx omR/47z1WE4H/2Pv0dy701THvdqNOkPDo0lbFfsgGtZRVRdmIR2jFOjPW7TCpddI1D8u wVkbQ7TlL2qL7vd4gIcI6akdyqf7BJgciuJt0jBL5ZsYsaH+gYtMKGebYkoVT2/5S+/v 6jMamebR4T2jNnEKycYca45aKWgeXmQrr1CcRL+ZI0lbllBvhPkAwKE0wJidvwOPwJng OopxaiT8lsOERaTU4iVeFnhCZo4eJs8S5hsCw0U+EZsIiWMsdv+zkGFAuRKNSFJlOvA+ Z2Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3tPykFm2R2AzWLPxwlstSRNlrsQRpaeRcBxHgbq+Eck=; b=GZXMxM8buXtb4KGbdz4ZDYNry+xSKNhZpeelJYBvC1LrGy8eFKW2vozaiVwPHGAUkE EBlMxNN1JavG06lu7/NXz9B8uG9UUgLoDOwAkRnM9TmiBRsCCu34gfSe9fgFucOyDZyA 8Mhx0mlDxVpg7zjkFATYGH6I49/7x1hJGQTS67KIX8FHdR4m7C61jw0QZO6Qwa+iDJ1h IjwI4hEtA9vGISg637+jflHSEuOMjBrSqhYKiGurm/rJx7G5Ay9sxef+lAT1E675JNAq fiEts/KgcdYRhW/gwq04LgiHvZl22A6u8mXIET9pbIkNf9jLnmt4ZwTrHx1mJGnAbiIK 92jw== X-Gm-Message-State: AOAM5325L2C78IMAi26tiYWQlSkFPErfTQDjvsxd14hAq9nmSp9hWxLB qZ4bfG5l3ADNybhWezNyzkxc9N2G8SU= X-Google-Smtp-Source: ABdhPJyEmANJqVxuxvOiu5jEfbvT7HO8qzBK2dxrghBzIRI2VsscA+wf1E+vrlIYeKWttD2TrPu0hg== X-Received: by 2002:adf:d1b2:: with SMTP id w18mr19406251wrc.6.1631625309586; Tue, 14 Sep 2021 06:15:09 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:09 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 23/25] trace-cmd report: Use the new latency API to read data Date: Tue, 14 Sep 2021 16:14:36 +0300 Message-Id: <20210914131438.3965484-24-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading latency trace data, use the new API tracecmd_latency_data_read() It handles reading latency trace data from both version 6 and 7 trace files. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-read.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index f7ffb89e..cafceffe 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -948,18 +948,20 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record) printf("\n"); } -static void read_rest(void) +static void read_latency(struct tracecmd_input *handle) { - char buf[BUFSIZ + 1]; + char *buf = NULL; + size_t size = 0; int r; do { - r = read(input_fd, buf, BUFSIZ); - if (r > 0) { - buf[r] = 0; - printf("%s", buf); - } + r = tracecmd_latency_data_read(handle, &buf, &size); + if (r > 0) + printf("%.*s", r, buf); } while (r > 0); + + printf("\n"); + free(buf); } static int @@ -1243,7 +1245,7 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype if (ret > 0) { if (multi_inputs) die("latency traces do not work with multiple inputs"); - read_rest(); + read_latency(handles->handle); return; } From patchwork Tue Sep 14 13:14:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493289 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 813B9C433EF for ; Tue, 14 Sep 2021 13:15:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BCBC610CE for ; Tue, 14 Sep 2021 13:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbhINNQc (ORCPT ); Tue, 14 Sep 2021 09:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhINNQa (ORCPT ); Tue, 14 Sep 2021 09:16:30 -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 B6A04C061574 for ; Tue, 14 Sep 2021 06:15:12 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id u15so14099904wru.6 for ; Tue, 14 Sep 2021 06:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=03pkaD3PStP0fZOQqnALHuGm44wpLKhfVZ0L3E+wbpo=; b=LTjI3fWR7Iv+I3LHwqzQgknKc37hXQoVfv1kp8UG9vlD+yDEozNR8/CZNXRY1hvyXE muuQk/aeaDur0ZHaYjR10K4Gar9afYx3Hv6fJWgTi+iiwfZdXUgb4SkSnH0p57fJcxf1 nAqWQBKt7enS+IoFbA6P4R9dOVKYGKGqLdzHfl2E+xBYAQec+KSYhb6nGF3omLVpj0AX DLNa82J3GlpalSU3oMs5UxD9yB8VTZGE4HHu6zcxhNzj0zJ+hWqXX1Ocld5DWmVBDbqQ jtchDjE1Pz38OdZAYM1yn5LYiw6/hLiEYVvFBYF7Zetbp7gIDPymZgexa+BESPh8jI/G L3/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=03pkaD3PStP0fZOQqnALHuGm44wpLKhfVZ0L3E+wbpo=; b=lNFbQEeoRy0ZIxX+Z+F+MpPLjx+Omz4UIAgEBZjg4yDHjuFXRs9J52IoZq4IOFzsDY daVrEBoHD0CGQv4D/TCz7tDgCNZBh191ELNhsX6894sU/uN1vhN4AOQUepSoapTClCDo Y+FOFsA+TzR/VRBCk8OrVW8eL2gFGJEE7YPVrDuDKfBSu9tDZHcNHVDyitk8Rc8Yjxgq heHKZ2cRsJQJXBUMNVPmcohvTjf1eBoQA0dAoJMMTJEnLebbdaCBk9QuMF3DybgkSTST SzBUa3bfm4yQlV7fWFfAkskOvh2YCqInTzf9Yu0cq1r4OBn1pU+BCUs2+9pxlhJLQShg kR9g== X-Gm-Message-State: AOAM531FofamRpIEYNPcAvSlprcspg499dFmGc1Y8lbRTT5OnpbnUa+e bOptMRDSjjcPubuNcUkSH817vW0hqF4= X-Google-Smtp-Source: ABdhPJzCWC6bvRUmKxqpHNqGRFcV6dqN6roC3H+izA2CVlfnuppE2EJ69kzYHMnPtzBsQR3BIlhAIA== X-Received: by 2002:adf:9f14:: with SMTP id l20mr18926313wrf.427.1631625311266; Tue, 14 Sep 2021 06:15:11 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:10 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 24/25] trace-cmd: Call additional APIs when creating trace file Date: Tue, 14 Sep 2021 16:14:37 +0300 Message-Id: <20210914131438.3965484-25-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When creating a trace file, two more APIs should be called, compared to the old flow: - tracecmd_write_buffer_info(), to write version 6 buffers metadata in the file. - tracecmd_write_options() after the trace data is written, for version 7 trace files, as the buffer metadata is appended to the options at the end. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-listen.c | 6 ++++++ tracecmd/trace-record.c | 4 ++++ tracecmd/trace-restore.c | 3 ++- tracecmd/trace-split.c | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index d812145b..fa04c6da 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -604,6 +604,9 @@ static int put_together_file(int cpus, int ofd, const char *node, if (write_options) { ret = tracecmd_write_cpus(handle, cpus); + if (ret) + goto out; + ret = tracecmd_write_buffer_info(handle); if (ret) goto out; ret = tracecmd_write_options(handle); @@ -612,6 +615,9 @@ static int put_together_file(int cpus, int ofd, const char *node, } ret = tracecmd_write_cpu_data(handle, cpus, temp_files, ""); + if (!ret && tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS) + tracecmd_write_options(handle); + out: tracecmd_output_close(handle); for (cpu--; cpu >= 0; cpu--) { diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index af7f332c..f94eee6f 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3729,6 +3729,9 @@ setup_connection(struct buffer_instance *instance, struct common_record_context if (ret) goto error; ret = tracecmd_write_cpus(network_handle, instance->cpu_count); + if (ret) + goto error; + ret = tracecmd_write_buffer_info(network_handle); if (ret) goto error; ret = tracecmd_write_options(network_handle); @@ -4092,6 +4095,7 @@ static void setup_agent(struct buffer_instance *instance, add_options(network_handle, ctx); tracecmd_write_cmdlines(network_handle); tracecmd_write_cpus(network_handle, instance->cpu_count); + tracecmd_write_buffer_info(network_handle); tracecmd_write_options(network_handle); tracecmd_msg_finish_sending_data(instance->msg_handle); instance->network_handle = network_handle; diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c index 8d2fcae8..a903c21a 100644 --- a/tracecmd/trace-restore.c +++ b/tracecmd/trace-restore.c @@ -163,6 +163,7 @@ void trace_restore (int argc, char **argv) if (tracecmd_append_cpu_data(handle, args, &argv[first_arg]) < 0) die("failed to append data"); - + if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS) + tracecmd_write_options(handle); return; } diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index e4a0c3b3..671d6e9f 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -391,6 +391,9 @@ static double parse_file(struct tracecmd_input *handle, if (tracecmd_append_cpu_data(ohandle, cpus, cpu_list) < 0) die("Failed to append tracing data\n"); + if (tracecmd_get_out_file_version(ohandle) >= FILE_VERSION_SECTIONS) + tracecmd_write_options(ohandle); + current = end; for (cpu = 0; cpu < cpus; cpu++) { /* Set the tracecmd cursor to the next set of records */ From patchwork Tue Sep 14 13:14:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12493291 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 6A6A5C433F5 for ; Tue, 14 Sep 2021 13:15:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53D70610D1 for ; Tue, 14 Sep 2021 13:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbhINNQc (ORCPT ); Tue, 14 Sep 2021 09:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233206AbhINNQb (ORCPT ); Tue, 14 Sep 2021 09:16:31 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D77C061760 for ; Tue, 14 Sep 2021 06:15:13 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id e26so9250252wmk.2 for ; Tue, 14 Sep 2021 06:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=toMN7Gy7qiKlHDx5qzo4dMJk80onCA4nB44Bg+SUiec=; b=LUjOPrWrz+8C8C5Y+9Lp/KnOyICDEyzf7tMLHr6aJqTZ1jPFNGrCc3MWJI4joB/aK/ oU26rXX+1/fZjFDOCqRvUUM3VeK734AVNZ+P2ArXqhzvT4cx1FNVI0kTQCpaFHoUAMX7 c5O/UXW0BVn0evppayHxAOYAcRq0HYR7iP7AC/cboNbW+Wr4+uC64JlpLsOIyDnzR5zw VTMppxmD3buWrg1vdPrJA7DMF9QOZfMaV4hwr/Qg5APiaGTazR4Fbgxe15CEO4gs7Nmx xn9T2ldq9/zpo52o7oOF/WP1xTDLOS75zk3MRRsPWDD/tgS4sKy6YAvlxdVE5hJyevvD tl1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=toMN7Gy7qiKlHDx5qzo4dMJk80onCA4nB44Bg+SUiec=; b=kyBmFeXtZfSCt4PjtEJAyuwbBdXH2er5PIDt1C74licG79rilvhWyDHB0fdnfvKnn3 8INdjtIvhm9/WJIaHaNNGT99QOYATHTT+vNjU5AmvIvgTJVUJG7d91k0+T7vEFjdtNcJ /Y52/at30uO4s6QIdtD+LlcBqF8j5ZK+H4uQNY41qvWEjmoEr9wSc2t0LawNvQx+iW3y hguTL/UUYZAWOvcq37F5HqA+mRPnebqOaXAqBpXS0CV0UX0jCFXDvl2nKSTGL9jhyEXa TR3r+w2e/V7rHrka8zIZGa32NPGwhL/maLMMfYEdxST6qJ0LCPmHYpJO2MrSAJ47s9ZF ll8A== X-Gm-Message-State: AOAM530cxUkmESP4pHcPdmbS7XgqWnQfSwohPfSCtXiqTS8LncXSZcce ZV91Uj0eFg95JIAu9Gil9TlvxYuuOpg= X-Google-Smtp-Source: ABdhPJwgaiTVGPlEv31zdM4djaU4lYhLoHTgGhV7LxNYEG/uLeEKH+0ujepmWI76CfxqWcX1LPG4VQ== X-Received: by 2002:a7b:c771:: with SMTP id x17mr2111652wmk.131.1631625312455; Tue, 14 Sep 2021 06:15:12 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id y9sm1274760wmj.36.2021.09.14.06.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 06:15:11 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v3 25/25] trace-cmd report: Add new parameter for trace file version Date: Tue, 14 Sep 2021 16:14:38 +0300 Message-Id: <20210914131438.3965484-26-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914131438.3965484-1-tz.stoyanov@gmail.com> References: <20210914131438.3965484-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org By default, "trace-cmd report" writes in trace file version 6. A new parameter is added, which can be used to set desired version the output trace file. "trace-cmd report --file-version " Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 21 +++++++++++++++++++++ tracecmd/trace-usage.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index f94eee6f..421bb7d4 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3698,6 +3698,8 @@ static struct tracecmd_output *create_net_output(struct common_record_context *c out = tracecmd_output_allocate(-1); if (!out) return NULL; + if (ctx->file_version && tracecmd_output_set_version(out, ctx->file_version)) + goto error; if (tracecmd_output_set_msg(out, msg_handle)) goto error; if (tracecmd_output_write_headers(out, listed_events)) @@ -3744,6 +3746,8 @@ setup_connection(struct buffer_instance *instance, struct common_record_context network_handle = tracecmd_output_allocate(msg_handle->fd); if (!network_handle) goto error; + if (tracecmd_output_set_version(network_handle, ctx->file_version)) + goto error; if (tracecmd_output_write_headers(network_handle, listed_events)) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -4475,6 +4479,8 @@ static struct tracecmd_output *create_output(struct common_record_context *ctx) out = tracecmd_output_allocate(fd); if (!out) goto error; + if (ctx->file_version && tracecmd_output_set_version(out, ctx->file_version)) + goto error; if (tracecmd_output_write_headers(out, listed_events)) goto error; return out; @@ -5785,6 +5791,7 @@ void init_top_instance(void) } enum { + OPT_file_ver = 238, OPT_verbose = 239, OPT_tsc2nsec = 240, OPT_fork = 241, @@ -6224,6 +6231,7 @@ static void parse_record_options(int argc, {"tsc2nsec", no_argument, NULL, OPT_tsc2nsec}, {"poll", no_argument, NULL, OPT_poll}, {"verbose", optional_argument, NULL, OPT_verbose}, + {"file-version", required_argument, NULL, OPT_file_ver}, {NULL, 0, NULL, 0} }; @@ -6649,6 +6657,19 @@ static void parse_record_options(int argc, cmd_check_die(ctx, CMD_set, *(argv+1), "--poll"); recorder_flags |= TRACECMD_RECORD_POLL; break; + case OPT_file_ver: + cmd_check_die(ctx, CMD_start, *(argv+1), "--file_version"); + cmd_check_die(ctx, CMD_set, *(argv+1), "--file_version"); + cmd_check_die(ctx, CMD_extract, *(argv+1), "--file_version"); + cmd_check_die(ctx, CMD_stream, *(argv+1), "--file_version"); + cmd_check_die(ctx, CMD_profile, *(argv+1), "--file_version"); + ctx->file_version = atoi(optarg); + if (ctx->file_version < FILE_VERSION_MIN || + ctx->file_version > FILE_VERSION_MAX) + die("Unsupported file version %d, " + "supported versions are from %d to %d", + ctx->file_version, FILE_VERSION_MIN, FILE_VERSION_MAX); + break; case OPT_quiet: case 'q': quiet = true; diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 32b38bfd..ac12b066 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -69,7 +69,7 @@ static struct usage_help usage_help[] = { " If 0 is specified, no loop is performed - timestamps offset is calculated only twice," " at the beginnig and at the end of the trace\n" " --poll don't block while reading from the trace buffer\n" - " --verbose 'level' Set the desired log level\n" + " --file-version set the desired trace file version\n" }, { "set",