Received: by 2002:a9a:4c47:0:b029:116:c383:538 with SMTP id u7csp1125346lko; Tue, 13 Jul 2021 17:37:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx302T08pV8UCUqkpHdYLTxfn8xDlsVJgjGASBR140fxZoy4N5JbyypZjZk5Omog5M35Evl X-Received: by 2002:a92:2805:: with SMTP id l5mr4713341ilf.242.1626223045801; Tue, 13 Jul 2021 17:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626223045; cv=none; d=google.com; s=arc-20160816; b=WnQFZhuhgXhLXWigSeFzuVXAOXdpFX/wMJd8MvEn3BOCnikR7hyRUroWSnS46gi6u5 2schEQv/53Q26stpmG+PUQPo0Xhuj5CcuwvmTqL3zpwtV63q0LIKkJdpcol9nEoM/or1 AyCEGiKN4Td1idodwMledbFaf8yYcH8pxNLOnK9hggSnNKMrPoBIEbYTgUU680XJl7EI l1kE1iRR1IlcOTJzaDi0XgPeMD7TXbAJmfqYhFojbsXqxyNF1zSmC+vh2+q6HNKcV9Mq iQhQsKc2Jv1MApRwYYwLb+B5uW25V8Rz0LdGxEIdWWv1sRfI2Tj0Rj+2co1krzAQ2ZAr YAfg== 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=FDm3lJYHGGaxvtivXokPORl5JWRQ690WY2gWwBN/M4s=; b=lqzTVxGahf0GZLZvI3hUkgH04/PgOeg7ncf/HrhBAq0WeZxZLF1IZVzl4Dntql/Kvo ghRW9a7AdFJan8Z/9yvw8maO76tuy6Ytriht5WEUejU0FHlGPKkEhVU3LmGo5vkAXyLh gkVcvG5JrdPR9hz1odkBD8LGyHbLSCV5MId+PgA+AVl39dj5byfwRlJu1t3Zc+biRI7O f7IVyIrZLN0NFMk6iniJeECQpN6G8prYf1gMnMnC0uURR5Y6N9SMY/ZvDddwimrMa6l3 xFbfREzgYDzQB5AchNl6dO+6io8C5apYlIVJKqpIamfEUIJtic512OECZ/jsw6L91hho DuUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qesyhibu; 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 s9si443261ilq.3.2021.07.13.17.37.13; Tue, 13 Jul 2021 17:37:25 -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=qesyhibu; 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 S237232AbhGNAhm (ORCPT + 99 others); Tue, 13 Jul 2021 20:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237226AbhGNAhl (ORCPT ); Tue, 13 Jul 2021 20:37:41 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87FD9C0613EF for ; Tue, 13 Jul 2021 17:34:49 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id t9so193843pgn.4 for ; Tue, 13 Jul 2021 17:34:49 -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=FDm3lJYHGGaxvtivXokPORl5JWRQ690WY2gWwBN/M4s=; b=qesyhibu30an5buJETLm55Cy+AEcE3HgMBCdY8QypdHwbsOeErWTIKuUfCZv/BNtUU H1li/17O+8In5hNoMTBKzhAgAByyIhtlMSHA3V8E9A6UAl7GCjl7n/tGVHZ1UlgqPAeF EI53gATUYT5pSCm10mdHWUx0Jgko3SqN4W09d2JYigjzCfPM2RQsRglZRXGcCvJCROhE /5lTWTV02UCCNKB4Gokf1wR5n909JCoV3cQHEdvHjEI0hB9g34pFOnXhBc0BZP76JXgt 4edXmL01/DvAvzEm8BCjNsVUkwZHNN7NV+aRLJBoX60Lr0lInyVM7NrJB+yIx3yA+JD+ Ku6g== 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=FDm3lJYHGGaxvtivXokPORl5JWRQ690WY2gWwBN/M4s=; b=hRx3wvctBlJjOLc9MZBiUXP6lC5a1XHiH5nuBYKFQVJ2V+O9cixgVnaAa/YTNqu8tN 2xus5HcjyadNb+d17NbHlt3pH3xBPF3DRkcPLNWffmIK6JXjRYj7I3d7zeeyPt1i1OV3 I71Krlqo9QUXGIyiR4KLALLvhln8G1tmevZOmBjVyn1DWGU3cqNFEkYbDnASnFy0zYEq Ud3W13yZDU7SiYZX+LBhH81/9M2Fs067yO8KkEchsR+EmW6G9sOXmfTZTpvEBwqdVYWD TxecCprZgVmcTCx+7CSo7XWHndPCJt5eLi0ZEytGOKRK7eMDgQsPI91WFOpYgbS3aPfX aChA== X-Gm-Message-State: AOAM533N4SLkyFCpQt2ztdscNEkM5lfDjVA+dksB7nLW2S0LhBB9LKGd 4Gj6ijyUTZw9AD3mBw9r1lo= X-Received: by 2002:a63:3387:: with SMTP id z129mr6522500pgz.227.1626222889149; Tue, 13 Jul 2021 17:34:49 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4801:c8d0:9b12:1fd4:6232:5315]) by smtp.gmail.com with ESMTPSA id x6sm285896pgq.67.2021.07.13.17.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 17:34:48 -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: Tue, 13 Jul 2021 17:34:40 -0700 Message-Id: <20210714003442.1111502-4-namhyung@kernel.org> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210714003442.1111502-1-namhyung@kernel.org> References: <20210714003442.1111502-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.93.g670b81a890-goog