data.h 1.3 KB

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