rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 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 | bool is_pipe; |
| 16 | bool force; |
| 17 | unsigned long size; |
| 18 | enum perf_data_mode mode; |
| 19 | }; |
| 20 | |
| 21 | static inline bool perf_data_file__is_read(struct perf_data_file *file) |
| 22 | { |
| 23 | return file->mode == PERF_DATA_MODE_READ; |
| 24 | } |
| 25 | |
| 26 | static inline bool perf_data_file__is_write(struct perf_data_file *file) |
| 27 | { |
| 28 | return file->mode == PERF_DATA_MODE_WRITE; |
| 29 | } |
| 30 | |
| 31 | static inline int perf_data_file__is_pipe(struct perf_data_file *file) |
| 32 | { |
| 33 | return file->is_pipe; |
| 34 | } |
| 35 | |
| 36 | static inline int perf_data_file__fd(struct perf_data_file *file) |
| 37 | { |
| 38 | return file->fd; |
| 39 | } |
| 40 | |
| 41 | static inline unsigned long perf_data_file__size(struct perf_data_file *file) |
| 42 | { |
| 43 | return file->size; |
| 44 | } |
| 45 | |
| 46 | int perf_data_file__open(struct perf_data_file *file); |
| 47 | void perf_data_file__close(struct perf_data_file *file); |
| 48 | ssize_t perf_data_file__write(struct perf_data_file *file, |
| 49 | void *buf, size_t size); |
| 50 | /* |
| 51 | * If at_exit is set, only rename current perf.data to |
| 52 | * perf.data.<postfix>, continue write on original file. |
| 53 | * Set at_exit when flushing the last output. |
| 54 | * |
| 55 | * Return value is fd of new output. |
| 56 | */ |
| 57 | int perf_data_file__switch(struct perf_data_file *file, |
| 58 | const char *postfix, |
| 59 | size_t pos, bool at_exit); |
| 60 | #endif /* __PERF_DATA_H */ |