Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2 | #ifndef __PERF_DATA_H |
| 3 | #define __PERF_DATA_H |
| 4 | |
Namhyung Kim | 6013666 | 2020-10-30 14:47:42 +0900 | [diff] [blame] | 5 | #include <stdio.h> |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 6 | #include <stdbool.h> |
| 7 | |
| 8 | enum perf_data_mode { |
| 9 | PERF_DATA_MODE_WRITE, |
| 10 | PERF_DATA_MODE_READ, |
| 11 | }; |
| 12 | |
Adrian Hunter | 3dedec4 | 2019-10-04 11:31:18 +0300 | [diff] [blame] | 13 | enum perf_dir_version { |
Adrian Hunter | 46e201e | 2019-10-04 11:31:20 +0300 | [diff] [blame] | 14 | PERF_DIR_SINGLE_FILE = 0, |
Adrian Hunter | 3dedec4 | 2019-10-04 11:31:18 +0300 | [diff] [blame] | 15 | PERF_DIR_VERSION = 1, |
| 16 | }; |
| 17 | |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 18 | struct perf_data_file { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 19 | char *path; |
Namhyung Kim | 6013666 | 2020-10-30 14:47:42 +0900 | [diff] [blame] | 20 | union { |
| 21 | int fd; |
| 22 | FILE *fptr; |
| 23 | }; |
Jiri Olsa | 45112e8 | 2019-02-21 10:41:29 +0100 | [diff] [blame] | 24 | unsigned long size; |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 27 | struct perf_data { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 28 | const char *path; |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 29 | struct perf_data_file file; |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 30 | bool is_pipe; |
Jiri Olsa | ec65def | 2019-03-08 14:47:35 +0100 | [diff] [blame] | 31 | bool is_dir; |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 32 | bool force; |
Namhyung Kim | 6013666 | 2020-10-30 14:47:42 +0900 | [diff] [blame] | 33 | bool use_stdio; |
Adrian Hunter | 2a525f6 | 2021-04-30 10:03:01 +0300 | [diff] [blame] | 34 | bool in_place_update; |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 35 | enum perf_data_mode mode; |
Jiri Olsa | 1455206 | 2019-02-24 20:06:44 +0100 | [diff] [blame] | 36 | |
| 37 | struct { |
Jiri Olsa | 258031c | 2019-03-08 14:47:39 +0100 | [diff] [blame] | 38 | u64 version; |
Jiri Olsa | 1455206 | 2019-02-24 20:06:44 +0100 | [diff] [blame] | 39 | struct perf_data_file *files; |
| 40 | int nr; |
| 41 | } dir; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 44 | static inline bool perf_data__is_read(struct perf_data *data) |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 45 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 46 | return data->mode == PERF_DATA_MODE_READ; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 49 | static inline bool perf_data__is_write(struct perf_data *data) |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 50 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 51 | return data->mode == PERF_DATA_MODE_WRITE; |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 52 | } |
| 53 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 54 | static inline int perf_data__is_pipe(struct perf_data *data) |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 55 | { |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 56 | return data->is_pipe; |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Jiri Olsa | ec65def | 2019-03-08 14:47:35 +0100 | [diff] [blame] | 59 | static inline bool perf_data__is_dir(struct perf_data *data) |
| 60 | { |
| 61 | return data->is_dir; |
| 62 | } |
| 63 | |
Adrian Hunter | 46e201e | 2019-10-04 11:31:20 +0300 | [diff] [blame] | 64 | static inline bool perf_data__is_single_file(struct perf_data *data) |
| 65 | { |
| 66 | return data->dir.version == PERF_DIR_SINGLE_FILE; |
| 67 | } |
| 68 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 69 | static inline int perf_data__fd(struct perf_data *data) |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 70 | { |
Namhyung Kim | 6013666 | 2020-10-30 14:47:42 +0900 | [diff] [blame] | 71 | if (data->use_stdio) |
| 72 | return fileno(data->file.fptr); |
| 73 | |
Jiri Olsa | eae8ad8 | 2017-01-23 22:25:41 +0100 | [diff] [blame] | 74 | return data->file.fd; |
Jiri Olsa | cc9784bd | 2013-10-15 16:27:34 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 77 | int perf_data__open(struct perf_data *data); |
| 78 | void perf_data__close(struct perf_data *data); |
Namhyung Kim | 6013666 | 2020-10-30 14:47:42 +0900 | [diff] [blame] | 79 | ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size); |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 80 | ssize_t perf_data__write(struct perf_data *data, |
Jiri Olsa | 6f9a317 | 2013-11-28 11:30:17 +0100 | [diff] [blame] | 81 | void *buf, size_t size); |
Jiri Olsa | e268687 | 2017-01-23 22:42:56 +0100 | [diff] [blame] | 82 | ssize_t perf_data_file__write(struct perf_data_file *file, |
| 83 | void *buf, size_t size); |
Wang Nan | 040f991 | 2016-04-13 08:21:05 +0000 | [diff] [blame] | 84 | /* |
| 85 | * If at_exit is set, only rename current perf.data to |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 86 | * perf.data.<postfix>, continue write on original data. |
Wang Nan | 040f991 | 2016-04-13 08:21:05 +0000 | [diff] [blame] | 87 | * Set at_exit when flushing the last output. |
| 88 | * |
| 89 | * Return value is fd of new output. |
| 90 | */ |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 91 | int perf_data__switch(struct perf_data *data, |
Wang Nan | 040f991 | 2016-04-13 08:21:05 +0000 | [diff] [blame] | 92 | const char *postfix, |
Andi Kleen | 03724b2 | 2019-03-14 15:49:55 -0700 | [diff] [blame] | 93 | size_t pos, bool at_exit, char **new_filepath); |
Jiri Olsa | 1455206 | 2019-02-24 20:06:44 +0100 | [diff] [blame] | 94 | |
| 95 | int perf_data__create_dir(struct perf_data *data, int nr); |
Jiri Olsa | eb61767 | 2019-02-24 20:06:45 +0100 | [diff] [blame] | 96 | int perf_data__open_dir(struct perf_data *data); |
Jiri Olsa | 1455206 | 2019-02-24 20:06:44 +0100 | [diff] [blame] | 97 | void perf_data__close_dir(struct perf_data *data); |
Jiri Olsa | e8be135 | 2019-03-08 14:47:37 +0100 | [diff] [blame] | 98 | int perf_data__update_dir(struct perf_data *data); |
Jiri Olsa | 29583c1 | 2019-03-08 14:47:38 +0100 | [diff] [blame] | 99 | unsigned long perf_data__size(struct perf_data *data); |
Adrian Hunter | eeb399b | 2019-10-04 11:31:21 +0300 | [diff] [blame] | 100 | int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz); |
| 101 | char *perf_data__kallsyms_name(struct perf_data *data); |
Jiri Olsa | 058f151 | 2020-11-26 18:00:21 +0100 | [diff] [blame] | 102 | bool is_perf_data(const char *path); |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 103 | #endif /* __PERF_DATA_H */ |