Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf data: Support single perf.data file directory

Support directory output that contains a regular perf.data file, named
"data". By default the directory is named perf.data i.e.
perf.data
└── data

Most of the infrastructure to support a directory is already there. This
patch makes the changes needed to support the format above.

Presently there is no 'perf record' option to output a directory.

This is preparation for adding support for putting a copy of /proc/kcore in
the directory.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191004083121.12182-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
46e201ef 01e97a59

+43 -2
+28
tools/perf/Documentation/perf.data-directory-format.txt
··· 1 + perf.data directory format 2 + 3 + DISCLAIMER This is not ABI yet and is subject to possible change 4 + in following versions of perf. We will remove this 5 + disclaimer once the directory format soaks in. 6 + 7 + 8 + This document describes the on-disk perf.data directory format. 9 + 10 + The layout is described by HEADER_DIR_FORMAT feature. 11 + Currently it holds only version number (0): 12 + 13 + HEADER_DIR_FORMAT = 24 14 + 15 + struct { 16 + uint64_t version; 17 + } 18 + 19 + The current only version value 0 means that: 20 + - there is a single perf.data file named 'data' within the directory. 21 + e.g. 22 + 23 + $ tree -ps perf.data 24 + perf.data 25 + └── [-rw------- 25912] data 26 + 27 + Future versions are expected to describe different data files 28 + layout according to special needs.
+1 -1
tools/perf/builtin-record.c
··· 537 537 size_t padding; 538 538 u8 pad[8] = {0}; 539 539 540 - if (!perf_data__is_pipe(data) && !perf_data__is_dir(data)) { 540 + if (!perf_data__is_pipe(data) && perf_data__is_single_file(data)) { 541 541 off_t file_offset; 542 542 int fd = perf_data__fd(data); 543 543 int err;
+8 -1
tools/perf/util/data.c
··· 76 76 DIR *dir; 77 77 int nr = 0; 78 78 79 + /* 80 + * Directory containing a single regular perf data file which is already 81 + * open, means there is nothing more to do here. 82 + */ 83 + if (perf_data__is_single_file(data)) 84 + return 0; 85 + 79 86 if (WARN_ON(!data->is_dir)) 80 87 return -EINVAL; 81 88 ··· 413 406 u64 size = data->file.size; 414 407 int i; 415 408 416 - if (!data->is_dir) 409 + if (perf_data__is_single_file(data)) 417 410 return size; 418 411 419 412 for (i = 0; i < data->dir.nr; i++) {
+6
tools/perf/util/data.h
··· 10 10 }; 11 11 12 12 enum perf_dir_version { 13 + PERF_DIR_SINGLE_FILE = 0, 13 14 PERF_DIR_VERSION = 1, 14 15 }; 15 16 ··· 53 52 static inline bool perf_data__is_dir(struct perf_data *data) 54 53 { 55 54 return data->is_dir; 55 + } 56 + 57 + static inline bool perf_data__is_single_file(struct perf_data *data) 58 + { 59 + return data->dir.version == PERF_DIR_SINGLE_FILE; 56 60 } 57 61 58 62 static inline int perf_data__fd(struct perf_data *data)