18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __PERF_DATA_H 38c2ecf20Sopenharmony_ci#define __PERF_DATA_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <stdbool.h> 68c2ecf20Sopenharmony_ci#include <linux/types.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cienum perf_data_mode { 98c2ecf20Sopenharmony_ci PERF_DATA_MODE_WRITE, 108c2ecf20Sopenharmony_ci PERF_DATA_MODE_READ, 118c2ecf20Sopenharmony_ci}; 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cienum perf_dir_version { 148c2ecf20Sopenharmony_ci PERF_DIR_SINGLE_FILE = 0, 158c2ecf20Sopenharmony_ci PERF_DIR_VERSION = 1, 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct perf_data_file { 198c2ecf20Sopenharmony_ci char *path; 208c2ecf20Sopenharmony_ci int fd; 218c2ecf20Sopenharmony_ci unsigned long size; 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct perf_data { 258c2ecf20Sopenharmony_ci const char *path; 268c2ecf20Sopenharmony_ci struct perf_data_file file; 278c2ecf20Sopenharmony_ci bool is_pipe; 288c2ecf20Sopenharmony_ci bool is_dir; 298c2ecf20Sopenharmony_ci bool force; 308c2ecf20Sopenharmony_ci enum perf_data_mode mode; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci struct { 338c2ecf20Sopenharmony_ci u64 version; 348c2ecf20Sopenharmony_ci struct perf_data_file *files; 358c2ecf20Sopenharmony_ci int nr; 368c2ecf20Sopenharmony_ci } dir; 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic inline bool perf_data__is_read(struct perf_data *data) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci return data->mode == PERF_DATA_MODE_READ; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline bool perf_data__is_write(struct perf_data *data) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci return data->mode == PERF_DATA_MODE_WRITE; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic inline int perf_data__is_pipe(struct perf_data *data) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci return data->is_pipe; 528c2ecf20Sopenharmony_ci} 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic inline bool perf_data__is_dir(struct perf_data *data) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci return data->is_dir; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline bool perf_data__is_single_file(struct perf_data *data) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci return data->dir.version == PERF_DIR_SINGLE_FILE; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic inline int perf_data__fd(struct perf_data *data) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci return data->file.fd; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciint perf_data__open(struct perf_data *data); 708c2ecf20Sopenharmony_civoid perf_data__close(struct perf_data *data); 718c2ecf20Sopenharmony_cissize_t perf_data__write(struct perf_data *data, 728c2ecf20Sopenharmony_ci void *buf, size_t size); 738c2ecf20Sopenharmony_cissize_t perf_data_file__write(struct perf_data_file *file, 748c2ecf20Sopenharmony_ci void *buf, size_t size); 758c2ecf20Sopenharmony_ci/* 768c2ecf20Sopenharmony_ci * If at_exit is set, only rename current perf.data to 778c2ecf20Sopenharmony_ci * perf.data.<postfix>, continue write on original data. 788c2ecf20Sopenharmony_ci * Set at_exit when flushing the last output. 798c2ecf20Sopenharmony_ci * 808c2ecf20Sopenharmony_ci * Return value is fd of new output. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_ciint perf_data__switch(struct perf_data *data, 838c2ecf20Sopenharmony_ci const char *postfix, 848c2ecf20Sopenharmony_ci size_t pos, bool at_exit, char **new_filepath); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciint perf_data__create_dir(struct perf_data *data, int nr); 878c2ecf20Sopenharmony_ciint perf_data__open_dir(struct perf_data *data); 888c2ecf20Sopenharmony_civoid perf_data__close_dir(struct perf_data *data); 898c2ecf20Sopenharmony_ciint perf_data__update_dir(struct perf_data *data); 908c2ecf20Sopenharmony_ciunsigned long perf_data__size(struct perf_data *data); 918c2ecf20Sopenharmony_ciint perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz); 928c2ecf20Sopenharmony_cichar *perf_data__kallsyms_name(struct perf_data *data); 938c2ecf20Sopenharmony_ci#endif /* __PERF_DATA_H */ 94