From patchwork Thu Nov 11 15:12: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: 12615137 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 EFF3DC433EF for ; Thu, 11 Nov 2021 15:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D748861252 for ; Thu, 11 Nov 2021 15:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234024AbhKKPPc (ORCPT ); Thu, 11 Nov 2021 10:15:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbhKKPPb (ORCPT ); Thu, 11 Nov 2021 10:15:31 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B41BC061767 for ; Thu, 11 Nov 2021 07:12:42 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id t18so6029809edd.8 for ; Thu, 11 Nov 2021 07:12: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=mtTNvGrogu/i0YDrnIRsSyMtFVwF8wUsaR5ZCRWL0jE=; b=RWCwODxfenRVu1K/zEog7z4sq8ESve6/oT5C7Cj9wCTGi7RnNeZkex6pY28I+TiQKG 8a7YQW2YTwOdY35V3S5jBy+Vmb9IBxEUf9q58t2krgm4pKdu3d6rmiecdj//6ySlW6Tl tNcd45RqQU5vF8isuEL4OWRQxGFRx2dRVRwCML/NEew0VDAZCEazn48nc9QJD1a0kzaK d9+1847uMDhenll5Qu4VNKBAs+G2L5cS0xXxQkAwxX8YgNN2XHPtzkWUwW7KvQR9h+to qo35GRb3APmFPUTI6t/Z0yffcDSEsvj4a4P8sRZur1BW/55iwhdo54x9phQUBAevdhNR Wb7A== 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=mtTNvGrogu/i0YDrnIRsSyMtFVwF8wUsaR5ZCRWL0jE=; b=VEmebGYhDr+UoCiY0a4+uVGhV3zWmUR9/pd1zeGXIPurnu8CC7W/KEoGuwYD+Qw0JM xb9cDYrODf2kF69rREHrUn7bB60zV7L2yFOy1oyVa+JMMQhMZ2dr8oj1J8Telxozavwf 3SzN1f3szRApo3qbC8j9gpa4XjyEsU5YI+xEJjCSaa1DGzIBAX+HTsamCa5L62mqhCv6 f0hJCjybtPMzpEyQo6Lf6/J554HVA04M2gd+T8lgKpSK5iAHeYHAyAjO9hDLHNdhFwjD Udnz9rVANFwn6diQFWJlWSQNtk+tZjFgcGmRENDYCgq5kmLv9k0ke6QPcTdC7pVGv+UD Pfgg== X-Gm-Message-State: AOAM532s1+2lNxxW85JvHwex1PlyKyQ/bZ0X1cl4wlwenwypbm9AdyOg JyGSUYIBgf2vD5vMM1EPZMQIPnNxprzh5Q== X-Google-Smtp-Source: ABdhPJz15mp89kxtlM2b1IMIsC3mmaOQCNHquPTlgWAdSLN6T32JyrEOhRX45rejgFEaan+u+2gRMg== X-Received: by 2002:aa7:d155:: with SMTP id r21mr10942735edo.341.1636643561130; Thu, 11 Nov 2021 07:12:41 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id dk5sm1686835edb.20.2021.11.11.07.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:40 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 7/8] trace-cmd library: Extend tracecmd_copy() API Date: Thu, 11 Nov 2021 17:12:27 +0200 Message-Id: <20211111151228.86922-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151228.86922-1-tz.stoyanov@gmail.com> References: <20211111151228.86922-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The tracecmd_copy() API is used to copy data between trace files. Extended it to support copying data between files from different versions. Added also functionality to copy all sections between the files. Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 5 ++- lib/trace-cmd/trace-output.c | 40 +++++++++++++++---- tracecmd/trace-restore.c | 2 +- tracecmd/trace-split.c | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 0c4fa06f..34e9b97d 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -330,8 +330,9 @@ int tracecmd_write_options(struct tracecmd_output *handle); int tracecmd_append_options(struct tracecmd_output *handle); void tracecmd_output_close(struct tracecmd_output *handle); void tracecmd_output_free(struct tracecmd_output *handle); -struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, - const char *file); +struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file, + enum tracecmd_file_states state, int file_version, + const char *compression); int tracecmd_write_cpu_data(struct tracecmd_output *handle, int cpus, char * const *cpu_data_files, const char *buff_name); diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 8a8219a4..a029678b 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -2511,14 +2511,23 @@ struct tracecmd_output *tracecmd_create_init_file(const char *output_file) * tracecmd_copy - copy the headers of one trace.dat file for another * @ihandle: input handle of the trace.dat file to copy * @file: the trace.dat file to create + * @state: what data will be copied from the source handle + * @file_version: version of the output file + * @compression: compression of the output file, can be one of: + * NULL - inherit compression from the input file + * "any" - compress the output file with the best available algorithm + * "none" - do not compress the output file + * algorithm_name - compress the output file with specified algorithm * * Reads the header information and creates a new trace data file * with the same characteristics (events and all) and returns * tracecmd_output handle to this new file. */ -struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, - const char *file) +struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file, + enum tracecmd_file_states state, int file_version, + const char *compression) { + enum tracecmd_file_states fstate; struct tracecmd_output *handle; int fd; @@ -2531,18 +2540,33 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, goto out_free; if (tracecmd_output_set_from_input(handle, ihandle)) goto out_free; + if (file_version >= FILE_VERSION_MIN) + tracecmd_output_set_version(handle, file_version); + if (compression && tracecmd_output_set_compression(handle, compression)) + goto out_free; tracecmd_output_write_init(handle); - - if (tracecmd_copy_headers(ihandle, handle, 0, 0) < 0) + fstate = state > TRACECMD_FILE_CPU_COUNT ? TRACECMD_FILE_CPU_COUNT : state; + if (tracecmd_copy_headers(ihandle, handle, 0, fstate) < 0) goto out_free; - - handle->file_state = tracecmd_get_file_state(ihandle); - + if (tracecmd_copy_buffer_descr(ihandle, handle) < 0) + goto out_free; + if (state >= TRACECMD_FILE_OPTIONS && + tracecmd_copy_options(ihandle, handle) < 0) + goto out_free; + if (state >= TRACECMD_FILE_CPU_LATENCY && + tracecmd_copy_trace_data(ihandle, handle) < 0) + goto out_free; + if (HAS_SECTIONS(handle)) + tracecmd_write_options(handle); /* The file is all ready to have cpu data attached */ return handle; out_free: - tracecmd_output_close(handle); + if (handle) + tracecmd_output_close(handle); + else + close(fd); + unlink(file); return NULL; } diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c index a903c21a..1e416496 100644 --- a/tracecmd/trace-restore.c +++ b/tracecmd/trace-restore.c @@ -153,7 +153,7 @@ void trace_restore (int argc, char **argv) if (tracecmd_read_headers(ihandle, TRACECMD_FILE_CMD_LINES) < 0) die("error reading file %s headers", input); - handle = tracecmd_copy(ihandle, output); + handle = tracecmd_copy(ihandle, output, TRACECMD_FILE_CMD_LINES, 0, NULL); tracecmd_close(ihandle); } else handle = tracecmd_create_init_file(output); diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index 671d6e9f..06a1c82b 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -348,7 +348,7 @@ static double parse_file(struct tracecmd_input *handle, dir = dirname(output); base = basename(output); - ohandle = tracecmd_copy(handle, output_file); + ohandle = tracecmd_copy(handle, output_file, TRACECMD_FILE_CMD_LINES, 0, NULL); cpus = tracecmd_cpus(handle); cpu_data = malloc(sizeof(*cpu_data) * cpus);