From patchwork Fri Oct 8 04:19:54 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: 12544285 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 18ABFC433F5 for ; Fri, 8 Oct 2021 04:20:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01F62610CE for ; Fri, 8 Oct 2021 04:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237588AbhJHEWT (ORCPT ); Fri, 8 Oct 2021 00:22:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbhJHEWS (ORCPT ); Fri, 8 Oct 2021 00:22:18 -0400 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 D4426C061570 for ; Thu, 7 Oct 2021 21:20:23 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id d9so7364650edh.5 for ; Thu, 07 Oct 2021 21:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zZN0+G47jwZX54elKPFv0gjYbEfEwi1cIVE1yqMMANM=; b=NuW37Hlr3p/BEeNV9jc591w+n8QM9LooRaxRYAuZBEJSDJ512dxpH8+g06FsS3TITt LQcnMn8Lbz1kVz5eG33C8k3NK/nwvyLlq+ovmUniIOS2ZZ6YFE1PfLd5Uupz+jWfVHtf 72vKUPZgvP8znNCzDmG3CbwudkmfVxnpdJMPoiwWEn3LyaHai5z3dlK/bd++7ga1Ym5J A30j/xn5fAoMa060VyhJ1Qp8lWbLjdVh5C08aMqTwHAJNP3WLJzUUkyh6LjcMpEZKdwI PKfkHLrP/1Okk6vhtMnAR4/MWlykwDI6ZSblKn/a3REYRnpBDmSbj0IBZ/mn1YWsbiLq dyLg== 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=zZN0+G47jwZX54elKPFv0gjYbEfEwi1cIVE1yqMMANM=; b=HYkmMx/luJacfySN0sXVCr6hgpbJOCzNXGWE9WtkvzoXV9teLklgbufvlqmaKklN3H POoQ6H9uuh1wWw4cG8oVogLm4M2HOOHLEHJjtzQm+nhbxXPwQfHyTZbQuwsKkuFRU7bx 6PUDGolxarjiDCPtRGc/dHNw1kAHP+xXpDAsfnadhsAZ4Kc+gItF4O3qCWCZmZYhf06e aKjsWiqbJjOJptnERwT3EaNUx0IaHglsYZYHHmHfqyrPqel+d9eNN/IYUlRaHn6Iqm75 NaGqVIEU45Dg3L0gFVMvJlMhvOKJVvvrhnTpoCJkjHtAP77XO/wcJFC0OOEp4mMDlFje 8ssg== X-Gm-Message-State: AOAM532fvvsHCp78P66ljRGwgXbM5LQc7YDNRm6BFqILEl0nFnvGGwGq NLij4NtpO8ZGtqsXBkwfxo8CKqiSd4/xhA== X-Google-Smtp-Source: ABdhPJy5tX5y7fJOEONRr5zDEWy2xtocbR7ZJEVG7+4zK7K1i4vw4NNg2AHz1jTXninYMwx+6lqHuA== X-Received: by 2002:a17:906:2543:: with SMTP id j3mr1241254ejb.287.1633666822488; Thu, 07 Oct 2021 21:20:22 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id p6sm511669edi.18.2021.10.07.21.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:20:22 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 21/25] trace-cmd library: Handle latency trace in version 7 files Date: Fri, 8 Oct 2021 07:19:54 +0300 Message-Id: <20211008041958.976309-22-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041958.976309-1-tz.stoyanov@gmail.com> References: <20211008041958.976309-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Latency trace data is saved the same was as flyrecord buffer data in trace files version 7. There is a BUFFER_TEXT option which holds the latency specific trace metadata and points to the section in the file with the trace data. A new API is added to read latency data: tracecmd_latency_data_read() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 5 +++- lib/trace-cmd/trace-input.c | 29 ++++++++++++++++++- lib/trace-cmd/trace-output.c | 5 +++- tracecmd/trace-record.c | 3 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index a08890df..045fd5a1 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -221,6 +221,8 @@ tracecmd_peek_data_ref(struct tracecmd_input *handle, int cpu) return rec; } +int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size); + struct tep_record * tracecmd_read_prev(struct tracecmd_input *handle, struct tep_record *record); @@ -295,7 +297,8 @@ int tracecmd_output_write_init(struct tracecmd_output *handler); int tracecmd_output_write_headers(struct tracecmd_output *handler, struct tracecmd_event_list *list); -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + int file_version); struct tracecmd_output *tracecmd_create_init_fd(int fd); struct tracecmd_output *tracecmd_create_init_file(const char *output_file); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 511f209f..b1b4aaad 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3194,6 +3194,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; @@ -3256,6 +3274,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; @@ -3270,7 +3294,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 b21aaf5d..a3b75c08 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)