]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - tools/perf/util/data.h
UBUNTU: Ubuntu-5.15.0-39.42
[mirror_ubuntu-jammy-kernel.git] / tools / perf / util / data.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
f5fc1412
JO
2#ifndef __PERF_DATA_H
3#define __PERF_DATA_H
4
60136667 5#include <stdio.h>
f5fc1412
JO
6#include <stdbool.h>
7
8enum perf_data_mode {
9 PERF_DATA_MODE_WRITE,
10 PERF_DATA_MODE_READ,
11};
12
3dedec4f 13enum perf_dir_version {
46e201ef 14 PERF_DIR_SINGLE_FILE = 0,
3dedec4f
AH
15 PERF_DIR_VERSION = 1,
16};
17
eae8ad80 18struct perf_data_file {
2d4f2799 19 char *path;
60136667
NK
20 union {
21 int fd;
22 FILE *fptr;
23 };
45112e89 24 unsigned long size;
eae8ad80
JO
25};
26
8ceb41d7 27struct perf_data {
2d4f2799 28 const char *path;
eae8ad80 29 struct perf_data_file file;
6f9a317f 30 bool is_pipe;
ec65def1 31 bool is_dir;
6f9a317f 32 bool force;
60136667 33 bool use_stdio;
2a525f6a 34 bool in_place_update;
6f9a317f 35 enum perf_data_mode mode;
14552063
JO
36
37 struct {
258031c0 38 u64 version;
14552063
JO
39 struct perf_data_file *files;
40 int nr;
41 } dir;
f5fc1412
JO
42};
43
8ceb41d7 44static inline bool perf_data__is_read(struct perf_data *data)
f5fc1412 45{
8ceb41d7 46 return data->mode == PERF_DATA_MODE_READ;
f5fc1412
JO
47}
48
8ceb41d7 49static inline bool perf_data__is_write(struct perf_data *data)
f5fc1412 50{
8ceb41d7 51 return data->mode == PERF_DATA_MODE_WRITE;
f5fc1412
JO
52}
53
8ceb41d7 54static inline int perf_data__is_pipe(struct perf_data *data)
cc9784bd 55{
8ceb41d7 56 return data->is_pipe;
cc9784bd
JO
57}
58
ec65def1
JO
59static inline bool perf_data__is_dir(struct perf_data *data)
60{
61 return data->is_dir;
62}
63
46e201ef
AH
64static inline bool perf_data__is_single_file(struct perf_data *data)
65{
66 return data->dir.version == PERF_DIR_SINGLE_FILE;
67}
68
8ceb41d7 69static inline int perf_data__fd(struct perf_data *data)
cc9784bd 70{
60136667
NK
71 if (data->use_stdio)
72 return fileno(data->file.fptr);
73
eae8ad80 74 return data->file.fd;
cc9784bd
JO
75}
76
8ceb41d7
JO
77int perf_data__open(struct perf_data *data);
78void perf_data__close(struct perf_data *data);
60136667 79ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size);
8ceb41d7 80ssize_t perf_data__write(struct perf_data *data,
6f9a317f 81 void *buf, size_t size);
e268687b
JO
82ssize_t perf_data_file__write(struct perf_data_file *file,
83 void *buf, size_t size);
040f9915
WN
84/*
85 * If at_exit is set, only rename current perf.data to
8ceb41d7 86 * perf.data.<postfix>, continue write on original data.
040f9915
WN
87 * Set at_exit when flushing the last output.
88 *
89 * Return value is fd of new output.
90 */
8ceb41d7 91int perf_data__switch(struct perf_data *data,
040f9915 92 const char *postfix,
03724b2e 93 size_t pos, bool at_exit, char **new_filepath);
14552063
JO
94
95int perf_data__create_dir(struct perf_data *data, int nr);
eb617670 96int perf_data__open_dir(struct perf_data *data);
14552063 97void perf_data__close_dir(struct perf_data *data);
e8be1357 98int perf_data__update_dir(struct perf_data *data);
29583c17 99unsigned long perf_data__size(struct perf_data *data);
eeb399b5
AH
100int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
101char *perf_data__kallsyms_name(struct perf_data *data);
058f1511 102bool is_perf_data(const char *path);
f5fc1412 103#endif /* __PERF_DATA_H */