tools/perf/util/data.c
Source file repositories/reference/linux-study-clean/tools/perf/util/data.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/data.c- Extension
.c- Size
- 11335 bytes
- Lines
- 581
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compiler.hlinux/kernel.hlinux/string.hlinux/zalloc.hlinux/err.hsys/types.hsys/stat.herrno.hfcntl.hunistd.hstring.hasm/bug.hdirent.hdata.hutil.hdebug.hheader.hrlimit.hinternal/lib.h
Detected Declarations
function perf_data_file__closefunction close_dirfunction perf_data__close_dirfunction perf_data__create_dirfunction perf_data__open_dirfunction check_pipefunction check_backupfunction is_dirfunction open_file_readfunction open_file_writefunction open_filefunction open_file_dupfunction open_dirfunction perf_data__openfunction perf_data__closefunction perf_data_file__readfunction perf_data__readfunction perf_data_file__writefunction perf_data__writefunction perf_data_file__seekfunction perf_data__seekfunction perf_data__switchfunction perf_data__sizefunction perf_data__make_kcore_dirfunction has_kcore_dirfunction is_perf_data
Annotated Snippet
if (file->fptr) {
fclose(file->fptr);
file->fptr = NULL;
}
} else {
close(file->fd);
file->fd = -1;
}
zfree(&file->path);
}
static void close_dir(struct perf_data_file *files, int nr)
{
while (--nr >= 0)
perf_data_file__close(&files[nr]);
free(files);
}
void perf_data__close_dir(struct perf_data *data)
{
close_dir(data->dir.files, data->dir.nr);
data->dir.files = NULL;
data->dir.nr = 0;
}
int perf_data__create_dir(struct perf_data *data, int nr)
{
enum rlimit_action set_rlimit = NO_CHANGE;
struct perf_data_file *files = NULL;
int i, ret;
if (WARN_ON(!data->is_dir))
return -EINVAL;
files = calloc(nr, sizeof(*files));
if (!files)
return -ENOMEM;
for (i = 0; i < nr; i++) {
struct perf_data_file *file = &files[i];
ret = asprintf(&file->path, "%s/data.%d", data->path, i);
if (ret < 0) {
ret = -ENOMEM;
goto out_err;
}
retry_open:
ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (ret < 0) {
/*
* If using parallel threads to collect data,
* perf record needs at least 6 fds per CPU.
* When we run out of them try to increase the limits.
*/
if (errno == EMFILE && rlimit__increase_nofile(&set_rlimit))
goto retry_open;
ret = -errno;
goto out_err;
}
set_rlimit = NO_CHANGE;
file->fd = ret;
}
data->dir.version = PERF_DIR_VERSION;
data->dir.files = files;
data->dir.nr = nr;
return 0;
out_err:
close_dir(files, i);
return ret;
}
int perf_data__open_dir(struct perf_data *data)
{
struct perf_data_file *files = NULL;
struct dirent *dent;
int ret = -1;
DIR *dir;
int nr = 0;
/*
* Directory containing a single regular perf data file which is already
* open, means there is nothing more to do here.
*/
if (perf_data__is_single_file(data))
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/kernel.h`, `linux/string.h`, `linux/zalloc.h`, `linux/err.h`, `sys/types.h`, `sys/stat.h`, `errno.h`.
- Detected declarations: `function perf_data_file__close`, `function close_dir`, `function perf_data__close_dir`, `function perf_data__create_dir`, `function perf_data__open_dir`, `function check_pipe`, `function check_backup`, `function is_dir`, `function open_file_read`, `function open_file_write`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.