xref: /OK3568_Linux_fs/app/lvgl_demo/sys/timestamp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <sys/time.h>
5 #include <unistd.h>
6 
clock_ms(void)7 uint32_t clock_ms(void)
8 {
9     struct timeval tv;
10     gettimeofday(&tv,NULL);
11     return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
12 }
13 
clock_us(void)14 uint64_t clock_us(void)
15 {
16     struct timeval tv;
17     gettimeofday(&tv,NULL);
18     return (tv.tv_sec * 1000000 + tv.tv_usec);
19 }
20 
timestamp(char * fmt,int index,int start)21 void timestamp(char *fmt, int index, int start)
22 {
23     static long int st[128];
24     struct timeval t;
25 
26     if (start)
27     {
28         printf("[%d %s]", index, fmt);
29         gettimeofday(&t,NULL);
30         st[index] = t.tv_sec * 1000000 + t.tv_usec;
31     }
32     else
33     {
34         gettimeofday(&t,NULL);
35         printf("[%d # cost %ld us]\n", index, (t.tv_sec * 1000000 + t.tv_usec) - st[index]);
36     }
37 }
38 
39