perf data: Support having perf.data stored as a directory
[sfrench/cifs-2.6.git] / tools / perf / util / 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
7 enum perf_data_mode {
8         PERF_DATA_MODE_WRITE,
9         PERF_DATA_MODE_READ,
10 };
11
12 struct perf_data_file {
13         char            *path;
14         int              fd;
15         unsigned long    size;
16 };
17
18 struct 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                 struct perf_data_file   *files;
28                 int                      nr;
29         } dir;
30 };
31
32 static inline bool perf_data__is_read(struct perf_data *data)
33 {
34         return data->mode == PERF_DATA_MODE_READ;
35 }
36
37 static inline bool perf_data__is_write(struct perf_data *data)
38 {
39         return data->mode == PERF_DATA_MODE_WRITE;
40 }
41
42 static inline int perf_data__is_pipe(struct perf_data *data)
43 {
44         return data->is_pipe;
45 }
46
47 static inline bool perf_data__is_dir(struct perf_data *data)
48 {
49         return data->is_dir;
50 }
51
52 static inline int perf_data__fd(struct perf_data *data)
53 {
54         return data->file.fd;
55 }
56
57 static inline unsigned long perf_data__size(struct perf_data *data)
58 {
59         return data->file.size;
60 }
61
62 int perf_data__open(struct perf_data *data);
63 void perf_data__close(struct perf_data *data);
64 ssize_t perf_data__write(struct perf_data *data,
65                               void *buf, size_t size);
66 ssize_t perf_data_file__write(struct perf_data_file *file,
67                               void *buf, size_t size);
68 /*
69  * If at_exit is set, only rename current perf.data to
70  * perf.data.<postfix>, continue write on original data.
71  * Set at_exit when flushing the last output.
72  *
73  * Return value is fd of new output.
74  */
75 int perf_data__switch(struct perf_data *data,
76                            const char *postfix,
77                            size_t pos, bool at_exit);
78
79 int perf_data__create_dir(struct perf_data *data, int nr);
80 int perf_data__open_dir(struct perf_data *data);
81 void perf_data__close_dir(struct perf_data *data);
82 #endif /* __PERF_DATA_H */