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 char *path; 14 int fd; 15 unsigned long size; 16 }; 17 18 struct perf_data { 19 const char *path; 20 struct perf_data_file file; 21 bool is_pipe; 22 bool force; 23 enum perf_data_mode mode; 24 25 struct { 26 struct perf_data_file *files; 27 int nr; 28 } dir; 29 }; 30 31 static inline bool perf_data__is_read(struct perf_data *data) 32 { 33 return data->mode == PERF_DATA_MODE_READ; 34 } 35 36 static inline bool perf_data__is_write(struct perf_data *data) 37 { 38 return data->mode == PERF_DATA_MODE_WRITE; 39 } 40 41 static inline int perf_data__is_pipe(struct perf_data *data) 42 { 43 return data->is_pipe; 44 } 45 46 static inline int perf_data__fd(struct perf_data *data) 47 { 48 return data->file.fd; 49 } 50 51 static inline unsigned long perf_data__size(struct perf_data *data) 52 { 53 return data->file.size; 54 } 55 56 int perf_data__open(struct perf_data *data); 57 void perf_data__close(struct perf_data *data); 58 ssize_t perf_data__write(struct perf_data *data, 59 void *buf, size_t size); 60 ssize_t perf_data_file__write(struct perf_data_file *file, 61 void *buf, size_t size); 62 /* 63 * If at_exit is set, only rename current perf.data to 64 * perf.data.<postfix>, continue write on original data. 65 * Set at_exit when flushing the last output. 66 * 67 * Return value is fd of new output. 68 */ 69 int perf_data__switch(struct perf_data *data, 70 const char *postfix, 71 size_t pos, bool at_exit); 72 73 int perf_data__create_dir(struct perf_data *data, int nr); 74 int perf_data__open_dir(struct perf_data *data); 75 void perf_data__close_dir(struct perf_data *data); 76 #endif /* __PERF_DATA_H */ 77