linux/tools/perf/util/data.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __PERF_DATA_H
   3#define __PERF_DATA_H
   4
   5#include <stdio.h>
   6#include <stdbool.h>
   7
   8enum perf_data_mode {
   9        PERF_DATA_MODE_WRITE,
  10        PERF_DATA_MODE_READ,
  11};
  12
  13enum perf_dir_version {
  14        PERF_DIR_SINGLE_FILE    = 0,
  15        PERF_DIR_VERSION        = 1,
  16};
  17
  18struct perf_data_file {
  19        char            *path;
  20        union {
  21                int      fd;
  22                FILE    *fptr;
  23        };
  24        unsigned long    size;
  25};
  26
  27struct perf_data {
  28        const char              *path;
  29        struct perf_data_file    file;
  30        bool                     is_pipe;
  31        bool                     is_dir;
  32        bool                     force;
  33        bool                     use_stdio;
  34        bool                     in_place_update;
  35        enum perf_data_mode      mode;
  36
  37        struct {
  38                u64                      version;
  39                struct perf_data_file   *files;
  40                int                      nr;
  41        } dir;
  42};
  43
  44static inline bool perf_data__is_read(struct perf_data *data)
  45{
  46        return data->mode == PERF_DATA_MODE_READ;
  47}
  48
  49static inline bool perf_data__is_write(struct perf_data *data)
  50{
  51        return data->mode == PERF_DATA_MODE_WRITE;
  52}
  53
  54static inline int perf_data__is_pipe(struct perf_data *data)
  55{
  56        return data->is_pipe;
  57}
  58
  59static inline bool perf_data__is_dir(struct perf_data *data)
  60{
  61        return data->is_dir;
  62}
  63
  64static inline bool perf_data__is_single_file(struct perf_data *data)
  65{
  66        return data->dir.version == PERF_DIR_SINGLE_FILE;
  67}
  68
  69static inline int perf_data__fd(struct perf_data *data)
  70{
  71        if (data->use_stdio)
  72                return fileno(data->file.fptr);
  73
  74        return data->file.fd;
  75}
  76
  77int perf_data__open(struct perf_data *data);
  78void perf_data__close(struct perf_data *data);
  79ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size);
  80ssize_t perf_data__write(struct perf_data *data,
  81                              void *buf, size_t size);
  82ssize_t perf_data_file__write(struct perf_data_file *file,
  83                              void *buf, size_t size);
  84/*
  85 * If at_exit is set, only rename current perf.data to
  86 * perf.data.<postfix>, continue write on original data.
  87 * Set at_exit when flushing the last output.
  88 *
  89 * Return value is fd of new output.
  90 */
  91int perf_data__switch(struct perf_data *data,
  92                           const char *postfix,
  93                           size_t pos, bool at_exit, char **new_filepath);
  94
  95int perf_data__create_dir(struct perf_data *data, int nr);
  96int perf_data__open_dir(struct perf_data *data);
  97void perf_data__close_dir(struct perf_data *data);
  98int perf_data__update_dir(struct perf_data *data);
  99unsigned long perf_data__size(struct perf_data *data);
 100int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
 101char *perf_data__kallsyms_name(struct perf_data *data);
 102bool is_perf_data(const char *path);
 103#endif /* __PERF_DATA_H */
 104