Loading...
1#ifndef __PERF_DATA_H
2#define __PERF_DATA_H
3
4#include <stdbool.h>
5
6enum perf_data_mode {
7 PERF_DATA_MODE_WRITE,
8 PERF_DATA_MODE_READ,
9};
10
11struct perf_data_file {
12 const char *path;
13 int fd;
14 bool is_pipe;
15 bool force;
16 unsigned long size;
17 enum perf_data_mode mode;
18};
19
20static inline bool perf_data_file__is_read(struct perf_data_file *file)
21{
22 return file->mode == PERF_DATA_MODE_READ;
23}
24
25static inline bool perf_data_file__is_write(struct perf_data_file *file)
26{
27 return file->mode == PERF_DATA_MODE_WRITE;
28}
29
30static inline int perf_data_file__is_pipe(struct perf_data_file *file)
31{
32 return file->is_pipe;
33}
34
35static inline int perf_data_file__fd(struct perf_data_file *file)
36{
37 return file->fd;
38}
39
40static inline unsigned long perf_data_file__size(struct perf_data_file *file)
41{
42 return file->size;
43}
44
45int perf_data_file__open(struct perf_data_file *file);
46void perf_data_file__close(struct perf_data_file *file);
47ssize_t perf_data_file__write(struct perf_data_file *file,
48 void *buf, size_t size);
49
50#endif /* __PERF_DATA_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __PERF_DATA_H
3#define __PERF_DATA_H
4
5#include <stdbool.h>
6
7enum perf_data_mode {
8 PERF_DATA_MODE_WRITE,
9 PERF_DATA_MODE_READ,
10};
11
12struct perf_data_file {
13 char *path;
14 int fd;
15 unsigned long size;
16};
17
18struct perf_data {
19 const char *path;
20 struct perf_data_file file;
21 bool is_pipe;
22 bool is_dir;
23 bool force;
24 enum perf_data_mode mode;
25
26 struct {
27 u64 version;
28 struct perf_data_file *files;
29 int nr;
30 } dir;
31};
32
33static inline bool perf_data__is_read(struct perf_data *data)
34{
35 return data->mode == PERF_DATA_MODE_READ;
36}
37
38static inline bool perf_data__is_write(struct perf_data *data)
39{
40 return data->mode == PERF_DATA_MODE_WRITE;
41}
42
43static inline int perf_data__is_pipe(struct perf_data *data)
44{
45 return data->is_pipe;
46}
47
48static inline bool perf_data__is_dir(struct perf_data *data)
49{
50 return data->is_dir;
51}
52
53static inline int perf_data__fd(struct perf_data *data)
54{
55 return data->file.fd;
56}
57
58int perf_data__open(struct perf_data *data);
59void perf_data__close(struct perf_data *data);
60ssize_t perf_data__write(struct perf_data *data,
61 void *buf, size_t size);
62ssize_t perf_data_file__write(struct perf_data_file *file,
63 void *buf, size_t size);
64/*
65 * If at_exit is set, only rename current perf.data to
66 * perf.data.<postfix>, continue write on original data.
67 * Set at_exit when flushing the last output.
68 *
69 * Return value is fd of new output.
70 */
71int perf_data__switch(struct perf_data *data,
72 const char *postfix,
73 size_t pos, bool at_exit, char **new_filepath);
74
75int perf_data__create_dir(struct perf_data *data, int nr);
76int perf_data__open_dir(struct perf_data *data);
77void perf_data__close_dir(struct perf_data *data);
78int perf_data__update_dir(struct perf_data *data);
79unsigned long perf_data__size(struct perf_data *data);
80#endif /* __PERF_DATA_H */