From patchwork Mon Sep 13 12:41:58 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: 12488837 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 A059EC433FE for ; Mon, 13 Sep 2021 12:42:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 894D960FF2 for ; Mon, 13 Sep 2021 12:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240001AbhIMMng (ORCPT ); Mon, 13 Sep 2021 08:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239995AbhIMMnf (ORCPT ); Mon, 13 Sep 2021 08:43:35 -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 D406BC061574 for ; Mon, 13 Sep 2021 05:42:19 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 196-20020a1c04cd000000b002fa489ffe1fso6851449wme.4 for ; Mon, 13 Sep 2021 05:42:19 -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=bp2hT6LArxwN/6m8wavIayM35MrPWkhPiC4Vw46dQks=; b=AjhHg/snZ7iDqq2oGx8O5vcK2M+Lv+21SMy48A2h1cGgaAMzgUx2ix1lkY5JJ8k0eh v03XaapQIR1uZZqZGnjlTCd9PfjhjRb9L//rxab8dLWfPcXFfuLztISUlthqaMQvTszA GO5XFAAFGwL/Xb+f+zaT4TFE9d8irOha9HXQ7PmZkjE4CVE/nscoDUvEVA4scBcHZEYr haFwY8FFVOuvE/GvW9dPfQ7C+3HgjSAPQhu3IDlaMzxvdRIQHOm4EI18B4HCRnNgkiTr crQ/i8Bp6nRGaRebnD37hJNPx550he0F34OvhTaGkF30U2qmcubMWy3FaGycOnc8PZPi /OAw== 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=bp2hT6LArxwN/6m8wavIayM35MrPWkhPiC4Vw46dQks=; b=NNfhCAbytrfpgqTDVJrRUYc5jLw5jyOiFxRfJBqsZ6zVLex4UMQzqm3khLbTLKrXFx iex9TH4+T6zGVvHGD4gSrvjLV4X76m0ZQOY/sJnoGSy3KcZVK5eVBOCRyebG1PjhypRJ aihcqqzpdcvIvswu/wqTeyPQSOGp3WUJLBFCy9l/wkvSOGlAT59lJXvPmfcksEdEsXWD 7zbBTbi3wVVU6MqpTu6R02Yp03Z0OR5YuSuKmaGg3Ff8l0F0pNW6rKmY1mqDuxCbVq+c X5vkjPlfG0hP3el1scqe0gMHEt3vdZx0P30R3msZettUyVM+Jcs1aIY1+SFpVGYKuzHD nZ6g== X-Gm-Message-State: AOAM530ylyZdeWBErvGoCsxMqBY4/+p1VK7SAU+zJ2F1StzBOLO+WGJd OLQ32Ki7fyJ+l6ZEN8p7JXIjZ0Hcluo= X-Google-Smtp-Source: ABdhPJx3YUtx6UhhLzSKGmKqA9sZ+gMcfNRAWy2767ahCxYd/SkDk4j/xnxEiLbtk5EslvC+zBhhJg== X-Received: by 2002:a7b:cd93:: with SMTP id y19mr1602381wmj.110.1631536938467; Mon, 13 Sep 2021 05:42:18 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id u13sm7244290wrt.41.2021.09.13.05.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 05:42:18 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 15/20] trace-cmd library: Read compressed latency data Date: Mon, 13 Sep 2021 15:41:58 +0300 Message-Id: <20210913124203.3677760-16-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210913124203.3677760-1-tz.stoyanov@gmail.com> References: <20210913124203.3677760-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Extended the latency read logic for reading comperssed latency trace data. Both decompressing approaches are supported: in-memory and using temporary file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 74 +++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index fab8b9ba..c901be0e 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -175,6 +175,7 @@ struct tracecmd_input { bool read_zpage; /* uncompress pages in memory, do not use tmp files */ bool cpu_compressed; int file_version; + struct cpu_zdata latz; struct cpu_data *cpu_data; long long ts_offset; struct tsc2nsec tsc_calc; @@ -3450,20 +3451,52 @@ static int read_options_type(struct tracecmd_input *handle) int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size) { + struct cpu_zdata *zdata = &handle->latz; + void *data; + int rsize; + int fd = -1; + int id; + 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)) + if (!handle->cpu_compressed) { + fd = handle->fd; + } else if (!handle->read_zpage) { + if (zdata->fd < 0) return -1; + fd = zdata->fd; } - return do_read(handle, *buf, *size); + /* Read data from a file */ + if (fd >= 0) { + if (!(*buf)) { + *size = BUFSIZ; + *buf = malloc(*size); + if (!(*buf)) + return -1; + } + return do_read_fd(fd, *buf, *size); + } + + /* Uncompress data in memory */ + if (zdata->last_chunk >= zdata->count) + return 0; + id = zdata->last_chunk; + if (!*buf || *size < zdata->chunks[id].size) { + data = realloc(*buf, zdata->chunks[id].size); + if (!data) + return -1; + *buf = data; + *size = zdata->chunks[id].size; + } + if (tracecmd_uncompress_chunk(handle->compress, &zdata->chunks[id], *buf)) + return -1; + rsize = zdata->chunks[id].size; + zdata->last_chunk++; + return rsize; } static int init_cpu_data(struct tracecmd_input *handle) @@ -3531,7 +3564,27 @@ static int init_cpu_data(struct tracecmd_input *handle) int init_latency_data(struct tracecmd_input *handle) { - /* To do */ + unsigned long long wsize; + int ret; + + if (!handle->cpu_compressed) + return 0; + + if (handle->read_zpage) { + handle->latz.count = tracecmd_load_chunks_info(handle->compress, &handle->latz.chunks); + if (handle->latz.count < 0) + return -1; + } else { + strcpy(handle->latz.file, COMPR_TEMP_FILE); + handle->latz.fd = mkstemp(handle->latz.file); + if (handle->latz.fd < 0) + return -1; + ret = tracecmd_uncompress_copy_to(handle->compress, handle->latz.fd, NULL, &wsize); + if (ret) + return -1; + lseek64(handle->latz.fd, 0, SEEK_SET); + } + return 0; } @@ -4004,6 +4057,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) handle->fd = fd; handle->ref = 1; + handle->latz.fd = -1; /* By default, use usecs, unless told otherwise */ handle->flags |= TRACECMD_FL_IN_USECS; @@ -4293,7 +4347,11 @@ void tracecmd_close(struct tracecmd_input *handle) free(handle->trace_clock); free(handle->version); close(handle->fd); - + free(handle->latz.chunks); + if (handle->latz.fd >= 0) { + close(handle->latz.fd); + unlink(handle->latz.file); + } while (handle->sections) { del_sec = handle->sections; handle->sections = handle->sections->next;