Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 1 | #ifndef __PERF_DATA_H |
| 2 | #define __PERF_DATA_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | |
| 6 | enum perf_data_mode { |
| 7 | PERF_DATA_MODE_WRITE, |
| 8 | PERF_DATA_MODE_READ, |
| 9 | }; |
| 10 | |
| 11 | struct perf_data_file { |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 12 | const char *path; |
| 13 | int fd; |
| 14 | bool is_pipe; |
| 15 | bool force; |
| 16 | unsigned long size; |
| 17 | enum perf_data_mode mode; |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | static inline bool perf_data_file__is_read(struct perf_data_file *file) |
| 21 | { |
| 22 | return file->mode == PERF_DATA_MODE_READ; |
| 23 | } |
| 24 | |
| 25 | static inline bool perf_data_file__is_write(struct perf_data_file *file) |
| 26 | { |
| 27 | return file->mode == PERF_DATA_MODE_WRITE; |
| 28 | } |
| 29 | |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 30 | static inline int perf_data_file__is_pipe(struct perf_data_file *file) |
| 31 | { |
| 32 | return file->is_pipe; |
| 33 | } |
| 34 | |
| 35 | static inline int perf_data_file__fd(struct perf_data_file *file) |
| 36 | { |
| 37 | return file->fd; |
| 38 | } |
| 39 | |
| 40 | static inline unsigned long perf_data_file__size(struct perf_data_file *file) |
| 41 | { |
| 42 | return file->size; |
| 43 | } |
| 44 | |
Jiri Olsa | 6a4d98d | 2013-10-15 16:27:33 +0200 | [diff] [blame] | 45 | int perf_data_file__open(struct perf_data_file *file); |
| 46 | void perf_data_file__close(struct perf_data_file *file); |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 47 | ssize_t perf_data_file__write(struct perf_data_file *file, |
| 48 | void *buf, size_t size); |
Wang Nan | 040f991 | 2016-04-13 08:21:05 +0000 | [diff] [blame] | 49 | /* |
| 50 | * If at_exit is set, only rename current perf.data to |
| 51 | * perf.data.<postfix>, continue write on original file. |
| 52 | * Set at_exit when flushing the last output. |
| 53 | * |
| 54 | * Return value is fd of new output. |
| 55 | */ |
| 56 | int perf_data_file__switch(struct perf_data_file *file, |
| 57 | const char *postfix, |
| 58 | size_t pos, bool at_exit); |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 59 | #endif /* __PERF_DATA_H */ |