blob: c9de82af5584e5b4fdbf9f7cd0f3bba5cd3ad32f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsaf5fc14122013-10-15 16:27:32 +02002#ifndef __PERF_DATA_H
3#define __PERF_DATA_H
4
Namhyung Kim60136662020-10-30 14:47:42 +09005#include <stdio.h>
Jiri Olsaf5fc14122013-10-15 16:27:32 +02006#include <stdbool.h>
7
8enum perf_data_mode {
9 PERF_DATA_MODE_WRITE,
10 PERF_DATA_MODE_READ,
11};
12
Adrian Hunter3dedec42019-10-04 11:31:18 +030013enum perf_dir_version {
Adrian Hunter46e201e2019-10-04 11:31:20 +030014 PERF_DIR_SINGLE_FILE = 0,
Adrian Hunter3dedec42019-10-04 11:31:18 +030015 PERF_DIR_VERSION = 1,
16};
17
Jiri Olsaeae8ad82017-01-23 22:25:41 +010018struct perf_data_file {
Jiri Olsa2d4f2792019-02-21 10:41:30 +010019 char *path;
Namhyung Kim60136662020-10-30 14:47:42 +090020 union {
21 int fd;
22 FILE *fptr;
23 };
Jiri Olsa45112e82019-02-21 10:41:29 +010024 unsigned long size;
Jiri Olsaeae8ad82017-01-23 22:25:41 +010025};
26
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010027struct perf_data {
Jiri Olsa2d4f2792019-02-21 10:41:30 +010028 const char *path;
Jiri Olsaeae8ad82017-01-23 22:25:41 +010029 struct perf_data_file file;
Jiri Olsa6f9a3172013-11-28 11:30:17 +010030 bool is_pipe;
Jiri Olsaec65def2019-03-08 14:47:35 +010031 bool is_dir;
Jiri Olsa6f9a3172013-11-28 11:30:17 +010032 bool force;
Namhyung Kim60136662020-10-30 14:47:42 +090033 bool use_stdio;
Adrian Hunter2a525f62021-04-30 10:03:01 +030034 bool in_place_update;
Jiri Olsa6f9a3172013-11-28 11:30:17 +010035 enum perf_data_mode mode;
Jiri Olsa14552062019-02-24 20:06:44 +010036
37 struct {
Jiri Olsa258031c2019-03-08 14:47:39 +010038 u64 version;
Jiri Olsa14552062019-02-24 20:06:44 +010039 struct perf_data_file *files;
40 int nr;
41 } dir;
Jiri Olsaf5fc14122013-10-15 16:27:32 +020042};
43
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010044static inline bool perf_data__is_read(struct perf_data *data)
Jiri Olsaf5fc14122013-10-15 16:27:32 +020045{
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010046 return data->mode == PERF_DATA_MODE_READ;
Jiri Olsaf5fc14122013-10-15 16:27:32 +020047}
48
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010049static inline bool perf_data__is_write(struct perf_data *data)
Jiri Olsaf5fc14122013-10-15 16:27:32 +020050{
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010051 return data->mode == PERF_DATA_MODE_WRITE;
Jiri Olsaf5fc14122013-10-15 16:27:32 +020052}
53
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010054static inline int perf_data__is_pipe(struct perf_data *data)
Jiri Olsacc9784bd2013-10-15 16:27:34 +020055{
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010056 return data->is_pipe;
Jiri Olsacc9784bd2013-10-15 16:27:34 +020057}
58
Jiri Olsaec65def2019-03-08 14:47:35 +010059static inline bool perf_data__is_dir(struct perf_data *data)
60{
61 return data->is_dir;
62}
63
Adrian Hunter46e201e2019-10-04 11:31:20 +030064static inline bool perf_data__is_single_file(struct perf_data *data)
65{
66 return data->dir.version == PERF_DIR_SINGLE_FILE;
67}
68
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010069static inline int perf_data__fd(struct perf_data *data)
Jiri Olsacc9784bd2013-10-15 16:27:34 +020070{
Namhyung Kim60136662020-10-30 14:47:42 +090071 if (data->use_stdio)
72 return fileno(data->file.fptr);
73
Jiri Olsaeae8ad82017-01-23 22:25:41 +010074 return data->file.fd;
Jiri Olsacc9784bd2013-10-15 16:27:34 +020075}
76
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010077int perf_data__open(struct perf_data *data);
78void perf_data__close(struct perf_data *data);
Namhyung Kim60136662020-10-30 14:47:42 +090079ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size);
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010080ssize_t perf_data__write(struct perf_data *data,
Jiri Olsa6f9a3172013-11-28 11:30:17 +010081 void *buf, size_t size);
Jiri Olsae2686872017-01-23 22:42:56 +010082ssize_t perf_data_file__write(struct perf_data_file *file,
83 void *buf, size_t size);
Wang Nan040f9912016-04-13 08:21:05 +000084/*
85 * If at_exit is set, only rename current perf.data to
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010086 * perf.data.<postfix>, continue write on original data.
Wang Nan040f9912016-04-13 08:21:05 +000087 * Set at_exit when flushing the last output.
88 *
89 * Return value is fd of new output.
90 */
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010091int perf_data__switch(struct perf_data *data,
Wang Nan040f9912016-04-13 08:21:05 +000092 const char *postfix,
Andi Kleen03724b22019-03-14 15:49:55 -070093 size_t pos, bool at_exit, char **new_filepath);
Jiri Olsa14552062019-02-24 20:06:44 +010094
95int perf_data__create_dir(struct perf_data *data, int nr);
Jiri Olsaeb617672019-02-24 20:06:45 +010096int perf_data__open_dir(struct perf_data *data);
Jiri Olsa14552062019-02-24 20:06:44 +010097void perf_data__close_dir(struct perf_data *data);
Jiri Olsae8be1352019-03-08 14:47:37 +010098int perf_data__update_dir(struct perf_data *data);
Jiri Olsa29583c12019-03-08 14:47:38 +010099unsigned long perf_data__size(struct perf_data *data);
Adrian Huntereeb399b2019-10-04 11:31:21 +0300100int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
101char *perf_data__kallsyms_name(struct perf_data *data);
Jiri Olsa058f1512020-11-26 18:00:21 +0100102bool is_perf_data(const char *path);
Jiri Olsaf5fc14122013-10-15 16:27:32 +0200103#endif /* __PERF_DATA_H */