Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [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 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12 | enum perf_dir_version { |
| 13 | PERF_DIR_SINGLE_FILE = 0, |
| 14 | PERF_DIR_VERSION = 1, |
| 15 | }; |
| 16 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | struct perf_data_file { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 18 | char *path; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | int fd; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 20 | unsigned long size; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | struct perf_data { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 24 | const char *path; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | struct perf_data_file file; |
| 26 | bool is_pipe; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 27 | bool is_dir; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 28 | bool force; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | enum perf_data_mode mode; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 30 | |
| 31 | struct { |
| 32 | u64 version; |
| 33 | struct perf_data_file *files; |
| 34 | int nr; |
| 35 | } dir; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static inline bool perf_data__is_read(struct perf_data *data) |
| 39 | { |
| 40 | return data->mode == PERF_DATA_MODE_READ; |
| 41 | } |
| 42 | |
| 43 | static inline bool perf_data__is_write(struct perf_data *data) |
| 44 | { |
| 45 | return data->mode == PERF_DATA_MODE_WRITE; |
| 46 | } |
| 47 | |
| 48 | static inline int perf_data__is_pipe(struct perf_data *data) |
| 49 | { |
| 50 | return data->is_pipe; |
| 51 | } |
| 52 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 53 | static inline bool perf_data__is_dir(struct perf_data *data) |
| 54 | { |
| 55 | return data->is_dir; |
| 56 | } |
| 57 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 58 | static inline bool perf_data__is_single_file(struct perf_data *data) |
| 59 | { |
| 60 | return data->dir.version == PERF_DIR_SINGLE_FILE; |
| 61 | } |
| 62 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 63 | static inline int perf_data__fd(struct perf_data *data) |
| 64 | { |
| 65 | return data->file.fd; |
| 66 | } |
| 67 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 68 | int perf_data__open(struct perf_data *data); |
| 69 | void perf_data__close(struct perf_data *data); |
| 70 | ssize_t perf_data__write(struct perf_data *data, |
| 71 | void *buf, size_t size); |
| 72 | ssize_t perf_data_file__write(struct perf_data_file *file, |
| 73 | void *buf, size_t size); |
| 74 | /* |
| 75 | * If at_exit is set, only rename current perf.data to |
| 76 | * perf.data.<postfix>, continue write on original data. |
| 77 | * Set at_exit when flushing the last output. |
| 78 | * |
| 79 | * Return value is fd of new output. |
| 80 | */ |
| 81 | int perf_data__switch(struct perf_data *data, |
| 82 | const char *postfix, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 83 | size_t pos, bool at_exit, char **new_filepath); |
| 84 | |
| 85 | int perf_data__create_dir(struct perf_data *data, int nr); |
| 86 | int perf_data__open_dir(struct perf_data *data); |
| 87 | void perf_data__close_dir(struct perf_data *data); |
| 88 | int perf_data__update_dir(struct perf_data *data); |
| 89 | unsigned long perf_data__size(struct perf_data *data); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 90 | int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz); |
| 91 | char *perf_data__kallsyms_name(struct perf_data *data); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | #endif /* __PERF_DATA_H */ |