d44e3c4f |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | * which accompanies this distribution, and is available at |
6 | * http://www.eclipse.org/legal/epl-v10.html |
7 | * |
8 | * Contributors: |
9 | * Balasko, Jeno |
10 | * Baranyi, Botond |
11 | * |
12 | ******************************************************************************/ |
3abe9331 |
13 | |
14 | #ifndef PROFILERTOOLS_HH |
15 | #define PROFILERTOOLS_HH |
16 | |
17 | #include "Vector.hh" |
18 | #include "Types.h" |
19 | #include <sys/time.h> |
20 | |
21 | namespace Profiler_Tools { |
22 | |
23 | /** Reads a timeval value from the given string. The parameter must contain the |
24 | * string representation of a real number with 6 digits after the decimal dot. */ |
25 | extern timeval string2timeval(const char* str); |
26 | |
27 | /** Returns the string representation of a real number (with 6 digits after the |
28 | * decimal dot) equivalent to the timeval parameter. |
29 | * The returned character pointer needs to be freed. */ |
30 | extern char* timeval2string(timeval tv); |
31 | |
32 | /** Adds the two timeval parameters together and returns the result. */ |
33 | extern timeval add_timeval(const timeval operand1, const timeval operand2); |
34 | |
35 | /** Subtracts the second timeval parameter from the first one and returns the result. */ |
36 | extern timeval subtract_timeval(const timeval operand1, const timeval operand2); |
37 | |
38 | /** Database entry for one file */ |
39 | struct profiler_db_item_t { |
40 | /** Database entry for one line */ |
41 | struct profiler_line_data_t { |
42 | /** Line number */ |
43 | int lineno; |
44 | /** The line's total execution time */ |
45 | timeval total_time; |
46 | /** The number of times this line was executed */ |
47 | int exec_count; |
48 | }; |
49 | /** Database entry for one function (including test cases, alt steps, the control part, etc.) */ |
50 | struct profiler_function_data_t { |
51 | /** Function name (owned) */ |
52 | char* name; |
53 | /** Function starting line */ |
54 | int lineno; |
55 | /** The function's total execution time */ |
56 | timeval total_time; |
57 | /** The number of times this function was executed */ |
58 | int exec_count; |
59 | }; |
60 | /** TTCN-3 File name (relative path, owned) */ |
61 | char* filename; |
62 | /** Contains database entries for all the lines in this file */ |
63 | Vector<profiler_line_data_t> lines; |
64 | /** Contains database entries for all the functions in this file */ |
65 | Vector<profiler_function_data_t> functions; |
66 | }; |
67 | |
68 | /** Profiler database type */ |
69 | typedef Vector<profiler_db_item_t> profiler_db_t; |
70 | |
71 | enum profiler_stats_flag_t { |
72 | // flags for each statistics entry |
73 | STATS_NUMBER_OF_LINES = 0x0000001, |
74 | STATS_LINE_DATA_RAW = 0x0000002, |
75 | STATS_FUNC_DATA_RAW = 0x0000004, |
76 | STATS_LINE_AVG_RAW = 0x0000008, |
77 | STATS_FUNC_AVG_RAW = 0x0000010, |
78 | STATS_LINE_TIMES_SORTED_BY_MOD = 0x0000020, |
79 | STATS_FUNC_TIMES_SORTED_BY_MOD = 0x0000040, |
80 | STATS_LINE_TIMES_SORTED_TOTAL = 0x0000080, |
81 | STATS_FUNC_TIMES_SORTED_TOTAL = 0x0000100, |
82 | STATS_LINE_COUNT_SORTED_BY_MOD = 0x0000200, |
83 | STATS_FUNC_COUNT_SORTED_BY_MOD = 0x0000400, |
84 | STATS_LINE_COUNT_SORTED_TOTAL = 0x0000800, |
85 | STATS_FUNC_COUNT_SORTED_TOTAL = 0x0001000, |
86 | STATS_LINE_AVG_SORTED_BY_MOD = 0x0002000, |
87 | STATS_FUNC_AVG_SORTED_BY_MOD = 0x0004000, |
88 | STATS_LINE_AVG_SORTED_TOTAL = 0x0008000, |
89 | STATS_FUNC_AVG_SORTED_TOTAL = 0x0010000, |
90 | STATS_TOP10_LINE_TIMES = 0x0020000, |
91 | STATS_TOP10_FUNC_TIMES = 0x0040000, |
92 | STATS_TOP10_LINE_COUNT = 0x0080000, |
93 | STATS_TOP10_FUNC_COUNT = 0x0100000, |
94 | STATS_TOP10_LINE_AVG = 0x0200000, |
95 | STATS_TOP10_FUNC_AVG = 0x0400000, |
96 | STATS_UNUSED_LINES = 0x0800000, |
97 | STATS_UNUSED_FUNC = 0x1000000, |
98 | // grouped entries |
99 | STATS_ALL_RAW_DATA = 0x000001E, |
100 | STATS_LINE_DATA_SORTED_BY_MOD = 0x0002220, |
101 | STATS_FUNC_DATA_SORTED_BY_MOD = 0x0004440, |
102 | STATS_LINE_DATA_SORTED_TOTAL = 0x0008880, |
103 | STATS_FUNC_DATA_SORTED_TOTAL = 0x0011100, |
104 | STATS_LINE_DATA_SORTED = 0x000AAA0, |
105 | STATS_FUNC_DATA_SORTED = 0x0015540, |
106 | STATS_ALL_DATA_SORTED = 0x001FFE0, |
107 | STATS_TOP10_LINE_DATA = 0x02A0000, |
108 | STATS_TOP10_FUNC_DATA = 0x0540000, |
109 | STATS_TOP10_ALL_DATA = 0x07E0000, |
110 | STATS_UNUSED_DATA = 0x1800000, |
111 | STATS_ALL = 0x1FFFFFF |
112 | }; |
113 | |
114 | #define STATS_MAX_HEX_DIGITS 7 |
115 | |
116 | /** Returns the index of a TTCN-3 function's entry in the specified database |
117 | * @param p_db profiler database |
118 | * @param p_element index of the file (where the function is declared) |
119 | * @param p_lineno function start line */ |
120 | extern int get_function(const profiler_db_t& p_db, int p_element, int p_lineno); |
121 | |
122 | /** Creates a new TTCN-3 function entry and inserts it in the specified database |
123 | * @param p_db profiler database |
124 | * @param p_element file entry's index |
125 | * @param p_lineno function start line |
126 | * @param p_function_name name of the function */ |
127 | extern void create_function(profiler_db_t& p_db, int p_element, int p_lineno, |
128 | const char* p_function_name); |
129 | |
130 | /** Returns the index of a TTCN-3 code line's entry in the specified database */ |
131 | extern int get_line(const profiler_db_t& p_db, int p_element, int p_lineno); |
132 | |
133 | /** Creates a new TTCN-3 code line entry and inserts it into the specified database */ |
134 | extern void create_line(profiler_db_t& p_db, int p_element, int p_lineno); |
135 | |
136 | /** Adds the data from the database file to the local database |
137 | * @param p_db local database |
138 | * @param p_filename database file name |
3abe9331 |
139 | * @param p_error_function callback function for displaying error messages */ |
140 | extern void import_data(profiler_db_t& p_db, const char* p_filename, |
d44e3c4f |
141 | void (*p_error_function)(const char*, ...)); |
3abe9331 |
142 | |
143 | /** Writes the local database to the database file (overwrites the file) |
144 | * @param p_db local database |
145 | * @param p_filename database file name |
146 | * @param p_disable_profiler discard profiling data |
147 | * @param p_disable_coverage discard code coverage data |
148 | * @param p_error_function callback function for displaying error messages */ |
149 | extern void export_data(profiler_db_t& p_db, const char* p_filename, |
150 | boolean p_disable_profiler, boolean p_disable_coverage, |
151 | void (*p_error_function)(const char*, ...)); |
152 | |
153 | /** Calculates and prints statistics from the gathered data |
154 | * @param p_db local database |
155 | * @param p_filename database file name |
156 | * @param p_disable_profiler discard profiling data |
157 | * @param p_disable_coverage discard code coverage data |
158 | * @param p_flags statistics filter (determines which statistics entries are printed) |
159 | * @param p_error_function callback function for displaying error messages */ |
160 | extern void print_stats(profiler_db_t& p_db, const char* p_filename, |
161 | boolean p_disable_profiler, boolean p_disable_coverage, |
162 | unsigned int p_flags, void (*p_error_function)(const char*, ...)); |
163 | |
164 | } |
165 | |
166 | #endif /* PROFILERTOOLS_HH */ |
167 | |