Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4117761pxv; Mon, 19 Jul 2021 17:30:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoB4Amb6t0400ySvp61OXxAKVyGtetmjyQMym0vyMH45/xXBxa9PM9fb0RZkHFt9OVbp5J X-Received: by 2002:a17:906:8158:: with SMTP id z24mr30059388ejw.359.1626741056609; Mon, 19 Jul 2021 17:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626741056; cv=none; d=google.com; s=arc-20160816; b=Z5jZ73X2DlIiZhh9RsNp7ysQ4kM8Vr39LsFJKUpvLhFsk3BeHoKM/I9tSKejs+C/35 K8pgBFo/vYGa3HSGclR7yvAC12GiNk4R3enPp7Z0erW/k8E+egVfofNBi4aYv6WhN11w wjTAVOsQKC8989pbGxPhDUsv2N+8EDRX3xwEkqG5dZqADZZ5hF19cA3Exq4uk6mCDN8k NXNJoF1DESvPI64lNHxl5WPMnHcBm2j/rRffQv1lqwbZYtgnaWQokGUCLWqUUAxsnBIx IYgqU4eLzdxRl8qoXungZ2cQMEBLZbuKqtrs2koKP/4dHoE4GQSekWqmOiVlEAGNje/R 7srA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=syPwIwbWlprfb5Gh/Ulv2ZSrap5K83pP7HkgDMtPAu0=; b=k9NOGpww7z8llORyLCmYpbAx5MUMbkkFTrQebDwFCCjngDJ/fqaw39kQeb++UGWi0i peX24OdCI83y5FQtdH3EI5lRREjNqAdf8qoFcHSr50pekNA1Siz9C2189xtUODeI8nSz 4MLHv51UgL3Y2PH4ok67aRX4MSrHeaePCHUCaw9+n2M6tNcxVe2u8DIWx8JijCIXirZu xy9zmex6yz3wpvr4lovCOHkXEH2Ag/kZ/InQRUTlMMMbB8P5dYS2iMb3F9Z6cQQygLaL 4GgKSEYxJB+hU0qvt39PDhIRyD/O8ztco8YPfnsd0fTv03QpvlAi/N6Ob6HiHxmQe78D EDlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=awCQ88jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si22984438edr.203.2021.07.19.17.30.33; Mon, 19 Jul 2021 17:30:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=awCQ88jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379756AbhGSXqR (ORCPT + 99 others); Mon, 19 Jul 2021 19:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442039AbhGSWdh (ORCPT ); Mon, 19 Jul 2021 18:33:37 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34225C08EC26 for ; Mon, 19 Jul 2021 15:32:07 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id a127so17925454pfa.10 for ; Mon, 19 Jul 2021 15:32:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=syPwIwbWlprfb5Gh/Ulv2ZSrap5K83pP7HkgDMtPAu0=; b=awCQ88jw7gmtBD8uT3/z2wZF6npN/EWOOI6S6wG6b/HcVNyQARzF7qRCUJh0f6TdYf xXLRXqgRnh1yOKIpvQz/NL3QURJjKjoOIJKTJq6L8gJJM2pvHjkVZY+qVc42WGaVcX24 noH8VZh7eSfbXxH8kGrYu5/G8b4JLX7epm3dQ2/eKK35zEXdsU6uX0wJQAwGYODfD7iG 7F1TQfNPAxDSjJAUwbLPEk04Ey2GNGlgPlJJ636NcY1cnf0ruLqL3UeDQ2lslg7zrNl0 9wtdIZs4DYSRXcFzQhwc7yXNjIZsXZCNcULqzJSaJLQYyO2szDtQZq9E0oPbZTInbEqn m4Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=syPwIwbWlprfb5Gh/Ulv2ZSrap5K83pP7HkgDMtPAu0=; b=hbl55iAW4LIUyLJbhPqV4hE9IcOghk/pB8r6FvuMLy3jP5LGrSeeYpBdN74KY9vmGN ltnoCgLLNMkTgm1jpC/KvW+6rr2u65Gcx4Js3mmXfNbB3QOtugT7HYNnlNxDPvLUbLrk y4yWItuUL5Tf4yijtW2KAPQXUABi4jVnDOsFHPzn4wIuciodqXEfwrjK1nmdid0oWbRO KKKhS4UameYKemk7t3IcaDZZJ5JnREQf+Rhr0BoXIS+IwHpxjflgoFGRHBXUzuQh4tbw ylxCq40hCuEuWS+UTEWMhIGFdfeR/50EAMMoeGweLPRWALN0UYr5tLxfR5tG6zQrlJ0b 9uPw== X-Gm-Message-State: AOAM532BHjDkSjwvmCPowXkn0LBicHFhsnQAZH8J1bTG/BtYZVPGf0hv SIbO1QtOLw5/vsPwOaF2u4E= X-Received: by 2002:a63:4e51:: with SMTP id o17mr17178001pgl.126.1626733926726; Mon, 19 Jul 2021 15:32:06 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4801:c8d0:ff4e:db29:48ff:3778]) by smtp.gmail.com with ESMTPSA id q19sm6921569pgj.17.2021.07.19.15.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 15:32:06 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Andi Kleen , Ian Rogers , Adrian Hunter Subject: [PATCH 3/5] perf inject: Fix output from a pipe to a file Date: Mon, 19 Jul 2021 15:31:51 -0700 Message-Id: <20210719223153.1618812-4-namhyung@kernel.org> X-Mailer: git-send-email 2.32.0.402.g57bb445576-goog In-Reply-To: <20210719223153.1618812-1-namhyung@kernel.org> References: <20210719223153.1618812-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes it needs to save the perf inject data to a file for debugging. But normally it assumes the same format for input and output, so the end result cannot be used due to a broken format. # perf record -a -o - sleep 1 | perf inject -b -o my.data # perf report -i my.data --stdio 0x208 [0]: failed to process type: 0 [Invalid argument] Error: failed to process sample # To display the perf.data header info, please use --header/--header-only options. # In this case, it thought the data has a regular file header since the output is not a pipe. But actually it doesn't have one and has a pipe file header. At the end of the session, it tries to rewrite the regular file header with updated features and it overwrites the data just follows the pipe header. Fix it by checking either the input and the output is a pipe. Signed-off-by: Namhyung Kim --- tools/perf/builtin-inject.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index d99f4538d2fc..7c126597d3f5 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -46,6 +46,7 @@ struct perf_inject { bool jit_mode; bool in_place_update; bool in_place_update_dry_run; + bool is_pipe; const char *input_name; struct perf_data output; u64 bytes_written; @@ -126,7 +127,7 @@ static int perf_event__repipe_attr(struct perf_tool *tool, if (ret) return ret; - if (!inject->output.is_pipe) + if (!inject->is_pipe) return 0; return perf_event__repipe_synth(tool, event); @@ -825,14 +826,14 @@ static int __cmd_inject(struct perf_inject *inject) if (!inject->itrace_synth_opts.set) auxtrace_index__free(&session->auxtrace_index); - if (!data_out->is_pipe && !inject->in_place_update) + if (!inject->is_pipe && !inject->in_place_update) lseek(fd, output_data_offset, SEEK_SET); ret = perf_session__process_events(session); if (ret) return ret; - if (!data_out->is_pipe && !inject->in_place_update) { + if (!inject->is_pipe && !inject->in_place_update) { if (inject->build_ids) perf_header__set_feat(&session->header, HEADER_BUILD_ID); @@ -991,7 +992,10 @@ int cmd_inject(int argc, const char **argv) } data.path = inject.input_name; - inject.session = __perf_session__new(&data, inject.output.is_pipe, + if (!strcmp(inject.input_name, "-") || inject.output.is_pipe) + inject.is_pipe = true; + + inject.session = __perf_session__new(&data, inject.is_pipe, perf_data__fd(&inject.output), &inject.tool); if (IS_ERR(inject.session)) -- 2.32.0.402.g57bb445576-goog