From patchwork Mon Sep 13 12:41:46 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: 12488811 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 5BE2FC433F5 for ; Mon, 13 Sep 2021 12:42:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46DE060FC0 for ; Mon, 13 Sep 2021 12:42:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239101AbhIMMnZ (ORCPT ); Mon, 13 Sep 2021 08:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239085AbhIMMnY (ORCPT ); Mon, 13 Sep 2021 08:43:24 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E71FC061574 for ; Mon, 13 Sep 2021 05:42:09 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id g16so14506738wrb.3 for ; Mon, 13 Sep 2021 05:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jdv8rK6vXgqUw+vNfuhyVo0YJpHG5XQUVh2ccXuM4d8=; b=g5O8mAJJWkQzoqm+nu7proO3SwZWN1t9ag0NB7opb7FfqUOUPO4adk23A+i6I+r0Dl uLnc7SS020+S7qcKi5ZYBKHDyXCcDevmnZssCLj4bQJ73uWNYj7PgcmJrlr19wRAfrfc //0AbMLNYTDmEoJjtl6BStezhn8dQcdSRBQgWOWMK56OD/gIsVVaIt6CGQo8CdUFjqlf yVZSwSxSiY96DZ3o7yPmu2l1pNu2tzvS0mPGqsbJF48lGdMbkzC+fpKw/47GGbhNkYYX DtAnXRB7Tu/bg0LpLY1FSkvVBkT8ronOBjxtoJpSxfN6kQtLpX1pWL/Zfq/WWPVZO12s QH+A== 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=Jdv8rK6vXgqUw+vNfuhyVo0YJpHG5XQUVh2ccXuM4d8=; b=siugycrze+Knk4ddXw1Qhk1JrybIpUkTk8NTg/iV4PlOXtdF38vWJw8AOzl+jRtemO 60n2TRUPMiWDO0530zKsdGvftqpqs/s8BIQbVJByk+VcwwmC30gwWuAN6Jjw+01CETv8 ULOUZvoQxpIH+9purR93BT3bJp+6HKX3pmlILK/ktRa1Hhj4An/1wRiXYkklHHWcxTq9 crJWNltDigVBFq757tfidbLgu1SYhs5jK/yopm18UY2Mg6EFHU9O1m+kvfdRbRr4naFQ gt82lK5O4QmcGrbg4zoDeFHyEkHBd540gOCOLVVoE6rWwOd21EU/egQfCYSxKnkeemyg 0hpg== X-Gm-Message-State: AOAM533b2NZYj8BDYdviAfbdHRxtRP4HtP6jumdDgmEuzJEeMl+seTIT ziONC2f0JAHmjZxY548wW95in5cv+Cw= X-Google-Smtp-Source: ABdhPJyM+KmdB5SMalHbe+LMNkUHYzt/Tn0aYmskF3Gvz4RePypC5fxk+6HWiKuYCf+vKFV6YeMP4A== X-Received: by 2002:adf:82cf:: with SMTP id 73mr12756696wrc.366.1631536927711; Mon, 13 Sep 2021 05:42:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 05:42:07 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 03/20] trace-cmd library: Internal helpers for uncompressing data Date: Mon, 13 Sep 2021 15:41:46 +0300 Message-Id: <20210913124203.3677760-4-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 New library internal helper functions are introduced, to add compression functionality to the input trace handler. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/trace-cmd-local.h | 3 ++ lib/trace-cmd/trace-input.c | 49 ++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index 304bec49..14223a08 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -45,6 +45,9 @@ void out_compression_reset(struct tracecmd_output *handle, bool compress); unsigned long long out_copy_fd_compress(struct tracecmd_output *handle, int fd, unsigned long long max, unsigned long long *write_size); +void in_uncompress_reset(struct tracecmd_input *handle); +int in_uncompress_block(struct tracecmd_input *handle); + unsigned long long out_write_section_header(struct tracecmd_output *handle, unsigned short header_id, char *description, enum tracecmd_section_flags flags, bool option); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index b7d78a3a..25d376f7 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -155,6 +155,9 @@ struct tracecmd_input { long long ts_offset; struct tsc2nsec tsc_calc; + bool read_compress; + struct tracecmd_compression *compress; + struct host_trace_info host; double ts2secs; unsigned int cpustats_size; @@ -262,13 +265,13 @@ static const char *show_records(struct page **pages, int nr_pages) static int init_cpu(struct tracecmd_input *handle, int cpu); -static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size) +static ssize_t do_read_fd(int fd, void *data, size_t size) { ssize_t tot = 0; ssize_t r; do { - r = read(handle->fd, data + tot, size - tot); + r = read(fd, data + tot, size - tot); tot += r; if (!r) @@ -280,6 +283,22 @@ static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size) return tot; } +static inline int do_lseek(struct tracecmd_input *handle, int offset, int whence) +{ + if (handle->read_compress) + return tracecmd_compress_lseek(handle->compress, offset, whence); + else + return lseek(handle->fd, offset, whence); +} + +static inline ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size) +{ + if (handle->read_compress) + return tracecmd_compress_read(handle->compress, data, size); + else + return do_read_fd(handle->fd, data, size); +} + static ssize_t do_read_check(struct tracecmd_input *handle, void *data, size_t size) { @@ -304,9 +323,7 @@ static char *read_string(struct tracecmd_input *handle) for (;;) { r = do_read(handle, buf, BUFSIZ); - if (r < 0) - goto fail; - if (!r) + if (r <= 0) goto fail; for (i = 0; i < r; i++) { @@ -332,7 +349,7 @@ static char *read_string(struct tracecmd_input *handle) } /* move the file descriptor to the end of the string */ - r = lseek(handle->fd, -(r - (i+1)), SEEK_CUR); + r = do_lseek(handle, -(r - (i+1)), SEEK_CUR); if (r < 0) goto fail; @@ -396,6 +413,26 @@ static int read8(struct tracecmd_input *handle, unsigned long long *size) return 0; } +__hidden void in_uncompress_reset(struct tracecmd_input *handle) +{ + if (handle->compress) { + handle->read_compress = false; + tracecmd_compress_reset(handle->compress); + } +} + +__hidden int in_uncompress_block(struct tracecmd_input *handle) +{ + int ret = 0; + + if (handle->compress) { + ret = tracecmd_uncompress_block(handle->compress); + if (!ret) + handle->read_compress = true; + } + return ret; +} + static struct file_section *section_get(struct tracecmd_input *handle, int id) { struct file_section *sec;