From patchwork Thu Nov 11 15:08:40 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: 12615031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8FF3C433EF for ; Thu, 11 Nov 2021 15:08:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A497C61252 for ; Thu, 11 Nov 2021 15:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233833AbhKKPLd (ORCPT ); Thu, 11 Nov 2021 10:11:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233810AbhKKPLc (ORCPT ); Thu, 11 Nov 2021 10:11:32 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F305C061766 for ; Thu, 11 Nov 2021 07:08:43 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id v11so25437500edc.9 for ; Thu, 11 Nov 2021 07:08:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QXQ5Y7LspDwj7wkzhT67NpKvi1WnCdTUt6QhhLF6Hk4=; b=gJ6BVEOea4AltqHJJuu0zGE7ZXFwOA21lmul4sYShNTZdWIdhoKnW5Cx35LhQ1xuZg FEeN7WXvGD1AVQrVVh5KW+Z9Sp6pO43Kc5++QJ4xrqEF1N25DgZZ2UDE022BQk8OObB5 E2Z/IIOQjG+mX9DwBU5WKR+DAbh3FQuW21OXN0nHdLGKx1puyfXdVYkNj1l5Mx232x1R JvSqXinMh6/2qLMoDsxANgi/77gpYRdnz9MU4lDOF8DejxenE/gUUKKJGDPKn69UO+SE Gxu3VxGSXgIXM+9IiDqrVjBZkb3cRvzs+MxZZoKnU8I1zdJ7VXVycyyo/PITw7/L4Dst vBEw== 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:mime-version :content-transfer-encoding; bh=QXQ5Y7LspDwj7wkzhT67NpKvi1WnCdTUt6QhhLF6Hk4=; b=lyucPZImjlQSNi2lOXAG5n5+p1uTBMJlUtuKRo8nYkhbrblim7JJNmjcU2P6t52APc NtrmpRmqCbBIXXrP2PJW6ofboyh8qfoythPe/I4/IXllmvJ60kzCApfC3kzbhsNRjQuj Pmfxe+3IycdR0BoBNPIaakEYYrKO61qxg3DznAqj9T7aomGTlJg31srQpUV6RmolFaeD JkVxKvauL6y6sbOqxWmmyYgH+o9qMHQhu2fGCNp03xjBPV5HZ/OLcAyqP+2ltqYmcmMK EGQN9tC9b+zlrVrWPOQNJlaJmdQEd1y5lO13Corm41+3/142CiiqoE4EbLyd/5eJL/59 mCQQ== X-Gm-Message-State: AOAM5318MCKmB/KqBR5j9zqipK3qMlrXc5dXWm+ZJzk24V0Q4rH8rN94 MLOEmHEDycSzPj3Yol2wPWjOWoWUYvuaQg== X-Google-Smtp-Source: ABdhPJwvax1up8SzFMzabHtIgnoxgTsXxwi9b8AE3GTIILXuWnoKRxkmHUqCi/SB9rPJ/Q7SHFZslg== X-Received: by 2002:a05:6402:518f:: with SMTP id q15mr10672810edd.77.1636643321958; Thu, 11 Nov 2021 07:08:41 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id h10sm1746465edb.59.2021.11.11.07.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:08:41 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 01/25] trace-cmd library: Define trace file version 7 Date: Thu, 11 Nov 2021 17:08:40 +0200 Message-Id: <20211111150840.86532-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 767a63ab..02194749 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 a0d6f0a6..a025c0fa 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 6272c0f8..ea7075a6 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -83,6 +83,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(); handle->big_endian = tracecmd_host_bigendian(); diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 3b2d40ee..9c0f047b 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 3a84e116..757dab0f 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 Thu Nov 11 15:08:47 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: 12615033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5360C433EF for ; Thu, 11 Nov 2021 15:08:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7EEB610D0 for ; Thu, 11 Nov 2021 15:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233870AbhKKPLk (ORCPT ); Thu, 11 Nov 2021 10:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233810AbhKKPLj (ORCPT ); Thu, 11 Nov 2021 10:11:39 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49AE9C061766 for ; Thu, 11 Nov 2021 07:08:50 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id x15so25476063edv.1 for ; Thu, 11 Nov 2021 07:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yLRabWk7Gj40sl6+i6takOhYD5WAL9J2N5tk2j4UeWc=; b=m0E6FcJZYSggG6PSqLPSikyBBb/iVrHy2B4w5wHtYkO3IyIbe8kgSpJlgQaP+J2Myl q9jTLFrUHC6rW9Md6KngFfALhcgTBwhVB+WY+/67Czfkvm+76r2i/udWv8ygqRDLWh/P GEoUj0F2IfIAtwz+hadW3iPMBHKDey9fT5HKLTQqEu0wHNe54l/KReoh/VLUy3hyFlMq jEuxpt0uUP9yR7exLwRAviPh9LHeaV+B7DDjxhD4DMFYzSFyT0+mEgcLWntZIPY2NLW1 DIertMo9XtI8deIOygKxPIuS6j08aTtWTwUuVdIy+HpKf4UM4G/K2M1zL9RFwAG4XabN fjVg== 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:mime-version :content-transfer-encoding; bh=yLRabWk7Gj40sl6+i6takOhYD5WAL9J2N5tk2j4UeWc=; b=hsXDy3kp9rvqlbZIDAl2UiQnva7Tu4KTp3tI9Ndwu/cJ93Gxbv/lMhHQMxL4VWL7i0 7p67H0qTXDI0OB+GnEO3j7swt1G9u0LREyPdTW+umS15K82wSCindyJq0zfLsS2eoCc7 JIQpqxd2N8qTJrYsrwj4CvqHFlikp9Nk3R6jSZmvDI42yXs30TqS2Eon0X5bvapYDqa+ 5jNTuNAaWD13DD6DxFFF5cKw1gqPC+WtE+LmTDRzS1DL+J62Di+VfD0r9yV+WZ/aew0Z 0jWoemJm37Paw4/MCj9qFX3DiUwr1sS8XI8fdGb5WbCFNS7xcxCmMUscx+pM085XsW6o GCpg== X-Gm-Message-State: AOAM532nTkcrq2QwikBfroA7rZMa84eVdG9YDD7UydmZ9ksb9p/fvCRZ bwndz9LDtHjkbyLwV58dvHsZcyBZTqp+uw== X-Google-Smtp-Source: ABdhPJxq1XnKFwCwCrTLF4naMdhEKLEtJqw10Sp6+TdrFjEf5jhrKFO1wkxcT9ng4PNiTcVdVmJojw== X-Received: by 2002:a17:907:9056:: with SMTP id az22mr10174090ejc.107.1636643328734; Thu, 11 Nov 2021 07:08:48 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id sa3sm1445000ejc.113.2021.11.11.07.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:08:48 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 02/25] trace-cmd library: Add cache functionality to network message handler Date: Thu, 11 Nov 2021 17:08:47 +0200 Message-Id: <20211111150847.86549-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 02194749..47a30246 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 a025c0fa..d65ff599 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -45,5 +45,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 ea7075a6..b43f9e47 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -94,6 +94,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) @@ -953,6 +961,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; } @@ -1268,7 +1279,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)) @@ -1301,9 +1312,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; @@ -1321,7 +1332,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)) @@ -1518,10 +1529,10 @@ static int update_buffer_cpu_offset(struct tracecmd_output *handle, 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; } @@ -1530,7 +1541,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; } @@ -1579,7 +1590,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; @@ -1594,10 +1605,10 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, * updated them with the correct data later. */ endian8 = 0; - data_files[i].file_data_offset = lseek64(handle->fd, 0, SEEK_CUR); + data_files[i].file_data_offset = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, &endian8, 8)) goto out_free; - data_files[i].file_write_size = lseek64(handle->fd, 0, SEEK_CUR); + data_files[i].file_write_size = do_lseek(handle, 0, SEEK_CUR); if (do_write_check(handle, &endian8, 8)) goto out_free; } @@ -1608,12 +1619,12 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, 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 += handle->page_size - 1; data_files[i].data_offset &= ~(handle->page_size - 1); - ret = lseek64(handle->fd, data_files[i].data_offset, SEEK_SET); + ret = do_lseek(handle, data_files[i].data_offset, SEEK_SET); if (ret == (off64_t)-1) goto out_free; @@ -1637,21 +1648,21 @@ __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].file_data_offset, SEEK_SET) == (off64_t)-1) + if (do_lseek(handle, data_files[i].file_data_offset, 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].file_write_size, SEEK_SET) == (off64_t)-1) + if (do_lseek(handle, data_files[i].file_write_size, 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)) @@ -1660,7 +1671,7 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, } free(data_files); - if (lseek64(handle->fd, 0, SEEK_END) == (off64_t)-1) + if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) return -1; handle->file_state = TRACECMD_FILE_CPU_FLYRECORD; @@ -1668,7 +1679,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 Thu Nov 11 15:08:53 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: 12615035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3278CC433EF for ; Thu, 11 Nov 2021 15:09:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BDDF61252 for ; Thu, 11 Nov 2021 15:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233942AbhKKPLv (ORCPT ); Thu, 11 Nov 2021 10:11:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbhKKPLr (ORCPT ); Thu, 11 Nov 2021 10:11:47 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6800C0613F5 for ; Thu, 11 Nov 2021 07:08:57 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id t18so5986607edd.8 for ; Thu, 11 Nov 2021 07:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J4Sa2loNC2J5Dn1F+0UFcuFjZX019rFzMn8JNOgtKYE=; b=MlWjh7VH+3ryBh4gQP78ChjN58fLL+dsGq+UVPO8DlZuzJIRi7D6LPm7p1JAjHkOiE zBBMovglhJQ82iXcOzH1H1pd6eT6I1xGDhQc5xqAoVltbLNy2gqGFDGZFCUY1lK6MPHx gYfEMkBRckWoGJKsad7ObF7awVaqqJm4yOMOjROXXw1b4Hcp1xihplD0woehDAg4mrcU 6YwaseZvH/1/hiRa0XdqaeOU5ll4CoASpgzpHkS45rh74SH2wofnDFotqtCM/SJ/nkqu pkkTS78HjFNP1/J8b2dQrrUCll87oJgNp3px8c7E8OcpnEJ58RB+GEX25pGSkuZVvbAe P+BQ== 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:mime-version :content-transfer-encoding; bh=J4Sa2loNC2J5Dn1F+0UFcuFjZX019rFzMn8JNOgtKYE=; b=xUV2tug++j6B66E0oSB5J4EnAikfW3bC3Fjw9Xf/21QCTCKIUWsOAWVvBW/tU5S7aB njQk9oqkf2ELfg1qnsRImGn0Y8w9Mq3yv+nsjgDNfqff4YRyuvVWbr3xjT8v3G0LdhBB xBT2wES1wDd4OFFjfroDS2mlbdTZMltV+IzmG7KmH8SQIvNRjcP6CQckSG306R3T+EE9 dyAVqJ/MdRm/vd4D9nWfRocaFyqThmWKI2JogMRSIGZv1TQL3w1HwOteRiz8hrHrnai7 Dng+ii1cr0Ny2BKyHWmaMsE5nY/HfPIbq1dHWFiDdURm1MjWcT6siV+qPGTihD6+fLyv JJsA== X-Gm-Message-State: AOAM532MjmT7Nvyteiv8YQOURFS6ypE7KTrwf9zMWNxF7Be4d5d6zb9p vMg/mC+a2/LlYlpI4rgMvCCmIjAxdEXUIg== X-Google-Smtp-Source: ABdhPJxzxNABe4rRlKNrts2M/Kggu7xs4c/+A+QHu5L3QZJqK5m7aoWB/6i5S8nwiqqKZleHSWQNIg== X-Received: by 2002:a17:906:1913:: with SMTP id a19mr10257359eje.484.1636643335151; Thu, 11 Nov 2021 07:08:55 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id hs8sm1544051ejc.53.2021.11.11.07.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:08:54 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 03/25] trace-cmd library: New APIs to get and set version of output handler Date: Thu, 11 Nov 2021 17:08:53 +0200 Message-Id: <20211111150853.86566-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 47a30246..eaa902a3 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 b43f9e47..e8c788ad 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1055,6 +1055,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. @@ -1885,3 +1905,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 Thu Nov 11 15:09:00 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: 12615037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A203AC433EF for ; Thu, 11 Nov 2021 15:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A2B8610D0 for ; Thu, 11 Nov 2021 15:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233892AbhKKPLz (ORCPT ); Thu, 11 Nov 2021 10:11:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233810AbhKKPLy (ORCPT ); Thu, 11 Nov 2021 10:11:54 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22005C061766 for ; Thu, 11 Nov 2021 07:09:05 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id w1so25437217edd.10 for ; Thu, 11 Nov 2021 07:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HvjNhO6rSGOzEcVhxWg2PWcqULJ4m3bhK1jYhtiwVeE=; b=eJCDJUhDZTxYSTZkMt0HP5aNVWp9wRFnSGfarQEm/hBh47EsPN72UL3Hoc6RpaBH4M BV2Kl8raJjFuuW+FPfHDa/ohzJhnwt530h84t2yu9pMKKpOOQbfudHrBQCLUVn9g6c9N Mt8NWyjkt4PAV3w/5GUAPZF6UwWm/k/FDZjl2TpV184fH2sKDFPjoNIO8PwFsg1fIoV/ E0Xvi2FS7Dnd23Iow+W9jZ4OoPdixQ0FdVPI3N++TeZX8aEp3+TLEY3ucWTRaT25n8Ll blVRNOcJ4KuO0ibRwyN8u2hPhvfydhgpa/fye9Qzbud4bDZumGMPUjKS6HZDmYqQlWZm cAMw== 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:mime-version :content-transfer-encoding; bh=HvjNhO6rSGOzEcVhxWg2PWcqULJ4m3bhK1jYhtiwVeE=; b=lRZEPxUsAqi+prtDaUzI4m0dvmaSWqm5YOzyknURfettsLAYt27CQC3fmBfaIZlAKK MGxRfElZ7/SmKcln3EarJ9VY9X0NvYaTLhkgX69AfS4ySQe0qFxX62Vm8iIYOEnK9urw KC6lE0g3++VaT3rYYjVfzipwFYSLZ87r5PJUSJ9+g3hM3T+v7a8L2PJGxgwjUtfkxeve Wvcd8Sv+L9bo0CR8LSA67HGD2ey72dXxHA4EiTPCMvhiRl1/R3YqJUT/wlorQgvTgZ29 FO4oQUfAdHjZM7/FAIKl586FxrtIs9jQjrEThm+ZVKV4F3g68blZYZagP9HMbylz16v2 sFdw== X-Gm-Message-State: AOAM530ZMkOj53qgycFMdX9Bq/hJSvFCy8WrmhqH7UZejJm4qHAe6teW YpZUphkjJlr1D5irD79MbNN8PhChAmTE5A== X-Google-Smtp-Source: ABdhPJwWNrNasDBO5AGwAhELYt+swlc2nCXCPq0vSsIe4ecQND1TWz52DijXTpCzoQCnh6uXDY+I1g== X-Received: by 2002:a17:907:3e25:: with SMTP id hp37mr10364887ejc.43.1636643343688; Thu, 11 Nov 2021 07:09:03 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id t23sm1590364edc.95.2021.11.11.07.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:02 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 04/25] trace-cmd library: Add internal helper function for writing headers before file sections Date: Thu, 11 Nov 2021 17:09:00 +0200 Message-Id: <20211111150900.86585-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 eaa902a3..5b253511 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 d65ff599..d3760483 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -37,6 +37,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 e8c788ad..a8c1305d 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 Thu Nov 11 15:09:08 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: 12615039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41E3BC433EF for ; Thu, 11 Nov 2021 15:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B5F361252 for ; Thu, 11 Nov 2021 15:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233903AbhKKPMB (ORCPT ); Thu, 11 Nov 2021 10:12:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbhKKPMB (ORCPT ); Thu, 11 Nov 2021 10:12:01 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1DB6C06127A for ; Thu, 11 Nov 2021 07:09:11 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id c8so25037924ede.13 for ; Thu, 11 Nov 2021 07:09:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=twZ3wQR2kzl3xVcWQfKJM77Bsk+31Y7dHES6vFYSfLo=; b=ReCOwbQJFUJUi2UKPwwdffu+yDy+5SIMcxy8aTp8vJijI58IO9w0XuFhogl8lOVaWR rxlj9U9lZ4bC4csBTX6JUmvGi2Gni6N1LeaKOBpAqp1lNxFxTJmqjeMZkoxfNHEtOAKe 2Igs/zqrNWv0tDQw+sFv5KugEataKMD+NUvKgLkMH04QXzsfKcRW14gBnEr90T7x3GvJ s7hg+W19WpPcQNqiEddR2sWHArm26VRjA5ccFdDZUMgmfsqFU8RbXW5I5l1yut7bwlf2 FwEnosLDo90YyODyrfQuzsaO69fsLtY+qP6GNgxVhN5u8IXPTLUdRnG47RinbZgHWAeM gOHQ== 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:mime-version :content-transfer-encoding; bh=twZ3wQR2kzl3xVcWQfKJM77Bsk+31Y7dHES6vFYSfLo=; b=7V+gLkTSOqga8wbxhHDU+2XA/ye0Af2JSO9KmHRhDwrJC64lpiAmAMnvN+m6Ssf8Ap +TKrrr9zboATuCGhY5GLKHPkukZdrh1B03OerGgAb/+HxVUgPQ/AChp9HRgMb7644fbY 6GO5X+unq/iuMgXX/iTQygHLCrdzhaE6laak2rT6f2YjNs7ff5S34Ep7fZ+j4FCrdZJZ CvkkmliMp/LL7ooTog2PfpVD+dPwMbasUAZ4GLgmAJVF+GCdMljuqAOIDu1WWUDXds9C m/hJGKz56TFo1RpsHp6Cj0Ur/Pd5llyelHXG9ntYvqyQRvROYvtcHEfOj9h8yYnhbPRg NvTw== X-Gm-Message-State: AOAM530Xb95Po3K6ceLDPiyfzDSl5nE+1wzT/lOl0yPP/xB62VbjeuPU oxaoguB3PeqXRZAKUKUOmsU= X-Google-Smtp-Source: ABdhPJxOcDNzAhNv8PIqAWYB5LYqJ4mAXHZnQIAqM+I1anYxitcvmdnmb13bC2RqdaLyb2BLrhkU6g== X-Received: by 2002:a05:6402:518f:: with SMTP id q15mr10676333edd.77.1636643349997; Thu, 11 Nov 2021 07:09:09 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nb4sm1601392ejc.21.2021.11.11.07.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:09 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 05/25] trace-cmd library: Write header before file sections Date: Thu, 11 Nov 2021 17:09:08 +0200 Message-Id: <20211111150908.86602-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 5b253511..be9c79cc 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 a8c1305d..db72f47d 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); @@ -1512,6 +1564,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)) { @@ -1519,9 +1573,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 Thu Nov 11 15:09: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: 12615041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7253EC433F5 for ; Thu, 11 Nov 2021 15:09:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 564B361252 for ; Thu, 11 Nov 2021 15:09:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233868AbhKKPMJ (ORCPT ); Thu, 11 Nov 2021 10:12:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233810AbhKKPMG (ORCPT ); Thu, 11 Nov 2021 10:12:06 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EA24C061766 for ; Thu, 11 Nov 2021 07:09:17 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id z21so25381891edb.5 for ; Thu, 11 Nov 2021 07:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=77jR0p82kdn+GCoB+qgvModi8/WHtgjAp8mMa+wm5Zg=; b=W5z+3G3iVGTtbx/hmuHYoiuqkv+1HxwIwdoVDFrZU+Xs6y0wDHWlYd7zZivoBFtoJa Fh3s+839ABS6go2giaBHvULrTbZsdi91O5FIe6Id4mFYdZY/Q5BVipFoXDCCFIrHLN11 +L5xcC3aaO8AxUVxcFOc1YKIm8b5bl50/f/2PODrWILMdrWq2sIo8bBrKH8fNjilD7aB 3OBEWJ8dxPnuczqIRw9GvCVTiIiE2VNXk0Ia0NrrlhMbQ2ur+rRjKR/dlXZRRZWvLGJd CTZ2irpQfL8KiClKfnj/tybHJSMz/A3WOGKUnqNcHr4AU5WROCnQ6STZDRjEmIOmNAD8 Lkuw== 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:mime-version :content-transfer-encoding; bh=77jR0p82kdn+GCoB+qgvModi8/WHtgjAp8mMa+wm5Zg=; b=r1tzSIZJ8rz7zgb/eLeBTY5z9RBEG+eQv1GzbDso7HwxOXIbExTcwbmqU4tejTs1F9 P11ViKh3isTVUCDSxOIaVxSDNIGw6SP0+2Odw94mevbDHHgxa5XzQ3cV6C4PFiZASKH1 VoJcaAt+BJhcTMVROHc2J4YZTfWhUPoNgUtMwopneDRR22VYztKVgXtd4cDvlNCSx840 +yR9thovaycNqoY3+ISVU1NU05EsGYobp4fquD3thWaOiwSSMjSXdDCLOpTSUBi1umj/ /A8gWqaZmyaZpiLG14425dcg7WKVRRRaZbMgAftXkMKk4TI0X7EOgRZ2mD36lRA0k+ww oltg== X-Gm-Message-State: AOAM5304j/lIfQ4DXz2MgnA6zXBs8lmm6HcpTAR8IXwGU8pCMgClz1QR 0bxH3kYTxmf7Ko63evWvhE2M1rzGgBoGzA== X-Google-Smtp-Source: ABdhPJyV7aIRcGup+Hic3V6G7rwxR8za/EapP6DxNOf5CgzeWTC7+YSNioKMejVgmjFH4T2noX4aRw== X-Received: by 2002:a17:907:1626:: with SMTP id hb38mr10222178ejc.481.1636643355869; Thu, 11 Nov 2021 07:09:15 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id hg19sm713267ejc.1.2021.11.11.07.09.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:15 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 06/25] trace-cmd library: Add multiple options sections in trace file version 7 Date: Thu, 11 Nov 2021 17:09:14 +0200 Message-Id: <20211111150914.86620-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 db72f47d..48e69850 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -62,7 +62,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; @@ -1212,6 +1212,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; @@ -1245,6 +1246,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; } @@ -1313,7 +1322,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++) @@ -1326,8 +1335,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); @@ -1390,7 +1398,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; @@ -1408,7 +1416,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)) @@ -1432,11 +1440,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; @@ -1487,6 +1567,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 Thu Nov 11 15:09: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: 12615043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DDCFC433F5 for ; Thu, 11 Nov 2021 15:09:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F05661252 for ; Thu, 11 Nov 2021 15:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233810AbhKKPMP (ORCPT ); Thu, 11 Nov 2021 10:12:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233715AbhKKPMN (ORCPT ); Thu, 11 Nov 2021 10:12:13 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445C6C061766 for ; Thu, 11 Nov 2021 07:09:24 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id f8so25615442edy.4 for ; Thu, 11 Nov 2021 07:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bunGmG6t4DdPm171IFBPKJoBlEqIDwR02+aCLO4f1QA=; b=KJp+9gMuTp+XuDS17+OU+wKVBNH6olUskvTauosABlK5AEq7yCw5z494ugfQCXn0Pi WFHFRPZDIr+quXjS/0CgaFWFA9l7HZarSQ0GlEXn+XYAlkAINJq2lFS1sGq+Qs+jeaW9 0TwcsWziOWYjXwAr72f1IPSXFyiECwOtQ2IGH94bRDh2lgiNwCgV4zUxY97RZr+XXkDr 5KiSoOKc3NJZW+uoMFTLiH66NS869RjlfgoDlwFk3XwpCTrKu7N8czMLgDDRDdzOUEta o7Q4wB+v1JiJAQhtXL6FksVfy35iqk3MotnVUJx15wisbt8DwXRpY3jMCH5sS11IFDCz r0nw== 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:mime-version :content-transfer-encoding; bh=bunGmG6t4DdPm171IFBPKJoBlEqIDwR02+aCLO4f1QA=; b=hlvMAstxTiWlrVrbqXrIn1tahKC6QpT68UrWry7HA/eMvbn5lkgRIF8s29Wb8Tgytp q8ws6lXcQL7ti7fE1s0FRXZER0KiG1GFW4/kPRZ3+EwzPhE8C39o4PYUEooZYzNe49Q1 ugObI4g486CClwgdG6fkqS7/Rcbo59WnKNe+rN9cIYZkuLZHYgoSUxfQhfhbnTVmVpKy Bx5rZNEUQcQ84CWVFtZ2Lx3ADKbt8QhJC5ZHPGpAEmwPfRNRqNqAoJc7NPZC8ExwfBey Mcpjlr2YRc+jV0sGT+oPLt2CT6HXWyYQidH4jmw3Qp0N5sA5mwd7fLLcU5EctVlX/Kli Q7Fg== X-Gm-Message-State: AOAM5323REv660f+UGIp9K0uhyZRYVhCgOyFBd8lJ5jHWuxjhiaJ1gz1 +pDPvoP41I/HoO19dK2AmxlGLVMfOfMohA== X-Google-Smtp-Source: ABdhPJwvageKsDHTYWB8RvDIhcrSgoNI4ZEBuyvOT4DjZK2VR9m57swC3S9dWO1wKbXXbTzBAMfukQ== X-Received: by 2002:a17:906:b51:: with SMTP id v17mr10504374ejg.262.1636643362812; Thu, 11 Nov 2021 07:09:22 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z25sm1425008ejd.80.2021.11.11.07.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:22 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 07/25] trace-cmd library: Do not write CPU count section in trace files version 7 Date: Thu, 11 Nov 2021 17:09:21 +0200 Message-Id: <20211111150921.86643-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 48e69850..02fc78f9 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1390,10 +1390,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 Thu Nov 11 15:09: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: 12615045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92EBAC433F5 for ; Thu, 11 Nov 2021 15:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A3C961108 for ; Thu, 11 Nov 2021 15:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233908AbhKKPMW (ORCPT ); Thu, 11 Nov 2021 10:12:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233898AbhKKPMT (ORCPT ); Thu, 11 Nov 2021 10:12:19 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7139BC061766 for ; Thu, 11 Nov 2021 07:09:30 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id v11so25447109edc.9 for ; Thu, 11 Nov 2021 07:09:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BIxjXSlWZFxI3y+KKwdJz2YN7djHgx9BFml3J96UVs0=; b=F+NfjuLivrp0RNTchE6Wh3TMfq+yEWTeelsS9EFj9UfiZSJYpbfgr5DLM8xi1GRH+c neD7dGK2TifUAAmQwSgdGqhUn7X23OhvCQX45aTx6hQK8pCqh1GIlYRFrK4GI4PftHVq 8GboKBqTSyjRW5z7fW9cTamlNZdmEGZT2Qj8UjoNlyuufsNw2MVy4sDyEvOh9AYpXY5L dXvxs8jAtKwn2mRqwMUGux2WwCWBG3lBqNg+X8D8COOtsbMtmvEMdwY9sapp0Fk8t3bA Qlj5S3UGdkN9Csjs5a1dowLYA5G534dWz+QMEjjzwcNxanJ2kjQ7TvbJM+JwJmS4Br/j NVuw== 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:mime-version :content-transfer-encoding; bh=BIxjXSlWZFxI3y+KKwdJz2YN7djHgx9BFml3J96UVs0=; b=ew4BpC1hYLeez1/TUw+QQ694+z1KAl7ZsNJKNNKcA8saCpL4+fcOFbsxeFNErkMP9Y 7ZsppBqDmDZ6ls2NkN/DRnVSQ02vreqtv9YUpREIL1kKpjZBh2ngbVbTEu7y/F3RwLra RNjv0wsm/Bna4RZsSSi3u6BLG/Ym/7syT5oA2IyyFX41iWyRzXIfbIN1CbE1qDhQlvVe v2jew7IAeICD34PmzWhmVxCX6sLTH8JPWLCafOkGvhq4e3yVZdYTCWqUIvgfh/V793ld f0tFdNQOf4svYbLU11JV0MdRMNOJXt7MG5BqDv7zcCtMPMu71o+Tdp/L8poXgdq5vRf0 vKqw== X-Gm-Message-State: AOAM530oo5fckeFstVuW5qfn5HlgDbzMqM8fqz+PGV2YpO3eV6RFIPvV +xDPkAwSHTJKgzTo+nhmzfFG5Rshb/Enzg== X-Google-Smtp-Source: ABdhPJylKoJYvB6M8D9wY6h7UEAeu/nlOWYEnBCZIeGxMDRxE3sT5y9PrORacD/WHpILxuv5GA3sAA== X-Received: by 2002:a17:907:6d8d:: with SMTP id sb13mr10621663ejc.345.1636643368983; Thu, 11 Nov 2021 07:09:28 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id s4sm1825869edd.32.2021.11.11.07.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:28 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 08/25] trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file version 7 Date: Thu, 11 Nov 2021 17:09:27 +0200 Message-Id: <20211111150927.86661-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 | 191 +++++++++++++++++++++++++---------- 1 file changed, 137 insertions(+), 54 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 02fc78f9..1f846742 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1581,7 +1581,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; @@ -1631,8 +1631,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; @@ -1683,6 +1686,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; @@ -1759,8 +1854,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; @@ -1793,26 +1888,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) { @@ -1836,7 +1911,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(*data_files)); @@ -1849,19 +1924,23 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, * Place 0 for the data offset and size, and save the offsets to * updated them with the correct data later. */ - endian8 = 0; - data_files[i].file_data_offset = do_lseek(handle, 0, SEEK_CUR); - if (do_write_check(handle, &endian8, 8)) - goto out_free; - data_files[i].file_write_size = do_lseek(handle, 0, SEEK_CUR); - if (do_write_check(handle, &endian8, 8)) - goto out_free; + if (!HAS_SECTIONS(handle)) { + endian8 = 0; + data_files[i].file_data_offset = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, &endian8, 8)) + goto out_free; + data_files[i].file_write_size = do_lseek(handle, 0, SEEK_CUR); + if (do_write_check(handle, &endian8, 8)) + 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; + 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; + } for (i = 0; i < cpus; i++) { data_files[i].data_offset = do_lseek(handle, 0, SEEK_CUR); @@ -1892,29 +1971,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].file_data_offset, 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].file_write_size, 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].file_data_offset, 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].file_write_size, 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; + free(data_files); if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) return -1; From patchwork Thu Nov 11 15:09: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: 12615047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 801DDC433F5 for ; Thu, 11 Nov 2021 15:09:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68D796135E for ; Thu, 11 Nov 2021 15:09:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233928AbhKKPM0 (ORCPT ); Thu, 11 Nov 2021 10:12:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbhKKPM0 (ORCPT ); Thu, 11 Nov 2021 10:12:26 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBE77C061766 for ; Thu, 11 Nov 2021 07:09:36 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id v11so25448474edc.9 for ; Thu, 11 Nov 2021 07:09:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TdhLGISiojXTI4BDqsvCg6kF4bBHfTBPwhzqSux3QuQ=; b=misq5FsH48CuWTX4aK13aBQTkSIWNWkqLNm6REUVIMbjR/5eg1SNsQlgkMXzDd+sHb kaObP4SXpuYQnty9Q5F9WxLA8ASr4SBFQ4vlNwxkz/g7gh9ryp/KTtuczK2UHekP/s9v IKnVUWR+X4ldEX3f8jgK4tggN5FtnBdx1932gt0idPn4NshjrtWhLbENBpiM9r03fOir RKxeBI02uOBXcb125HLDqqdQLmWSuu2SMYyKSBmB5nu9bA78ALMVy/6EwEe+33AtZWY9 YEnJmO2L4a4Zz6JF+qrq64jy2ISXWsBxoZ0cLYu3G93WDyoLaGVROpnlviieWN1bwMA7 Yk3w== 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:mime-version :content-transfer-encoding; bh=TdhLGISiojXTI4BDqsvCg6kF4bBHfTBPwhzqSux3QuQ=; b=BNKHdJwBSGZC0H0FBz13paqNQp4a1rVDMjdq4IXK+ciQVXBFW3xVcP6pqhyJpN0+cJ QycGOIfeOkBYu4K61mSU5g09R5tcnw9+E2E231JEXWLnUcbR9PdO0tBjVT39ehe1mpoq pdiGFTSwU9zZU7PV1LFmSW73pyAQGGYfAr/0r+PNHozcnCAoKSVyPsdXWP57AlXZM1KS HuyowaBj14y5ABWUjO4HFK7saAaAqeFfa4zFoaSZm8xRu/xrdAUcQPwBGAl41vK8HDbL GXRgWYmqd1UzRu/EeKLcZdYowo32a6xmmNi66Lg4XSJezkkDJGag+2MPH+LFjwe3y5bc PLcQ== X-Gm-Message-State: AOAM5303p2JLImgM5hon88P4NoWa/i9aSnrmzgeLRRJ0l4uiJqsRk1vr jHSrbOmYSIm7Mr8Z59cYqTJLEheKRsZmuQ== X-Google-Smtp-Source: ABdhPJxTrnZM/9w0qxHC/k/Ga3I67y5GNAWvXR9Bo/1NJAtGHZxelPtV8fTpETqit543dSukY+a+Rw== X-Received: by 2002:aa7:da55:: with SMTP id w21mr10546850eds.159.1636643375156; Thu, 11 Nov 2021 07:09:35 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q14sm1739059edj.42.2021.11.11.07.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:09:34 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 09/25] trace-cmd record: Append trace options after the trace data are written Date: Thu, 11 Nov 2021 17:09:33 +0200 Message-Id: <20211111150933.86678-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 757dab0f..32270e20 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, NULL) < 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 Thu Nov 11 15:11:03 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: 12615049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D393DC433EF for ; Thu, 11 Nov 2021 15:11:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6EC461108 for ; Thu, 11 Nov 2021 15:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233328AbhKKPOF (ORCPT ); Thu, 11 Nov 2021 10:14:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbhKKPOE (ORCPT ); Thu, 11 Nov 2021 10:14:04 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A74C061766 for ; Thu, 11 Nov 2021 07:11:15 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id m14so25733019edd.0 for ; Thu, 11 Nov 2021 07:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+4RDUY3qWgE4rgsV+KFWJN5mACr2UCj9iRlQaroPQz8=; b=DnFO08Wew95Hg3EOEujJLFBgvclua0CNzIKIq+zdsQHVvGSTY+jbiDseArwLG+QjfQ 3OAvSQljnu3PHcAMvl00SPb6edAP41gqDWltyEt2TKuJhlrGQe9WHtU17hiKHGqN/Qtn GO/qD3bcsqz7jrWq8kpYpnMsKV3gkuyJr10eO/bMrSN3IALcT+158R9aPyIylORShhGZ oJ2DejD716+x1fI2mqyiL/8Zk8s4+5UXBjNSAY182A/pKC9/lFJjGQBTNJR4sP15UoGq rNOP5EOiMAXkV+XDoKxYTo7k9EtOJmWlqqtuw/PND7mUbyztlFnYX1DtgE5NbtiXL/9M m9Ow== 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:mime-version :content-transfer-encoding; bh=+4RDUY3qWgE4rgsV+KFWJN5mACr2UCj9iRlQaroPQz8=; b=VxedDpw2eQ86tlFMnAmgFI1i3XLKiw8cBNDsQKtAeoxGdC3popF+dRb/MJzqbYZDMB DNSbZpc9Rc45AGw3fM/J9wJmWZYxrcAylSFimd1SR0qQoe/CayaroGHZIc6yc31pD395 mzIM1MPr4Jup63+3FkJkiXPe6H7+BO4zMkN8ULmcwggYPtboI10Kh88z3jLFUhf+N1yc KXkynxASFud5JqIkL/p+KKPqCdfPHiXF3PUOMeMqGb3Tia/Q3IjDiavEPVCNBn2aTw+v 0IRPGn4nHdP6RAlR6ZK1p4S87hixDPbbHTEOhVgYcW/BSdVmMa9Zjzx7w/Hs1Vl0Dqd/ 7frQ== X-Gm-Message-State: AOAM530p9dLKc/IfFv1iQujmdfCotdOz0SYkNn1N0tG06NLyErsOxAc1 xlft3yVgndcMwMZEyylN6Kjed8AOe3mFZg== X-Google-Smtp-Source: ABdhPJxhv5wZPhKTQsRa3AI0AO1AnBS8x7+fZEq8iPtdLutbaZHVk2LeD2jwlelx4RMM0hP1L7hyAQ== X-Received: by 2002:a17:907:d14:: with SMTP id gn20mr9909304ejc.73.1636643473832; Thu, 11 Nov 2021 07:11:13 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:13 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 10/25] trace-cmd library: Add section header before flyrecord trace data Date: Thu, 11 Nov 2021 17:11:03 +0200 Message-Id: <20211111151112.86751-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 1f846742..baa262fb 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1892,10 +1892,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; @@ -1914,6 +1916,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(*data_files)); if (!data_files) goto out_free; @@ -2002,6 +2011,9 @@ __hidden int out_write_cpu_data(struct tracecmd_output *handle, if (do_lseek(handle, 0, SEEK_END) == (off64_t)-1) return -1; + if (out_update_section_header(handle, offset)) + goto out_free; + handle->file_state = TRACECMD_FILE_CPU_FLYRECORD; return 0; From patchwork Thu Nov 11 15:11:04 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: 12615051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 913FEC433F5 for ; Thu, 11 Nov 2021 15:11:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E23361252 for ; Thu, 11 Nov 2021 15:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233890AbhKKPOG (ORCPT ); Thu, 11 Nov 2021 10:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233854AbhKKPOF (ORCPT ); Thu, 11 Nov 2021 10:14:05 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C14C061766 for ; Thu, 11 Nov 2021 07:11:16 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id z21so25404188edb.5 for ; Thu, 11 Nov 2021 07:11:16 -0800 (PST) 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=k6NE8OO3euVt7z09x9MAKo0Pnnt76BjxGY33SBas1nE=; b=FJiDX1yN+LKuFot/fougt/QoeftyyfmcZ367pj7jrCKpuUrsTik3WsPbsnj9wPDFa1 K1etZFh+epIkNxaYpf8I4la5zL3H7ogdZ9txvFQP0y8uvpgmrQ6PBPT6qUf75VqpPI7A 9k6/z8rgkSjCf3JWn3pqBMRP2YRW+ccZ+QU6IM8zK6M+S0GsAeZWt8NwTkYXpHCxVHWu Z9gzkDVm2K0jzusVsW5Hs5dnVk1RNfxUPnnq+psZadgR+BbClw/F6Sz7hYUmang5BtXH 4Om4pzyqC7X3QrbQ4jD4RXNBsgYwtq2aGs4Gc3EifNgblgZD7pphcOHyH9RRmrqMRorc YThg== 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=k6NE8OO3euVt7z09x9MAKo0Pnnt76BjxGY33SBas1nE=; b=nbUJRPT7zId390ApDFQny+zPTU+qU4dAXiG0kkMbjaT8ncN86x87/u2zjpV8AY1bwl +BIeW4zYQ7eddW0K8ZewA0ti1NcLlZ6L4kTH/h2hSygOvjb3ks3ezlSO9ryr8wqRNnpC nAA8XPKxa0f8AGeghGNp1Om3bddcO4/jAq+n9cgqThh0rX/uvEgRHhFcpxi26+SMclDa r5hGnnXBRiwk9Zm8pHLBKRRI6fTsUXFWU4xRSbL286RDsMNr05UZ2/enRGJ6oatAWz94 luWpDBVCOXbpMlhmARw9j2P72Xgm1mO3IHq7V+XLIBOb0MHaSY5od/NyvMowp0l0TikQ hg3g== X-Gm-Message-State: AOAM530VWGD5J9L34Q0tXi9Fz18i1aJM7lHi0NeaFwkBvkn8ZIHrrsfO hY/BYVIMxrN3Ah44AlUyPVzna3TpJlwGxQ== X-Google-Smtp-Source: ABdhPJxs95xmJ4v6pkHuQCEX4zlDOed4d7IfmVhsi14dmcaqP/M/qXI9RROw1vbNVsa9sOjNZOp/Fg== X-Received: by 2002:a17:906:6bc4:: with SMTP id t4mr9980719ejs.259.1636643474836; Thu, 11 Nov 2021 07:11:14 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:14 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 11/25] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format Date: Thu, 11 Nov 2021 17:11:04 +0200 Message-Id: <20211111151112.86751-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 be9c79cc..8159c2a9 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 baa262fb..028ad580 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1780,7 +1780,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; @@ -1803,7 +1805,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; @@ -1813,23 +1816,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 Thu Nov 11 15:11:05 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: 12615053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFFD6C433FE for ; Thu, 11 Nov 2021 15:11:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDFB961108 for ; Thu, 11 Nov 2021 15:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233854AbhKKPOH (ORCPT ); Thu, 11 Nov 2021 10:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbhKKPOG (ORCPT ); Thu, 11 Nov 2021 10:14:06 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DC9FC061767 for ; Thu, 11 Nov 2021 07:11:17 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id f8so25636761edy.4 for ; Thu, 11 Nov 2021 07:11:17 -0800 (PST) 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=JrlXUlSZ5wVZqbKe/8Rwq0VH5FrWsOGk7IpQZ2t42kM=; b=Bml6PkdO1UdMIjvV/tRa+JdUzCm9M0Z4HgZDxJiCOoj0dIfwpaEu0/mDarKSQZFkwX x3OS0wyks2crPpuYUZ/dmVUifGt4/RKR5cIhgb053X291GLoAOTb2qffv7dPDu3aFkvF dMWLV2XrozBG6rb1/0Eb+3/FOGeAJ9r0b/a83rI7n6A6nDg6zqVNPPSSCq/jrCJZ0FQE SWDRtCPJmgOmgOSUNmiohQOmcxRzOI2Ziwr0v76KcIDj5Ked1xI7Dy4Ox5sQTaEqrw81 XE5p+TcMv/ErjOJAowG8kCxwjJhvL3u9lmPHaZ1ObgFRBH0UE8dwWecUC3W/JLZx3XAK ZU4A== 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=JrlXUlSZ5wVZqbKe/8Rwq0VH5FrWsOGk7IpQZ2t42kM=; b=SyM4SdT5lIV1gaDsgHZjkmcjaDIz9n0WlwCQbvL2YpUGRUTbQNORQEj2h6wK0+CElv rIB4MCIB9SXLAMIIyRWJsFT8nga9OWlkrFZl5VVbAuSgu5V5X2nh0MxFcs+QDdN3Vekr 2Vca7SOydwrsFuH87TAMjuk5J1A6JK9bVQxe2YCVLOsQENC3sBMQZibmwXsDPpVVGcZu 6G7BHfAOkT8Ve2Gc8gAmy7gDwRxFwRXVLKnqIrGPf6Y8jgQikI3C1boeTc/kFDfo9saa ZKmHBTnWI7UDMH2rKaGvi8LALsUnBd282msfrrXxvv/X8dJ2spX97saTuixoOcTJR7aw /qdg== X-Gm-Message-State: AOAM532KCrJrVUwGheP0Gk0nAFPaPh4xsmKsPpHv6RHlRYGdqM2VR985 AL1GKqNAZTjyqIg1xvBHOKW/xFc8kL9lZQ== X-Google-Smtp-Source: ABdhPJxVD2ZiI3TkYgmwYfzYHK2f6JeRLoSco9F2BWL4lcu8+5KORCTeW0PItCRp+qejNYkpixE17g== X-Received: by 2002:a17:907:7215:: with SMTP id dr21mr10087360ejc.505.1636643475723; Thu, 11 Nov 2021 07:11:15 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:15 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 12/25] trace-cmd library: Do not write CPUs with empty trace data Date: Thu, 11 Nov 2021 17:11:05 +0200 Message-Id: <20211111151112.86751-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 028ad580..2ed7155b 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2079,8 +2079,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--; i >= 0; i--) close(data[i].fd); From patchwork Thu Nov 11 15:11:06 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: 12615055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E308EC4332F for ; Thu, 11 Nov 2021 15:11:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC31F610D0 for ; Thu, 11 Nov 2021 15:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233925AbhKKPOI (ORCPT ); Thu, 11 Nov 2021 10:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233937AbhKKPOH (ORCPT ); Thu, 11 Nov 2021 10:14:07 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29616C061766 for ; Thu, 11 Nov 2021 07:11:18 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id c8so25062589ede.13 for ; Thu, 11 Nov 2021 07:11:18 -0800 (PST) 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=HBQ21A+hDDClbh44U63m7ICaBf9ViJ8+cNcu7iK/WBs=; b=o8ZgzhSiCw0VsbQ9JH55B3owv2CMI3Dyz5ar8AfQ7/GVtimgFe/ri6frRL63gK9Cx4 SwBDM5FLClDMgeEpzGwq+k3bbG4jHOP7ptVVHgHMCqpciSSflHDDDEG99r1p9NqozX0s vJaG0FZQP3pys7Le51EWvlYRt5pOqpxg1k5Rcfu/HgAtDtZRMldHKsxEY6/CjQYaNZ2r jBm5Hn/d2fwAPd01AMqelJUXGQpNTDlo2cdjtVsxmALwPszqphnhC3Er4yT1i8NGXyR8 J0UAPct/7DKAdE858uvGNEDKbSidqFJxszcPK1SSENkwuupNcSYJkjbNRGdRT9MLjG+a s8Sg== 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=HBQ21A+hDDClbh44U63m7ICaBf9ViJ8+cNcu7iK/WBs=; b=F3rL/w1bBiXRQz8mD0RX9iSI1XB3WDA0ji0B6YRtOiQqWfwF/IbPJYbnn21FTPk3of 32NRmCOluvwCTVvHW7v1OsygKolSa+/f/b27ZXq32bW0QvOYXX4ORL/X5+7ywJhx3AMy V3Zu3YsOIwYlcRH3OgpMT+2B+IOTTbx/+4H0dRmtk2k1apoUWXmyF4znEDs1/WZdTFM6 TkCnqYZ9N32/0wh1z/K/VvRJMYiG0e/O0MPPGOHt5BlOQuhF6iHx44sg1muiXNGsK1sc JiMatwS/obsRhF3XMT+4IyUe5UToa9QTiVZ+4NWyHqAZixtdsTVhT3moW/55mUl/9vU2 sycg== X-Gm-Message-State: AOAM530rMQ0KlBNYauaq8VMnMgCsKvhNnmRJQo5ukaUp/LtrqnBo3VVm vDjLl0VYPTYSzsWSz8B5l/tMAMxKIsw9Xw== X-Google-Smtp-Source: ABdhPJw0Mumg8jJtxERh44XZ21Bc0cIwFqENlN27graE3sXPy35wgqnrDw1YwxmBS95QZOZwQoJ5mw== X-Received: by 2002:a17:907:2d10:: with SMTP id gs16mr9888646ejc.353.1636643476781; Thu, 11 Nov 2021 07:11:16 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:16 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 13/25] trace-cmd library: Add macro to check file state on reading Date: Thu, 11 Nov 2021 17:11:06 +0200 Message-Id: <20211111151112.86751-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 31e5e674..0375afba 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -166,6 +166,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) @@ -382,7 +384,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)) @@ -588,7 +590,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) { @@ -661,7 +663,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) unsigned int size; char *buf; - if (handle->file_state >= TRACECMD_FILE_KALLSYMS) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_KALLSYMS)) return 0; if (read4(handle, &size) < 0) @@ -778,7 +780,7 @@ static int read_ftrace_printk(struct tracecmd_input *handle) unsigned int size; char *buf; - if (handle->file_state >= TRACECMD_FILE_PRINTK) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_PRINTK)) return 0; if (read4(handle, &size) < 0) @@ -826,7 +828,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) @@ -2829,7 +2831,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)) @@ -2994,7 +2996,7 @@ static int read_and_parse_cmdlines(struct tracecmd_input *handle) unsigned long long size; char *cmdlines; - if (handle->file_state >= TRACECMD_FILE_CMD_LINES) + if (CHECK_READ_STATE(handle, TRACECMD_FILE_CMD_LINES)) return 0; if (read_data_and_size(handle, &cmdlines, &size) < 0) From patchwork Thu Nov 11 15:11:07 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: 12615057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61878C433EF for ; Thu, 11 Nov 2021 15:11:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4844661252 for ; Thu, 11 Nov 2021 15:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233858AbhKKPOI (ORCPT ); Thu, 11 Nov 2021 10:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbhKKPOI (ORCPT ); Thu, 11 Nov 2021 10:14:08 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B79C061766 for ; Thu, 11 Nov 2021 07:11:19 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id g14so25471799edz.2 for ; Thu, 11 Nov 2021 07:11:19 -0800 (PST) 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=rjWkABomLOW1NqtQQBs+E+WWRI1oaiGoxLAEByFvk0I=; b=OZmUn+aTMQBXAteqHmZE1GCmel+kT9wie+1MlXidBXl+3nWdmk8jAMH18VNl6nftSb 0WOoowgnW3V6WeCdlPrIPW6LUoNQg/PodOzCyeJ6OKjUwnhlbzbh40FCHvN7TEZBe+SX gxoXvj73rsrjw9hqEuA0Z5U4hA1ETD/7wyFhfOBjkvnVioDdhJxpo1xjM9YfTyj0VBKk Xt/KHJCMGEtlHdbJjovgSQfHBMP2WaViCHiK0vRNOeS6L35Hd7EAaX8iFZFPWQcskj51 P+uDVKAbZnH9sUjwWRZsCdbG6HTF4TH3R8GSvQIA9Jr6WimqWTJMN9UV+Mm741RwLD0m dZhg== 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=rjWkABomLOW1NqtQQBs+E+WWRI1oaiGoxLAEByFvk0I=; b=Ux7pA/lgq/oRIIR0SgcEtZb9paiaK+3KJBkG1LmsmHtTbfHcDd1KKuY3YwGhJckxfS MvcIr/MG25+33USdT9WJDlGS0vWO6YZFvFjQCVm2l5YyMqMJZ1Tl5GnL+DDJWf7lIXje i1zKzXYk1NqkZUQlYkmjMiILgRK3SP4qmgW3Jid4gVqlllRT03QzLI1+4EOYrU2l7Al1 jJewa3hxJwg8fiGVyQqBYJhLtphuMtSuckHEabTzDQvnecBRIlG2PSQEClCQiAyp4ppd LbLryXkGAflpLTnkPrSlkiQ6gQHqNgQvc+mfZWc3vxJ7P72cRyT160K+MLBwxgUR0Cza baXA== X-Gm-Message-State: AOAM533e9dxsKfc5Kcb50if8VKC/UjLSMHFBGCTNFPpPnPi3VKPZb+IQ 1+1r0zBECe6ywXqUKz48F2x0W1qNy72/9g== X-Google-Smtp-Source: ABdhPJyzJAnYmSUu4X41HIZ87sk84CpEoji0I4RMbAIcNW2+bbpsh/Pm2k71g5nsVR4FnJcyEipmvg== X-Received: by 2002:a17:907:1c0a:: with SMTP id nc10mr10420695ejc.211.1636643477747; Thu, 11 Nov 2021 07:11:17 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:17 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 14/25] trace-cmd library: Introduce sections in trace file reading logic Date: Thu, 11 Nov 2021 17:11:07 +0200 Message-Id: <20211111151112.86751-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 0375afba..cc292236 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -115,6 +115,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; @@ -154,6 +162,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; @@ -377,6 +386,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; @@ -3493,6 +3554,7 @@ void tracecmd_ref(struct tracecmd_input *handle) */ void tracecmd_close(struct tracecmd_input *handle) { + struct file_section *del_sec; int cpu; int i; @@ -3532,6 +3594,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); @@ -3976,6 +4044,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 Thu Nov 11 15:11:08 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: 12615059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4A3BC433F5 for ; Thu, 11 Nov 2021 15:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB77061108 for ; Thu, 11 Nov 2021 15:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233891AbhKKPOK (ORCPT ); Thu, 11 Nov 2021 10:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbhKKPOJ (ORCPT ); Thu, 11 Nov 2021 10:14:09 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BFCDC061766 for ; Thu, 11 Nov 2021 07:11:20 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id f8so25637365edy.4 for ; Thu, 11 Nov 2021 07:11:20 -0800 (PST) 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=Pfjl6ms0+IyDnYH4oSxODTgbz7DSil7eApxt+buJR1w=; b=ES9ygzr9ClqwFVAiSldEK/UMXvo3H01kFYJ8viNFuB9i6laa79liyvQNSCOr5yvySe xXtnJGUPrx696A2yzKymZ8QxLQthKEMSNRoV0IRPwFcdinhCRbcCBm0cY+aSYtoG6TGX +1ADWvwfU7Iad+Am5WKCx+A211IhAu2NypvO0UM6uy0kUedRklKm54odMFW5SIz1kr2S pbYYUsM+RXxvWgwEp9zRjhzel+/Jj3tk5NhoYF4s9H7OKXZak3pzfxAebT5SXH7opYok Q+7n3RRgE9UIsZmFpCI6bTurT44R7AFwdBuuPVMe2ex2qkIrOI48g2R0UBDkdJA7j4C+ SAfw== 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=Pfjl6ms0+IyDnYH4oSxODTgbz7DSil7eApxt+buJR1w=; b=CmGyRdgqmwTvpXJNCSaaD4A6eGe8Pf+k/KMG2z8wnVpYDjFKDyvxw0ccbXtp/c7OHg GVCkn+c4JLbhYHWSAHVZBXqfo9xTuDJR/qZaDYEjVDDDZYRnCNerqKkRy+oVxfdJfeeP eNTh9gyPDczGPg3h4GPh1XSg2iqVA6owcDcm6BRjgZk9u0kRxCsEk4xHarDGEpaW1AAt 87+kcm8e7ABD+S9G+QgAV/CogL8IaO0rtN4Ffhc1AJUySoYcvZaAe05z4UUIu6ik5LXp rn9fPvbj4vw5b3e13u/2LJ0ESJILI967waUEOAuMr/L9qfk3vPa1RlVERgFo8/KgMhhK HpGw== X-Gm-Message-State: AOAM5306Mxx9TqLxnt8sIn+6ZSSP48yeuGyEIusF5V5q5CocyAmz9+ce 1DzDBktrVj1kTHSJmdC13+Wha3mi/rOx6w== X-Google-Smtp-Source: ABdhPJyBc2CevEWu/ug5vCuZQ8xA1LXSSagIB0D7WpwnTWamFLt4k3l5pBeV5SDoW0FlBZpzkACyQg== X-Received: by 2002:a05:6402:2808:: with SMTP id h8mr10757077ede.267.1636643478748; Thu, 11 Nov 2021 07:11:18 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:18 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 15/25] trace-cmd library: Initialize internal sections database on file read Date: Thu, 11 Nov 2021 17:11:08 +0200 Message-Id: <20211111151112.86751-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 8159c2a9..1a43b7e3 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 cc292236..75cc083c 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -165,8 +165,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. */ @@ -176,6 +175,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); @@ -448,6 +448,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; @@ -491,9 +495,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; @@ -654,6 +655,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; @@ -694,8 +699,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: @@ -727,6 +730,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; @@ -810,6 +817,9 @@ 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)); if (read4(handle, &size) < 0) return -1; @@ -844,6 +854,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)); + if (read4(handle, &size) < 0) return -1; if (!size) { @@ -2876,6 +2890,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; @@ -3060,6 +3086,11 @@ 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)); + + if (read_data_and_size(handle, &cmdlines, &size) < 0) return -1; cmdlines[size] = 0; @@ -3349,6 +3380,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; @@ -3388,6 +3420,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; @@ -3412,14 +3447,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 Thu Nov 11 15:11:09 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: 12615061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45BBBC433EF for ; Thu, 11 Nov 2021 15:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 236ED610D0 for ; Thu, 11 Nov 2021 15:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233616AbhKKPOK (ORCPT ); Thu, 11 Nov 2021 10:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233880AbhKKPOK (ORCPT ); Thu, 11 Nov 2021 10:14:10 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D70AFC061766 for ; Thu, 11 Nov 2021 07:11:20 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id o8so25323358edc.3 for ; Thu, 11 Nov 2021 07:11:20 -0800 (PST) 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=I09wudgEnThqsxiNXmxXrtQhMmFMUsD5LAbnumUjoP8=; b=XndKcvv4QCXFzEPktCio1nvB3xe/+A6XFhHLlRRJ4ljEoGGhoiVESyTz79yFalESQ0 XX1O2rYHCWykl9Ghs+iJ6jPPgC0mnKnlSL1XJsY3CfBoSQzj8nPdu1PjnPguEV9IgIys ZBykNrQyY9EAG/zSVj8aC99uL1qx5hAO5dBf4QXMUCfld0uTC2Uxiuq3diARFyiXpi/k WMVQqJdoFEv3Om31jNVQ/FMj93wIh0tGITYxx1W3kqKtJUUasX1dP4aZzD1uXVXaD7ON 0GJC0ZNdfAwWJhjAr/SQY4e5KPuJbznkpq/ndeEgbxssA4GACB+VvtMx6O/0m5GIUrPN qYpw== 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=I09wudgEnThqsxiNXmxXrtQhMmFMUsD5LAbnumUjoP8=; b=az5MqHUQymZo9JDH10hP8kcmCcriYT7HipH0qSwsTOkNfx8oJh6LAKPJVqCM0znFV4 I0u51pBRaEjF/PD1xiZX4Tg43rI9VZSkm4d/pA6BTp+4oYzkPOQ5OjUpBFdaR8q90Gt9 bFnRpOeI96N8voFtaPZxYT8M2NIz8kz1W+oWZI33UW1pNnhXjLTNRKUgH562dnwZRXbu y80SK7t56fxc/RBECAD59Nh0t8LlLPctq9yahMujqxjXRbSvMuNqD2BLEGfSbf67/8dw sD2zJYLWyR/ooUcfcE+CmHFwIUxEMRDqR3+D7YNUprDXIKYQpjeBqEbCVqrrdETk73UF jshQ== X-Gm-Message-State: AOAM532L4tOu0fQPl619yksRyzpQL867JEd6kzCpwfUal+/Tf2xTMz7j NqSMSkDTD5oMtF0tasaXmNDcWh93Ql4Nzw== X-Google-Smtp-Source: ABdhPJw0efyOedUtnYl4FkrgyPrbC2WI+6CsUpXlbyj3ij9Klp5a0p0OSATgtN8L5zAZC5jTLD4/nw== X-Received: by 2002:a17:906:c155:: with SMTP id dp21mr10014180ejc.325.1636643479525; Thu, 11 Nov 2021 07:11:19 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:19 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 16/25] trace-cmd library: Use sections database when reading parts of the trace file Date: Thu, 11 Nov 2021 17:11:09 +0200 Message-Id: <20211111151112.86751-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 75cc083c..03b044dd 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3268,21 +3268,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 */ @@ -3886,6 +3891,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) @@ -3901,13 +3907,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 Thu Nov 11 15:11:10 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: 12615063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C4E7C433EF for ; Thu, 11 Nov 2021 15:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21C7C61252 for ; Thu, 11 Nov 2021 15:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233937AbhKKPOM (ORCPT ); Thu, 11 Nov 2021 10:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233876AbhKKPOL (ORCPT ); Thu, 11 Nov 2021 10:14:11 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEAA1C061766 for ; Thu, 11 Nov 2021 07:11:21 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id m14so25734379edd.0 for ; Thu, 11 Nov 2021 07:11:21 -0800 (PST) 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=xjkf1Pq0zoaVyPCl2/feBUbTs0yHFu+S1iTv24D8Fg4=; b=TZLiaxECwvjWvtPNkb3JB3CxgxtnhXFFjrD0DGnvVnEv5Z75Ez9pPkEphNBKd7+hF6 iPUVemkux/PJvG/vFEAKTaScvbatsCf9PRY2+iOQIIZGFSIVOeKRwZXlxhx8dqBXE1t9 O8AfcMsifxuwb40IV1q2tbxST/DKc/Y3S4d8vVoJq49MdLqw8B+f4Li5jDHVcaOwzR5j y9Cec5it5T+wYhFlOHYmPQnWy6K2EQiJld7YjeaSvKSpSasu+Qc11NqNZzGlkajN+3qm BhTUgJLUKEMyW2pCuV0hPcb5STMYO0SIM365iRN6yPgQZxfw6ohENzudzlWTj1dGEial 00pQ== 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=xjkf1Pq0zoaVyPCl2/feBUbTs0yHFu+S1iTv24D8Fg4=; b=3SVk93+oLCrukUruuGVqnfKoxxrzCxFycQZAlOopGniA8pUm7ogo0b1yfB0xGvGgYJ p7L+qgl3JAo6vaXgTXfFvMAWWESI60KhWBh/WqafTcqxg0+SgdosCf2xEwSkVEBGnVIa BwBBFG6fSZlSEuuiGv4ckdnQX03Us9U9grbxh16+7DSqp6dxtOFu6yVgP4UZi6TEVZpK kNs/YPPBkxNGnVtYyJPXQ9X8psJKI63KJzt1oBUeVz2REq9vKINJRwMygBky0Y3ADDpR EAmhDc4Gd0foBCaZ3PNuRyqof8JCg3g5/PAbmVAffx6YlJQCL3R4oyQ/0ihduPTKTTPi uq2w== X-Gm-Message-State: AOAM530EqWs7f6xjwAOq1/1LeqHkUrku47j4AQg89850KbfSfHVwFKws IplE8hEdnM4Yaxwtx3hbVdOLVJGNZhWeAQ== X-Google-Smtp-Source: ABdhPJy8BrbPINHaBQ1aIH/iUKh3/GJAyAtmZVAskjpWOz6Yi5HvjooTngpXU6sWboVoLchlJH4u8w== X-Received: by 2002:a17:906:dff1:: with SMTP id lc17mr10023243ejc.215.1636643480485; Thu, 11 Nov 2021 07:11:20 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:20 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 17/25] trace-cmd library: Read headers from trace file version 7 Date: Thu, 11 Nov 2021 17:11:10 +0200 Message-Id: <20211111151112.86751-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 03b044dd..845604fd 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -163,8 +163,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; @@ -917,19 +916,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; @@ -995,6 +982,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 Thu Nov 11 15:11:11 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: 12615065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 899ECC433F5 for ; Thu, 11 Nov 2021 15:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C7FB61268 for ; Thu, 11 Nov 2021 15:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233876AbhKKPOM (ORCPT ); Thu, 11 Nov 2021 10:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233880AbhKKPOM (ORCPT ); Thu, 11 Nov 2021 10:14:12 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3FB1C061767 for ; Thu, 11 Nov 2021 07:11:22 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id x15so25505381edv.1 for ; Thu, 11 Nov 2021 07:11:22 -0800 (PST) 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=MQCB06I/EtGz7Qh7SLxRkLwXJYbA+YYAXabGdtanql0=; b=QwvzNzQ7hjEQ0IWdBGAw7zViA/jtBSRcI9ISbrx8oxdehFGuaxG8QmnMDYEagrZpnQ oSDjaDpdvmQkvQt/14H+GVHdAmLJup2fNmLcOnkpp9Ft9Zz5/H+cCyTxJquFHANU+uQJ Ppx7VPlPSEpUuYQGAJbSiSQPVKpOvYyXKwzAH3k0Eq0apOCUcvyZilZD5UnEOtB+znNW YutDMe9XiKKnKJ7LaT68mHmWZpKKFHVbWj7PssbAoSZC11xNB4k7oxsQwXRBZAzzz9FG ns4IHcnPyJq3gCvPR2baQVXXGxFh21TmIUvb318tz4rsk3SOLkkl1j8TRPsoOM9hlT5F 4Wbg== 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=MQCB06I/EtGz7Qh7SLxRkLwXJYbA+YYAXabGdtanql0=; b=YAHZDGLJUL7mD47wkl0NOWbi8JBjGHXp363XQb7N04bu+6vXq0YHjP1Ix3XxDKYaN4 RU7H9T69WWKV3ICz/0ZUQnocq8Yl1FwfIek3IcUNfsCDE9MjhVLdB6B6TrZCKSVd1aQK m5kcg9t8NCAUXPW62MeZXxvVBw4iQruIOOYVffQVwszR/KeyAFWxNgh6jwEIlBQLGccF jWe0IqcjYoxfDSf3rN0wYJV+9S/4n53ekK0ZFsapqzWHeaWjylky7qWLDoyWLcj2SRHR 92H3Nh96vfNyPTxAes/r8Da70y8ye1G2cBKLxEabIlZd3sYuYlGqMDSa24v5RCwLBD97 UPMg== X-Gm-Message-State: AOAM531aBUq3aT/215P/MEAXk7wjKEa2QszNCkzuR1ZJLYKr9x7IRGnS tmrpml9tUJfusaRiPOpBE50u6iwGs5RQow== X-Google-Smtp-Source: ABdhPJw5a1XJnIcV2kQ2bXIgVXYosrypknRXdcbGruUdNuNyunFeTFB/9fklUxKK3jZUxsIreZ4ARw== X-Received: by 2002:a17:907:96a4:: with SMTP id hd36mr10312700ejc.407.1636643481354; Thu, 11 Nov 2021 07:11:21 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:20 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 18/25] trace-cmd library: Read extended BUFFER option Date: Thu, 11 Nov 2021 17:11:11 +0200 Message-Id: <20211111151112.86751-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 845604fd..5644cbb1 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 { @@ -153,6 +163,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; @@ -2847,13 +2858,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; @@ -2944,21 +3051,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) @@ -3702,6 +3798,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 @@ -3757,8 +3860,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); @@ -4202,6 +4306,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 Thu Nov 11 15:11:12 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: 12615067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5490BC433FE for ; Thu, 11 Nov 2021 15:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D91C61284 for ; Thu, 11 Nov 2021 15:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233940AbhKKPON (ORCPT ); Thu, 11 Nov 2021 10:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233880AbhKKPON (ORCPT ); Thu, 11 Nov 2021 10:14:13 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E1CC061766 for ; Thu, 11 Nov 2021 07:11:24 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id g14so25472645edz.2 for ; Thu, 11 Nov 2021 07:11:23 -0800 (PST) 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=hHfTm+q0hIJsvcA6EowC9GwJNGvO99FGPnegvkyEvUA=; b=YCWwxmPadIl/4t16099UoCs1ZCu23O7IssDU/WyqUKQ6pFJhjSjaB8P6HZVo2pffzT L/dJk6Gbe0X17aqjkHjwDZ+US5PfrF2u1hi/2voOuTvNqD4xgmIsVzN1XI6ST3FeiAtF gR6is3Vl40nl/ORR5TV1xob5KNUZ3BqRR7sHNLRxrbdLMPm9TeQtVNqdcGCYLRQhMX22 +lgXNIV8t21H1Pilxxk/DiRhtUM4EBN1dgadoprc5C184ITiYv+JQrfsh5Smd1wcM6YS YK/+ID9QCt+fQb29cYwwv3I+zEx5NQ4sWaK7QnUkTlNAri+8XDIvr7NqsD3lPKXpn+Y+ /foQ== 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=hHfTm+q0hIJsvcA6EowC9GwJNGvO99FGPnegvkyEvUA=; b=QR3+dF1dt7/liH72YJ/Kq3irfmyAtxljLqY7nfwPDT/5cXC5Qdkqdo0OJcoawrAkWp F1ofwZpptXHfoZynmwKoJt5Kt/TYN3T6+oHQmMgIYtJC0ckBqYFj5GMlcTV4+0ya+Sub zb+JOoqwu4MdKq7wa1j5WqwLkorKkq6LjQ//zjldFJRuh3cn5LzkPqY594TItGJy2Fuh H/uIZcqrwH/JyN6E201Gwgw5n1wKKHj4vUSAgmSuCpPzRs7igTicb+bWgJRiRQhf1WiT VSI+qZQ3y+4YCBYdLVuxrxNmHMEwyUnfSLMYdL5NR/q38Bg4LzcCTbHPI7WN0vBcojwT z3ow== X-Gm-Message-State: AOAM533WbLZfXGQ/i30J5wTJEl/sZicef0apVImp3OGYLusXWvofB++w dRHysubobE3P/v+O/k+FBWQq1dvSWDQh9g== X-Google-Smtp-Source: ABdhPJzXhbDTEkvE9lfTGM/sa/0j5fGoDZB9LzMPXX9/6ekhVUDfiK0aduumsAcIAFRi8Y/fbkr7Dw== X-Received: by 2002:a17:907:7ea4:: with SMTP id qb36mr10641471ejc.146.1636643482215; Thu, 11 Nov 2021 07:11:22 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id nc30sm1648803ejc.35.2021.11.11.07.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:21 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 19/25] trace-cmd library: Handle the extended DONE option Date: Thu, 11 Nov 2021 17:11:12 +0200 Message-Id: <20211111151112.86751-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151112.86751-1-tz.stoyanov@gmail.com> References: <20211111151112.86751-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 d3760483..4b26960f 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -51,5 +51,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 5644cbb1..06f31679 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -176,6 +176,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. */ @@ -2858,6 +2859,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) { @@ -2960,19 +2985,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 */ @@ -3112,7 +3145,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 2ed7155b..1d666775 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2154,7 +2154,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 Thu Nov 11 15:11: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: 12615071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C60DC433EF for ; Thu, 11 Nov 2021 15:11:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F37C861108 for ; Thu, 11 Nov 2021 15:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233963AbhKKPO0 (ORCPT ); Thu, 11 Nov 2021 10:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbhKKPOZ (ORCPT ); Thu, 11 Nov 2021 10:14:25 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 225FCC061766 for ; Thu, 11 Nov 2021 07:11:36 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id f8so25640198edy.4 for ; Thu, 11 Nov 2021 07:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iIxlhgt+14VbKiQQaMNschK6klnH6cdqPSrXdBAV9kE=; b=kXTtAqMgS3Tegwb96/t2znmNdCH6fjS4EhrqHzJ9ASG1MT/W6W4kl5eSws9Fs25CUv 4oBdyuopKJMcw9pJOm0yr5nRsME6HIletHhXd8WGroaSnLEu13fxKLpElhj2xvI7YIFM Yd5Nq/WZ36JnwV/0qMDPk+k4jTBlU4lHCNU7HsxqnVD6tr6RNWEDKkbap4YyK2aQK0XC zdqCgOfZdH/Q0j/ZY6JvSffWInn7ZYj8lRL6uFV7fBvJuGwh6V4MVRLhXy4rhgYMe0KA ec3RXLzbCspyLy/7QD4jjNVT36Y+rYMfTZvXLpKCnFD48cfkg0JXJEsdotDqqySXXJHj RwMg== 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:mime-version :content-transfer-encoding; bh=iIxlhgt+14VbKiQQaMNschK6klnH6cdqPSrXdBAV9kE=; b=kFXKNT7FwqtmkS38EnmNg69I8KhbczK1yRnOQisSQjpRaibXQTcBQZKVX7jzchyJQF p1M91YxNRAlVLrsmId5UVzqPhuR70LWMHUydZEXREQLNSRgaPbetSF+ddNAf1C2fqJ43 +Q2qcoK754bUtx6cu0nSOpoOZNz2u3MCcW+Xz1jl+9yt2re86xUeUCKj1W5Jzqc7cmLi YXxm7YxJQW/fqEN2iBqalBfVguAznlcLGIqMM7R2qg8vaQUfGp6b2Faz8W5kcEb/9UG5 zL3YzR/wgQTVbazu/UM+HoZGs9cJBKIPc+lLJ9+ZxN7cIOV/uojQHFkPtRFflOb+ym8J G2Qw== X-Gm-Message-State: AOAM531CXoI98elwEgy5jiGjCRNN6NR8vUo0SZSuj5d9XA1HQIL1WxiS d+Gq3wpAMUER9Unh8xeMpY15CwMGOmQoDw== X-Google-Smtp-Source: ABdhPJyvtWvmdbcd35HPUzjQEdWeyL3jvq1OF6S07hLkGxrsfMRjczFGGu3aPtg/cUyv3b8McRXj6w== X-Received: by 2002:a17:906:2b12:: with SMTP id a18mr10350600ejg.254.1636643494605; Thu, 11 Nov 2021 07:11:34 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:34 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 20/25] trace-cmd library: Initialize CPU data for reading from version 7 trace files Date: Thu, 11 Nov 2021 17:11:28 +0200 Message-Id: <20211111151133.86788-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 06f31679..5d9f24e8 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3193,34 +3193,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; @@ -3235,32 +3219,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 */ @@ -3278,6 +3244,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 @@ -3297,15 +3358,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, @@ -3403,14 +3456,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; @@ -3432,7 +3478,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 Thu Nov 11 15:11: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: 12615069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6B54C433F5 for ; Thu, 11 Nov 2021 15:11:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD6FF61252 for ; Thu, 11 Nov 2021 15:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233819AbhKKPO0 (ORCPT ); Thu, 11 Nov 2021 10:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233978AbhKKPO0 (ORCPT ); Thu, 11 Nov 2021 10:14:26 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2BCC061766 for ; Thu, 11 Nov 2021 07:11:36 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id v11so25472765edc.9 for ; Thu, 11 Nov 2021 07:11:36 -0800 (PST) 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=DwtwwL7dh2VcFONxh8gCuF0yFXryF4H9/KX4SKY0LRs=; b=YQb/Ro//ZoyUucLei3sypfNAGkHlC5gPoNZ/zfcZzn7N5Mr9ohKdEKzmh0htki8YFA 84PPpIHGy0v+Tpo3OopWlJ2ar9MhZhmcPRfAPSGq3qP+vud5DwT3wxnkvqjoWt8QMlrZ MrWtSVCGOG72i1OHEZDI1JXibRNXqY3UpPnu+NjlLC8fnpa7VJyjz1u0KhzJ/X3qdvrc fdAcundGI6tyTwZLxbqktdKfEj+nCH1mJljWZIZZmnLjByD4aj9sPXbF9G6eAjkkpBmT JVDdmTt9tpOxmBSrzWgpgLG3bUuQO24CRBtqiiVSyYseLMWlDqE8HFoA5ky0dcZnGLmJ 3NYQ== 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=DwtwwL7dh2VcFONxh8gCuF0yFXryF4H9/KX4SKY0LRs=; b=bnxEECdiJJ+1nVaZyUTU6JsGUljUbiM/xGnO3aYzjpgh+0N98IT9g+FI6lzIAwWio2 xHlCxQHyNmMzOBGVfm14re/Z56+wQuL5LPO4RYmseMLe+jGTiusa9JwuXxr4w0jMUN1Y Ts1tXH/hBInXfOCjKiIq7tIVRLDipL19e1AxAXEUWsR+02XRFgHf/bRPO/noQpU9mBJH pWkjNovk3zspnYqOmjhwrq7Rnt9CMYoPxsCGaO/InIrO3aqGyO1U34bq0+qJYyA0bSWV m/iepdr0uBbmzx0n0Q7rfSBLZSEah1KVkNXGruYCE0SYivZoJa9ovti9ofRUdDCU/EWU SpOg== X-Gm-Message-State: AOAM532/lMfVqe1BC7BiWbRyAdRO6EkFqfd+CpsU8OBj9OOMFR+sO+Lr 5iEmJ4PSR1e3Cb4nxARMC8r4bS5SIKA/1Q== X-Google-Smtp-Source: ABdhPJw/NFP85PTrk2JGbYkmLiF0FJE+IctxC7ItE0B1anDAqF/PfF/fRe5WSkCAlQsWl1KITZmB4Q== X-Received: by 2002:a17:907:20e8:: with SMTP id rh8mr9916437ejb.437.1636643495514; Thu, 11 Nov 2021 07:11:35 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:35 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 21/25] trace-cmd library: Handle latency trace in version 7 files Date: Thu, 11 Nov 2021 17:11:29 +0200 Message-Id: <20211111151133.86788-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151133.86788-1-tz.stoyanov@gmail.com> References: <20211111151133.86788-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 1a43b7e3..879640ac 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 5d9f24e8..5efa4859 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3193,6 +3193,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; @@ -3255,6 +3273,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; @@ -3269,7 +3293,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 1d666775..e06931ce 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1778,7 +1778,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; @@ -1793,6 +1794,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 32270e20..0b1dc508 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 Thu Nov 11 15:11: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: 12615073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AC8CC433FE for ; Thu, 11 Nov 2021 15:11:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F190610D0 for ; Thu, 11 Nov 2021 15:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233980AbhKKPO1 (ORCPT ); Thu, 11 Nov 2021 10:14:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233966AbhKKPO1 (ORCPT ); Thu, 11 Nov 2021 10:14:27 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7A0EC061766 for ; Thu, 11 Nov 2021 07:11:37 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id f8so25640579edy.4 for ; Thu, 11 Nov 2021 07:11:37 -0800 (PST) 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=JvqHtw88yrWLlnBBs4NeaE4fixoXd7d33jNCQmgnuf4=; b=ea0JVQnF2MZSi3/9M7vSyqU30cV9ZcXaE4pDct0I+Dl7mX4iKMIUIE06qkTbornRrr i8fxMCLSgxX99/u5YRzoVM+Lysp0g8g+08doY8fJYLVMyGUldE4KojEFIvNc4MfayD5P 4YFqSqdKrlm3nzv4BjLiiLfTv5IshxK12qBUY37CdptEdBMuRjoDgl1eJyuirPlSb2ie jBKUfZbzr66GG6xIUiupEH296QH7OuWBDTFkKBmhYoQlgs96lxsZlgnXEXQpwNDjPVP4 GtQ1O0EcFZDwu0honMqXsaM57Wb4ZcTxAvoopzRe1ettYnS7Pg8y7RHrhXsvQQEAqOSz bVGA== 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=JvqHtw88yrWLlnBBs4NeaE4fixoXd7d33jNCQmgnuf4=; b=jEtN9qJ2sv0XVlPngRBUU5c/pwzvIfAiUtgfbTJ1NwmnD8aZGuNcEwatOQswD8pAYZ gzcpi0VTvwXsD/IMBm5jbiYWh6QZpi9O/wPX7NF52/zuTjfGbIEmaJ1JbhJtI9b5BSRQ TOAsSvG0cMs+TSTpYIs58E/PQm7araM/LgDD1HZ1gswRNBMvv8bdDfXwn0OEVdhwXBLL oCbur6rqob51LVN4HxlDQeVRsLjn1YtIP2TsW/aFiSy7g4eCksgN6UQ8Tf9aW2UQOxyN z30IzoosRYzwqCPS5TIScn4j+hk3b3V8i7zXvb4Y9booF3BH17rWX/1JlQQIJNJ/+L0Y EufQ== X-Gm-Message-State: AOAM531PU7EHuiavPEhH5K2jjpm13/LUF8YaE6Oi6cXvpxAZofBRnNYh derMsuRvjvKcULkkpQEDVoU9AM+RRRD0aA== X-Google-Smtp-Source: ABdhPJwHymjUYm/9NU6F8VM1UcjU+31Z0h27xSV3gObcUWoIn+sGSIQYI5KoJ4QJPx49ycCnxfKZiw== X-Received: by 2002:a17:907:6da2:: with SMTP id sb34mr10416840ejc.509.1636643496557; Thu, 11 Nov 2021 07:11:36 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:36 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 22/25] trace-cmd library: Handle buffer trace data init for version 7 files Date: Thu, 11 Nov 2021 17:11:30 +0200 Message-Id: <20211111151133.86788-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151133.86788-1-tz.stoyanov@gmail.com> References: <20211111151133.86788-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 5efa4859..f9978dde 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -4466,34 +4466,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 Thu Nov 11 15:11: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: 12615075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC7A0C433F5 for ; Thu, 11 Nov 2021 15:11:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0EBE61108 for ; Thu, 11 Nov 2021 15:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233975AbhKKPO3 (ORCPT ); Thu, 11 Nov 2021 10:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233982AbhKKPO2 (ORCPT ); Thu, 11 Nov 2021 10:14:28 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E536AC061766 for ; Thu, 11 Nov 2021 07:11:38 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id f8so25640737edy.4 for ; Thu, 11 Nov 2021 07:11:38 -0800 (PST) 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=+Am4+85r5pphMq6U5RFqrZJhdEeMNK5Aw59BnYLZDBU=; b=OYzI7E1ZjL9gbmhDMkCNxOZGbsRNbya6e3gEdulnxSBvYc+wrGNMxGkQmrOc8PYId0 8H3aOgSisCfG2DFEKNGXrHDOOxLZxG2npZosjboiBVpeOd8wXUF097x7F7IEq5znhyJC QpiG3SSUG01tMJjDftfFZPR11Ezw1EVkns4WtryanPNT1/GieSJARsGdeghKJmD7luqo trahIPqKzw3YLF8OJYev7BXVobSnvuhB4nunpJfv/3b35N1+5S8Ymp2GpXqWIkwPFhtu X2psprY+ppq7IjCIGZy44+N5mbkffoxaceY0Lt8rs9qdjTk73WIoLVtBWvA7D8TIQ0V9 vJOw== 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=+Am4+85r5pphMq6U5RFqrZJhdEeMNK5Aw59BnYLZDBU=; b=Y5rPIj3QiC9rre7kHjcxxirygX0xrArgt47VtGkAusM2tVDeNvNjOBq80k8kczmra+ oZmyTUidlIkjj/7Xvy/+G4X3CiVT2U6FeF8JLnqUhNMEOGjVSA+MzI87rnVzqjfE1B78 SX+so31OLuzMsVR0doZpVnSzYmcw2Po59Z6Zs4u0NdO4DHegVyGSKpc8vJJVGuGBiNi+ xLZzuYoHT7TT64ncoeEKxidbXh9Q5L5FW6loKu2I+4m13dGrkAVEIP6CQV5Rx/0bW5ul rz2EhtR05SGzcPuAr6VByOumACvl/+NUhxlggVw2zx1r5IKpLjxCDViHNIbfW4I1WoYT yYug== X-Gm-Message-State: AOAM532Lms2er4vInipTAMWoeKslRTuXGcowhCkdIqDFjkKBHiXDWxqC s1RiLFzaT75FKDHFtY91gc/n0nFBqQd8Ig== X-Google-Smtp-Source: ABdhPJwu2IY350PbkXL1F0HAJ19YB3KFyGFRZMNnW61KrUld6ByLuKk3H3bxmvaqQSInE422VWcINw== X-Received: by 2002:a17:907:8a24:: with SMTP id sc36mr9887552ejc.530.1636643497540; Thu, 11 Nov 2021 07:11:37 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:37 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 23/25] trace-cmd report: Use the new latency API to read data Date: Thu, 11 Nov 2021 17:11:31 +0200 Message-Id: <20211111151133.86788-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151133.86788-1-tz.stoyanov@gmail.com> References: <20211111151133.86788-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 Thu Nov 11 15:11: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: 12615077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74ABCC433F5 for ; Thu, 11 Nov 2021 15:11:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A7B961252 for ; Thu, 11 Nov 2021 15:11:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233887AbhKKPOa (ORCPT ); Thu, 11 Nov 2021 10:14:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233966AbhKKPOa (ORCPT ); Thu, 11 Nov 2021 10:14:30 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E9DFC061766 for ; Thu, 11 Nov 2021 07:11:41 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id b15so25220843edd.7 for ; Thu, 11 Nov 2021 07:11:41 -0800 (PST) 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=vmpYoO2hKc2Tt2B2GzLnV7lLQyhLhdSoGSsv86S+DsY=; b=FCTyxC/o0yRJJRli2Io9vlnYEkFX8dqBNSGqnsNbbZ9pe/EUIml14gQb8ybReO4/7V +di5EWISlYr6BFKZWp7dqWTqx7xtGCerbxHDCyv5NOimlLJei+jouY25N/qObNuGdvxj LA9uybIuaQA2YaL2nmOGqrwy+ETuOkfLLFhZkg+UMLr/ZPsZI/e0ScHdiAlfkAWEulhU 1Tz1lgS+d0x3K2d5E9AdTz4vH7x5gHYJAfBGmdDgM2z2oYirUT7LlKROFLz9C7RkQS8s nVshE85KL6OlR6fEyH0SIDFa1SIXU2IucT6e/1OqkJZ9qC8B50452s3ouSWRkLP4XoMF zjxQ== 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=vmpYoO2hKc2Tt2B2GzLnV7lLQyhLhdSoGSsv86S+DsY=; b=56z51P/XwBgjHj/vY1Wuo0czthEWbTcMMwZz/OVg4Srrgxv1yrSI3JubfKGE0wTIUq iV1Ljq3txcMQo55N7H55WYvKz8LVyC3i8gDX6nuylw3B9r5OzSgCzMchuKN3DiZ9njBr 8t8L44BrSORlLNq2/Wdb/ZxCT6/WVg7taUd4v+UkAnNmO2KYoeMQQHZGcGKt+hjXksGb NtwxQTsCwERepfUpbae45HsD5NdDd0KVBpsXrSGHWN1dYGS7E+QwTO9uGx7MNLiKqMyq ra4EmIqBEEGVa7XSEmeJnyzZqKg+twgSS5q+b98rSTOxTgPWwjno9Yd+Pz7GvFeRL6Ff P0ZQ== X-Gm-Message-State: AOAM532FriZyMcIWw5BqoIygFrvz2xfYc8+piTBQVtb7fg5ns5XZXu5f HN06ceAztmStOvL9PmpCXDnLyBXMciEjRg== X-Google-Smtp-Source: ABdhPJxqDJmPzi4alyaYtWkurBJRKGreOSNylIBjCdAYOQWEafUeeYIoFcv3IcVd7KvINeeERL7hsA== X-Received: by 2002:a17:907:3e10:: with SMTP id hp16mr10649766ejc.477.1636643499720; Thu, 11 Nov 2021 07:11:39 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:38 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 24/25] trace-cmd: Call additional APIs when creating trace file Date: Thu, 11 Nov 2021 17:11:32 +0200 Message-Id: <20211111151133.86788-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151133.86788-1-tz.stoyanov@gmail.com> References: <20211111151133.86788-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 45ba1211..28be6e7b 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, NULL); + 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 0b1dc508..338a6a8a 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 Thu Nov 11 15:11: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: 12615079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E050C433EF for ; Thu, 11 Nov 2021 15:11:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6957661252 for ; Thu, 11 Nov 2021 15:11:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233981AbhKKPOb (ORCPT ); Thu, 11 Nov 2021 10:14:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233966AbhKKPOb (ORCPT ); Thu, 11 Nov 2021 10:14:31 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D57AC061766 for ; Thu, 11 Nov 2021 07:11:42 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id m14so25737864edd.0 for ; Thu, 11 Nov 2021 07:11:42 -0800 (PST) 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=2smVDvmkjZ6dm1UyFu0+cAFXuWC1Wi6DodePOZPCsYo=; b=fsEPA2m/vEXTBVxObfHM5rBGY3KF7D0/ltKYHuxV0uPgbEZUPhsw6TqWdZS9GK+FpN TbQ1msxmAMSuN1OTNvKlwcHAIbqO71BbR2WZIuBDcODOMX+7yedxNrAlAHivoKFpUDLe G+NxdAw3n1Zqs7xCDKNQb4482QMAzqRzdzChV8ZbekLMoqyHXO55CtoIvHkibOVdIgu7 lz01PuHP2DF0P37N4+STfBaf94loxuNFTNEhPwcOIOiTfU9X1xqKGSEFdco0+fMJwMaV 8bs78NDH2jn0/QVM81W2zvVyIqcCXkUOh7dEt126vZkcvTlCpj5omrlLsL2R3IbjYijf lr2Q== 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=2smVDvmkjZ6dm1UyFu0+cAFXuWC1Wi6DodePOZPCsYo=; b=uDKTGtdvba6qiQ5id4OOKj5N26ntmjxS4G1+rjP0okSHZcs2kSqbcokyIiQEwJDHo0 YuPs6aBl1rBL/pmVNGRADCNh7BwzuRdoRMLOPiOyFwFnKI01fjMtYiIW668194y5tqME BSIKTJ3ioqQIPVGIaZmZWuyiwYJ0kpqyJfApfkkCs+xP6Paf3OOWs19X0FhUdpHPb/OP cop3fhdamYKTi3mGiVwVAaZ+MAGS2waGgRMOx8SFp5nTFvKY5alWV6P6O3c/EARQJPkX 6ariLIcugHZgYxh7m1GNBhlFEf8ArTKHFR2/UT/9pmPWWYE/ArncE0ycSlqNjlIfaJ1U RUJg== X-Gm-Message-State: AOAM530sBKZKRhBUbcSoQ/jAmbH1Djp/QPdFBP/Xd4pLxNZv+Ippm7+D UCKyfOYvHpqXqsp+7LuXwzkwXI1Wze4kNw== X-Google-Smtp-Source: ABdhPJxEYLGwAy1JzoxRqI9kLr0rAb2kBdGpvhJnFLemtmzf1gNe6Q7QrhYzsxPevv/WdIK1tcLSIg== X-Received: by 2002:a17:906:fb17:: with SMTP id lz23mr10239529ejb.149.1636643500731; Thu, 11 Nov 2021 07:11:40 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d14sm967018edu.57.2021.11.11.07.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:11:40 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v5 25/25] trace-cmd report: Add new parameter for trace file version Date: Thu, 11 Nov 2021 17:11:33 +0200 Message-Id: <20211111151133.86788-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151133.86788-1-tz.stoyanov@gmail.com> References: <20211111151133.86788-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 338a6a8a..fab34361 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",