data.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. };
  12. struct perf_data {
  13. struct perf_data_file file;
  14. bool is_pipe;
  15. bool force;
  16. unsigned long size;
  17. enum perf_data_mode mode;
  18. };
  19. static inline bool perf_data__is_read(struct perf_data *data)
  20. {
  21. return data->mode == PERF_DATA_MODE_READ;
  22. }
  23. static inline bool perf_data__is_write(struct perf_data *data)
  24. {
  25. return data->mode == PERF_DATA_MODE_WRITE;
  26. }
  27. static inline int perf_data__is_pipe(struct perf_data *data)
  28. {
  29. return data->is_pipe;
  30. }
  31. static inline int perf_data__fd(struct perf_data *data)
  32. {
  33. return data->file.fd;
  34. }
  35. static inline unsigned long perf_data__size(struct perf_data *data)
  36. {
  37. return data->size;
  38. }
  39. int perf_data__open(struct perf_data *data);
  40. void perf_data__close(struct perf_data *data);
  41. ssize_t perf_data__write(struct perf_data *data,
  42. void *buf, size_t size);
  43. ssize_t perf_data_file__write(struct perf_data_file *file,
  44. void *buf, size_t size);
  45. /*
  46. * If at_exit is set, only rename current perf.data to
  47. * perf.data.<postfix>, continue write on original data.
  48. * Set at_exit when flushing the last output.
  49. *
  50. * Return value is fd of new output.
  51. */
  52. int perf_data__switch(struct perf_data *data,
  53. const char *postfix,
  54. size_t pos, bool at_exit);
  55. #endif /* __PERF_DATA_H */