blob: ddf65dcbbc1ac4a5d898471bdb8bc874db6225c7 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef __STIMER_H
20#define __STIMER_H
21
22#include <time.h>
23
24typedef long long int stimer_t;
25
26#define STIMER_GET_CURRENT_TP(__now__) \
27({ \
28 struct timespec __ts__; \
29 __now__ = clock_gettime(CLOCK_REALTIME,&__ts__) ? \
30 -1 : (((stimer_t)__ts__.tv_sec) * 1000000000) + ((stimer_t)__ts__.tv_nsec); \
31 __now__; \
32})
33
34#define STIMER_GET_ELAPSED_NS(_start_) \
35({ \
36 stimer_t __ns__; \
37 STIMER_GET_CURRENT_TP(__ns__); \
38 if (__ns__ != -1) \
39 __ns__ -= _start_; \
40 __ns__; \
41})
42
43#define STIMER_GET_ELAPSED_US(__start__) \
44({ \
45 stimer_t __us__ = STIMER_GET_ELAPSED_NS(__start__); \
46 if (__us__ != -1) \
47 __us__ = (__us__ / 1000) + (__us__ % 1000 >= 500 ? 1 : 0); \
48 __us__; \
49})
50
51#define STIMER_GET_ELAPSED_MS(___start___) \
52({ \
53 stimer_t __ms__ = STIMER_GET_ELAPSED_US(___start___); \
54 if (__ms__ != -1) \
55 __ms__ = (__ms__ / 1000) + (__ms__ % 1000 >= 500 ? 1 : 0); \
56 __ms__; \
57})
58
59#endif
60