data.h 2.5 KB

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