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/profiler.h>
22 PROFILER* profiler_create(char* name)
26 profiler = (PROFILER*) xmalloc(sizeof(PROFILER));
28 profiler->name = name;
29 profiler->stopwatch = stopwatch_create();
34 void profiler_free(PROFILER* profiler)
36 stopwatch_free(profiler->stopwatch);
41 void profiler_enter(PROFILER* profiler)
43 stopwatch_start(profiler->stopwatch);
46 void profiler_exit(PROFILER* profiler)
48 stopwatch_stop(profiler->stopwatch);
51 void profiler_print_header()
54 printf(" |-----------------------|\n" );
55 printf(" PROFILER | elapsed seconds |\n" );
56 printf("|--------------------------------------------|-----------------------|\n" );
57 printf("| code section | iterations | total | avg. |\n" );
58 printf("|-------------------------------|------------|-----------|-----------|\n" );
61 void profiler_print(PROFILER* profiler)
63 double elapsed_sec = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
64 double avg_sec = elapsed_sec / (double) profiler->stopwatch->count;
66 printf("| %-30.30s| %'10lu | %'9f | %'9f |\n", profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec);
69 void profiler_print_footer()
71 printf("|--------------------------------------------------------------------|\n" );