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