| 1 |
|
| 2 | #ifndef __PERF_DATA_H
|
| 3 | #define __PERF_DATA_H
|
| 4 |
|
| 5 | #include <stdio.h>
|
| 6 | #include <stdbool.h>
|
| 7 | #include <unistd.h>
|
| 8 | #include <linux/types.h>
|
| 9 |
|
| 10 | enum perf_data_mode {
|
| 11 | PERF_DATA_MODE_WRITE,
|
| 12 | PERF_DATA_MODE_READ,
|
| 13 | };
|
| 14 |
|
| 15 | enum perf_dir_version {
|
| 16 | PERF_DIR_SINGLE_FILE = 0,
|
| 17 | PERF_DIR_VERSION = 1,
|
| 18 | };
|
| 19 |
|
| 20 | |
| 21 | * struct perf_data_file: A wrapper around a file used for perf.data reading or writing. Generally
|
| 22 | * part of struct perf_data.
|
| 23 |
|
| 24 | struct perf_data_file {
|
| 25 | |
| 26 | * @path: Path of file. Generally a copy of perf_data.path but for a
|
| 27 | * directory it is the file within the directory.
|
| 28 |
|
| 29 | char *path;
|
| 30 | union {
|
| 31 |
|
| 32 | int fd;
|
| 33 | |
| 34 | * @fptr: Stdio FILE. Valid if use_stdio is true, currently just
|
| 35 | * pipes in perf inject.
|
| 36 |
|
| 37 | FILE *fptr;
|
| 38 | };
|
| 39 |
|
| 40 | unsigned long size;
|
| 41 |
|
| 42 | bool use_stdio;
|
| 43 | };
|
| 44 |
|
| 45 | |
| 46 | * struct perf_data: A wrapper around a file used for perf.data reading or writing.
|
| 47 |
|
| 48 | struct perf_data {
|
| 49 |
|
| 50 | const char *path;
|
| 51 |
|
| 52 | struct perf_data_file file;
|
| 53 |
|
| 54 | bool open;
|
| 55 |
|
| 56 | bool is_pipe;
|
| 57 |
|
| 58 | bool is_dir;
|
| 59 |
|
| 60 | bool force;
|
| 61 |
|
| 62 | bool in_place_update;
|
| 63 |
|
| 64 | enum perf_data_mode mode:8;
|
| 65 |
|
| 66 | struct {
|
| 67 |
|
| 68 | u64 version;
|
| 69 |
|
| 70 | struct perf_data_file *files;
|
| 71 |
|
| 72 | int nr;
|
| 73 | } dir;
|
| 74 | };
|
| 75 |
|
| 76 | static inline int perf_data_file__fd(struct perf_data_file *file)
|
| 77 | {
|
| 78 | return file->use_stdio ? fileno(file->fptr) : file->fd;
|
| 79 | }
|
| 80 |
|
| 81 | ssize_t perf_data_file__write(struct perf_data_file *file,
|
| 82 | void *buf, size_t size);
|
| 83 | off_t perf_data_file__seek(struct perf_data_file *file, off_t offset, int whence);
|
| 84 |
|
| 85 |
|
| 86 | static inline bool perf_data__is_read(struct perf_data *data)
|
| 87 | {
|
| 88 | return data->mode == PERF_DATA_MODE_READ;
|
| 89 | }
|
| 90 |
|
| 91 | static inline bool perf_data__is_write(struct perf_data *data)
|
| 92 | {
|
| 93 | return data->mode == PERF_DATA_MODE_WRITE;
|
| 94 | }
|
| 95 |
|
| 96 | static inline int perf_data__is_pipe(struct perf_data *data)
|
| 97 | {
|
| 98 | return data->is_pipe;
|
| 99 | }
|
| 100 |
|
| 101 | static inline bool perf_data__is_dir(struct perf_data *data)
|
| 102 | {
|
| 103 | return data->is_dir;
|
| 104 | }
|
| 105 |
|
| 106 | static inline bool perf_data__is_single_file(struct perf_data *data)
|
| 107 | {
|
| 108 | return data->dir.version == PERF_DIR_SINGLE_FILE;
|
| 109 | }
|
| 110 |
|
| 111 | static inline int perf_data__fd(struct perf_data *data)
|
| 112 | {
|
| 113 | return perf_data_file__fd(&data->file);
|
| 114 | }
|
| 115 |
|
| 116 | int perf_data__open(struct perf_data *data);
|
| 117 | void perf_data__close(struct perf_data *data);
|
| 118 | ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size);
|
| 119 | ssize_t perf_data__write(struct perf_data *data,
|
| 120 | void *buf, size_t size);
|
| 121 | off_t perf_data__seek(struct perf_data *data, off_t offset, int whence);
|
| 122 | |
| 123 | * If at_exit is set, only rename current perf.data to
|
| 124 | * perf.data.<postfix>, continue write on original data.
|
| 125 | * Set at_exit when flushing the last output.
|
| 126 | *
|
| 127 | * Return value is fd of new output.
|
| 128 |
|
| 129 | int perf_data__switch(struct perf_data *data,
|
| 130 | const char *postfix,
|
| 131 | size_t pos, bool at_exit, char **new_filepath);
|
| 132 |
|
| 133 | int perf_data__create_dir(struct perf_data *data, int nr);
|
| 134 | int perf_data__open_dir(struct perf_data *data);
|
| 135 | void perf_data__close_dir(struct perf_data *data);
|
| 136 | unsigned long perf_data__size(struct perf_data *data);
|
| 137 | int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
|
| 138 | char *perf_data__kallsyms_name(struct perf_data *data);
|
| 139 | char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid);
|
| 140 |
|
| 141 | bool has_kcore_dir(const char *path);
|
| 142 | bool is_perf_data(const char *path);
|
| 143 |
|
| 144 | #endif
|