0001
0002 #ifndef __PERF_DATA_H
0003 #define __PERF_DATA_H
0004
0005 #include <stdio.h>
0006 #include <stdbool.h>
0007 #include <unistd.h>
0008 #include <linux/types.h>
0009
0010 enum perf_data_mode {
0011 PERF_DATA_MODE_WRITE,
0012 PERF_DATA_MODE_READ,
0013 };
0014
0015 enum perf_dir_version {
0016 PERF_DIR_SINGLE_FILE = 0,
0017 PERF_DIR_VERSION = 1,
0018 };
0019
0020 struct perf_data_file {
0021 char *path;
0022 union {
0023 int fd;
0024 FILE *fptr;
0025 };
0026 unsigned long size;
0027 };
0028
0029 struct perf_data {
0030 const char *path;
0031 struct perf_data_file file;
0032 bool is_pipe;
0033 bool is_dir;
0034 bool force;
0035 bool use_stdio;
0036 bool in_place_update;
0037 enum perf_data_mode mode;
0038
0039 struct {
0040 u64 version;
0041 struct perf_data_file *files;
0042 int nr;
0043 } dir;
0044 };
0045
0046 static inline bool perf_data__is_read(struct perf_data *data)
0047 {
0048 return data->mode == PERF_DATA_MODE_READ;
0049 }
0050
0051 static inline bool perf_data__is_write(struct perf_data *data)
0052 {
0053 return data->mode == PERF_DATA_MODE_WRITE;
0054 }
0055
0056 static inline int perf_data__is_pipe(struct perf_data *data)
0057 {
0058 return data->is_pipe;
0059 }
0060
0061 static inline bool perf_data__is_dir(struct perf_data *data)
0062 {
0063 return data->is_dir;
0064 }
0065
0066 static inline bool perf_data__is_single_file(struct perf_data *data)
0067 {
0068 return data->dir.version == PERF_DIR_SINGLE_FILE;
0069 }
0070
0071 static inline int perf_data__fd(struct perf_data *data)
0072 {
0073 if (data->use_stdio)
0074 return fileno(data->file.fptr);
0075
0076 return data->file.fd;
0077 }
0078
0079 int perf_data__open(struct perf_data *data);
0080 void perf_data__close(struct perf_data *data);
0081 ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size);
0082 ssize_t perf_data__write(struct perf_data *data,
0083 void *buf, size_t size);
0084 ssize_t perf_data_file__write(struct perf_data_file *file,
0085 void *buf, size_t size);
0086
0087
0088
0089
0090
0091
0092
0093 int perf_data__switch(struct perf_data *data,
0094 const char *postfix,
0095 size_t pos, bool at_exit, char **new_filepath);
0096
0097 int perf_data__create_dir(struct perf_data *data, int nr);
0098 int perf_data__open_dir(struct perf_data *data);
0099 void perf_data__close_dir(struct perf_data *data);
0100 int perf_data__update_dir(struct perf_data *data);
0101 unsigned long perf_data__size(struct perf_data *data);
0102 int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
0103 bool has_kcore_dir(const char *path);
0104 char *perf_data__kallsyms_name(struct perf_data *data);
0105 char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid);
0106 bool is_perf_data(const char *path);
0107 #endif