1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_DATA_H
3 #define __PERF_DATA_H
4
5 #include <stdbool.h>
6 #include <linux/types.h>
7
8 enum perf_data_mode {
9 PERF_DATA_MODE_WRITE,
10 PERF_DATA_MODE_READ,
11 };
12
13 struct perf_data_file {
14 char *path;
15 int fd;
16 unsigned long size;
17 };
18
19 struct perf_data {
20 const char *path;
21 struct perf_data_file file;
22 bool is_pipe;
23 bool is_dir;
24 bool force;
25 enum perf_data_mode mode;
26
27 struct {
28 u64 version;
29 struct perf_data_file *files;
30 int nr;
31 } dir;
32 };
33
perf_data__is_read(struct perf_data * data)34 static inline bool perf_data__is_read(struct perf_data *data)
35 {
36 return data->mode == PERF_DATA_MODE_READ;
37 }
38
perf_data__is_write(struct perf_data * data)39 static inline bool perf_data__is_write(struct perf_data *data)
40 {
41 return data->mode == PERF_DATA_MODE_WRITE;
42 }
43
perf_data__is_pipe(struct perf_data * data)44 static inline int perf_data__is_pipe(struct perf_data *data)
45 {
46 return data->is_pipe;
47 }
48
perf_data__is_dir(struct perf_data * data)49 static inline bool perf_data__is_dir(struct perf_data *data)
50 {
51 return data->is_dir;
52 }
53
perf_data__fd(struct perf_data * data)54 static inline int perf_data__fd(struct perf_data *data)
55 {
56 return data->file.fd;
57 }
58
59 int perf_data__open(struct perf_data *data);
60 void perf_data__close(struct perf_data *data);
61 ssize_t perf_data__write(struct perf_data *data,
62 void *buf, size_t size);
63 ssize_t perf_data_file__write(struct perf_data_file *file,
64 void *buf, size_t size);
65 /*
66 * If at_exit is set, only rename current perf.data to
67 * perf.data.<postfix>, continue write on original data.
68 * Set at_exit when flushing the last output.
69 *
70 * Return value is fd of new output.
71 */
72 int perf_data__switch(struct perf_data *data,
73 const char *postfix,
74 size_t pos, bool at_exit, char **new_filepath);
75
76 int perf_data__create_dir(struct perf_data *data, int nr);
77 int perf_data__open_dir(struct perf_data *data);
78 void perf_data__close_dir(struct perf_data *data);
79 int perf_data__update_dir(struct perf_data *data);
80 unsigned long perf_data__size(struct perf_data *data);
81 #endif /* __PERF_DATA_H */
82