• N
    perf inject: Fix output from a pipe to a file · fea20d66
    Namhyung Kim 提交于
    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: NNamhyung Kim <namhyung@kernel.org>
    Acked-by: NJiri Olsa <jolsa@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Link: http://lore.kernel.org/lkml/20210719223153.1618812-4-namhyung@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
    fea20d66
builtin-inject.c 28.1 KB