From patchwork Mon Sep 13 12:29:43 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: 12488775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00B09C433F5 for ; Mon, 13 Sep 2021 12:30:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0A4460FC0 for ; Mon, 13 Sep 2021 12:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240001AbhIMMb1 (ORCPT ); Mon, 13 Sep 2021 08:31:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240000AbhIMMb1 (ORCPT ); Mon, 13 Sep 2021 08:31:27 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9852FC061574 for ; Mon, 13 Sep 2021 05:30:11 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so5140346wmh.1 for ; Mon, 13 Sep 2021 05:30:11 -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=dlrgFnbNI5+Y8plmO2nBv6t6eiUzaCAlcFJIo/lxksA=; b=aHsp2boc4AXsEUXeWvBVIjl0ODiUU5cm17VsLJhfsgpTpc1QR7EAHQm+MuVBuWPX8P 3gQyEq2+kOOkbUZr36fV6o95Logp/T4u0Wz2ChjTqMYhsFUNSPqU08K2q+snX8QQ6lnn kkU0es+okV9FcmEOZ55RM4jPciQ9FVHqI8d0WI2fDD958Ty0XkI2eAHv7wDGY+yoSk2E qTCkY4g/DF4VkvhnO5+Mc8eu4NLXF6MJ92rqvyckZX8otREpa9OR14Te3rLvuPcpCL1O yKgnuArMjygNH0wQ3K4R5rPgnonw0a8qiR5s6WYbU/ryHe1qEEKnw2XZJkJ/F2ewbFKq /77Q== 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=dlrgFnbNI5+Y8plmO2nBv6t6eiUzaCAlcFJIo/lxksA=; b=IVKulHMd/JSSim8GrExG43Oc4BRl6cSQoToeIWxFqJ8hUqfYjfKK5Tu+4ouu/wTl7N MguVHnGD77WGPtP4gbP0Van8c0SnWo4YlVqXFsniBA/bBXpddSqPVnT/j7qm0R8UhCTj iMU1SDk33/0zel6Vrhd3DY5x9XdaC60U0AESbaLlqcOFKWl3FMHM8A5BcwBPHpRozRTs prvFNp+TAEAFy54lo99Y7OIT+pjoUDkqbY9aK5xg/09nqIdCjE1hY1xsOUuxdI0eP/qy suwGPngJCvtZfDvBxoqIViaSze7EU2PiY/XX5LOqwrkUbHRAXbwOmhgymQbxbU6qMoEn UXwA== X-Gm-Message-State: AOAM533CvUGbvfi6kJ/nijvhM6gyEM0eWF6Yci6Qtp9E7C44yMqw1Xbz ix3M1JMCKZ9v4K6UTVljZ3+BetQ9Nm8= X-Google-Smtp-Source: ABdhPJzmI+bZhgVh9fdQAWIFl2IWus2iQ02pJczO38fTriGWNbDBLhDyUFMJ8mY+IWcZP/BJS674tg== X-Received: by 2002:a7b:cc94:: with SMTP id p20mr10728477wma.75.1631536210266; Mon, 13 Sep 2021 05:30:10 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z5sm6842030wmf.33.2021.09.13.05.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 05:30:09 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 21/25] trace-cmd library: Handle latency trace in version 7 files Date: Mon, 13 Sep 2021 15:29:43 +0300 Message-Id: <20210913122947.3673239-22-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210913122947.3673239-1-tz.stoyanov@gmail.com> References: <20210913122947.3673239-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 468e51a0..77e2a53e 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -3201,6 +3201,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; @@ -3263,6 +3281,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; @@ -3277,7 +3301,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 4e2c132d..42151799 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1786,7 +1786,8 @@ out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name, return option; } -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + int file_version) { enum tracecmd_section_flags flags = 0; struct tracecmd_output *handle; @@ -1801,6 +1802,8 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in handle = tracecmd_output_allocate(fd); if (!handle) goto out_free; + if (file_version && tracecmd_output_set_version(handle, file_version)) + goto out_free; if (tracecmd_output_write_init(handle)) goto out_free; if (tracecmd_output_write_headers(handle, NULL)) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 879acb7c..af7f332c 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4505,7 +4505,8 @@ static void record_data(struct common_record_context *ctx) return; if (latency) { - handle = tracecmd_create_file_latency(ctx->output, local_cpu_count); + handle = tracecmd_create_file_latency(ctx->output, local_cpu_count, + ctx->file_version); tracecmd_set_quiet(handle, quiet); } else { if (!local_cpu_count)