data.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_DATA_H
  3. #define __PERF_DATA_H
  4. #include <stdbool.h>
  5. enum perf_data_mode {
  6. PERF_DATA_MODE_WRITE,
  7. PERF_DATA_MODE_READ,
  8. };
  9. struct perf_data_file {
  10. const char *path;
  11. int fd;
  12. bool is_pipe;
  13. bool force;
  14. unsigned long size;
  15. enum perf_data_mode mode;
  16. };
  17. static inline bool perf_data_file__is_read(struct perf_data_file *file)
  18. {
  19. return file->mode == PERF_DATA_MODE_READ;
  20. }
  21. static inline bool perf_data_file__is_write(struct perf_data_file *file)
  22. {
  23. return file->mode == PERF_DATA_MODE_WRITE;
  24. }
  25. static inline int perf_data_file__is_pipe(struct perf_data_file *file)
  26. {
  27. return file->is_pipe;
  28. }
  29. static inline int perf_data_file__fd(struct perf_data_file *file)
  30. {
  31. return file->fd;
  32. }
  33. static inline unsigned long perf_data_file__size(struct perf_data_file *file)
  34. {
  35. return file->size;
  36. }
  37. int perf_data_file__open(struct perf_data_file *file);
  38. void perf_data_file__close(struct perf_data_file *file);
  39. ssize_t perf_data_file__write(struct perf_data_file *file,
  40. void *buf, size_t size);
  41. /*
  42. * If at_exit is set, only rename current perf.data to
  43. * perf.data.<postfix>, continue write on original file.
  44. * Set at_exit when flushing the last output.
  45. *
  46. * Return value is fd of new output.
  47. */
  48. int perf_data_file__switch(struct perf_data_file *file,
  49. const char *postfix,
  50. size_t pos, bool at_exit);
  51. #endif /* __PERF_DATA_H */