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