blob: 4f42988eb2f7cc3a7510c5c0b6eff50faa32e256 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Ahernfdf9dc42016-11-29 10:15:41 -07002#ifndef _TIME_UTILS_H_
3#define _TIME_UTILS_H_
4
Arnaldo Carvalho de Meloc5e40272017-04-19 16:12:39 -03005#include <stddef.h>
Arnaldo Carvalho de Melof3711022019-08-29 15:16:27 -03006#include <time.h>
Arnaldo Carvalho de Meloc5e40272017-04-19 16:12:39 -03007#include <linux/types.h>
8
David Ahernfdf9dc42016-11-29 10:15:41 -07009struct perf_time_interval {
10 u64 start, end;
11};
12
David Ahernc284d662016-11-29 10:15:42 -070013int parse_nsec_time(const char *str, u64 *ptime);
14
David Ahernfdf9dc42016-11-29 10:15:41 -070015int perf_time__parse_str(struct perf_time_interval *ptime, const char *ostr);
16
Jin Yao13a70f32017-12-08 21:13:43 +080017int perf_time__percent_parse_str(struct perf_time_interval *ptime_buf, int num,
18 const char *ostr, u64 start, u64 end);
19
Jin Yao5a031f82018-01-10 23:00:31 +080020struct perf_time_interval *perf_time__range_alloc(const char *ostr, int *size);
21
David Ahernfdf9dc42016-11-29 10:15:41 -070022bool perf_time__skip_sample(struct perf_time_interval *ptime, u64 timestamp);
23
Jin Yao9a9b8b42017-12-08 21:13:44 +080024bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
25 int num, u64 timestamp);
26
Jin Yao284c4e12019-03-01 18:13:06 +080027struct perf_session;
28
29int perf_time__parse_for_ranges(const char *str, struct perf_session *session,
30 struct perf_time_interval **ranges,
31 int *range_size, int *range_num);
32
Arnaldo Carvalho de Meloc5e40272017-04-19 16:12:39 -030033int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
Andi Kleenf8c856c2019-03-05 06:47:53 -080034int timestamp__scnprintf_nsec(u64 timestamp, char *buf, size_t sz);
Arnaldo Carvalho de Meloc5e40272017-04-19 16:12:39 -030035
36int fetch_current_timestamp(char *buf, size_t sz);
37
Arnaldo Carvalho de Melof3711022019-08-29 15:16:27 -030038static inline unsigned long long rdclock(void)
39{
40 struct timespec ts;
41
42 clock_gettime(CLOCK_MONOTONIC, &ts);
43 return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
44}
45
David Ahernfdf9dc42016-11-29 10:15:41 -070046#endif