FreeRDP
Loading...
Searching...
No Matches
stopwatch.c
1
20#include <freerdp/config.h>
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include <winpr/sysinfo.h>
26#include <freerdp/utils/stopwatch.h>
27
28static void stopwatch_set_time(UINT64* usecs)
29{
30 const UINT64 ns = winpr_GetTickCount64NS();
31 *usecs = WINPR_TIME_NS_TO_US(ns);
32}
33
34STOPWATCH* stopwatch_create(void)
35{
36 STOPWATCH* sw = (STOPWATCH*)calloc(1, sizeof(STOPWATCH));
37 if (!sw)
38 return NULL;
39 stopwatch_reset(sw);
40
41 return sw;
42}
43
44void stopwatch_free(STOPWATCH* stopwatch)
45{
46 free(stopwatch);
47}
48
49void stopwatch_start(STOPWATCH* stopwatch)
50{
51 stopwatch_set_time(&stopwatch->start);
52 stopwatch->count++;
53}
54
55void stopwatch_stop(STOPWATCH* stopwatch)
56{
57 stopwatch_set_time(&stopwatch->end);
58 stopwatch->elapsed += (stopwatch->end - stopwatch->start);
59}
60
61void stopwatch_reset(STOPWATCH* stopwatch)
62{
63 stopwatch->start = 0;
64 stopwatch->end = 0;
65 stopwatch->elapsed = 0;
66 stopwatch->count = 0;
67}
68
69double stopwatch_get_elapsed_time_in_seconds(STOPWATCH* stopwatch)
70{
71 const long double ld = stopwatch->elapsed / 1000000.0L;
72 return (double)ld;
73}
74
75void stopwatch_get_elapsed_time_in_useconds(STOPWATCH* stopwatch, UINT32* sec, UINT32* usec)
76{
77 *sec = (UINT32)stopwatch->elapsed / 1000000;
78 *usec = (UINT32)stopwatch->elapsed % 1000000;
79}