2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Stephen Erisman
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <freerdp/utils/stopwatch.h>
22 STOPWATCH* stopwatch_create()
26 sw = (STOPWATCH*) xmalloc(sizeof(STOPWATCH));
32 void stopwatch_free(STOPWATCH* stopwatch)
37 void stopwatch_start(STOPWATCH* stopwatch)
39 stopwatch->start = clock();
43 void stopwatch_stop(STOPWATCH* stopwatch)
45 stopwatch->end = clock();
46 stopwatch->elapsed += (stopwatch->end - stopwatch->start);
49 void stopwatch_reset(STOPWATCH* stopwatch)
53 stopwatch->elapsed = 0;
57 double stopwatch_get_elapsed_time_in_seconds(STOPWATCH* stopwatch)
59 return ((double) stopwatch->elapsed) / CLOCKS_PER_SEC;
62 void stopwatch_get_elapsed_time_in_useconds(STOPWATCH* stopwatch, uint32* sec, uint32* usec)
65 double clocks_per_usec;
67 *sec = ((uint32) stopwatch->elapsed) / CLOCKS_PER_SEC;
68 uelapsed = stopwatch->elapsed - ((double)(*sec) * CLOCKS_PER_SEC);
70 clocks_per_usec = (CLOCKS_PER_SEC / 1000000);
72 if (clocks_per_usec > 0.0)
73 *usec = (uint32)(uelapsed / clocks_per_usec);