• Jiwei Sun's avatar
    perf record: Add support for limit perf output file size · 6d575816
    Jiwei Sun authored
    The patch adds a new option to limit the output file size, then based on
    it, we can create a wrapper of the perf command that uses the option to
    avoid exhausting the disk space by the unconscious user.
    
    In order to make the perf.data parsable, we just limit the sample data
    size, since the perf.data consists of many headers and sample data and
    other data, the actual size of the recorded file will bigger than the
    setting value.
    
    Testing it:
    
      # ./perf record -a -g --max-size=10M
      Couldn't synthesize bpf events.
      [ perf record: perf size limit reached (10249 KB), stopping session ]
      [ perf record: Woken up 32 times to write data ]
      [ perf record: Captured and wrote 10.133 MB perf.data (71964 samples) ]
    
      # ls -lh perf.data
      -rw------- 1 root root 11M Oct 22 14:32 perf.data
    
      # ./perf record -a -g --max-size=10K
      [ perf record: perf size limit reached (10 KB), stopping session ]
      Couldn't synthesize bpf events.
      [ perf record: Woken up 0 times to write data ]
      [ perf record: Captured and wrote 1.546 MB perf.data (69 samples) ]
    
      # ls -l perf.data
      -rw------- 1 root root 1626952 Oct 22 14:36 perf.data
    
    Committer notes:
    
    Fixed the build in multiple distros by using PRIu64 to print u64 struct
    members, fixing this:
    
      builtin-record.c: In function 'record__write':
      builtin-record.c:150:5: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'u64' [-Werror=format=]
           rec->bytes_written >> 10);
           ^
        CC       /tmp/build/pe
    Signed-off-by: default avatarJiwei Sun <jiwei.sun@windriver.com>
    Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Michael Petlan <mpetlan@redhat.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Richard Danter <richard.danter@windriver.com>
    Link: http://lore.kernel.org/lkml/20191022080901.3841-1-jiwei.sun@windriver.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    6d575816
perf-record.txt 21.9 KB