time-utils.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _TIME_UTILS_H_
  3. #define _TIME_UTILS_H_
  4. #include <stddef.h>
  5. #include <time.h>
  6. #include <linux/types.h>
  7. struct perf_time_interval {
  8. u64 start, end;
  9. };
  10. int parse_nsec_time(const char *str, u64 *ptime);
  11. int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
  12. int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
  13. const char *ostr, u64 start, u64 end);
  14. struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size);
  15. bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
  16. bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
  17. int num, u64 timestamp);
  18. struct perf_session;
  19. int perf_time__parse_for_ranges_reltime(const char *str, struct perf_session *session,
  20. struct perf_time_interval **ranges,
  21. int *range_size, int *range_num,
  22. bool reltime);
  23. int perf_time__parse_for_ranges(const char *str, struct perf_session *session,
  24. struct perf_time_interval **ranges,
  25. int *range_size, int *range_num);
  26. int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
  27. int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz);
  28. int fetch_current_timestamp(char *buf, size_t sz);
  29. static inline unsigned long long rdclock(void)
  30. {
  31. struct timespec ts;
  32. clock_gettime(CLOCK_MONOTONIC, &ts);
  33. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  34. }
  35. #endif