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
12 ******************************************************************************/
15 #include "../../common/memory.h"
20 static tcov_file_list
*the_files
= 0;
23 static profiler_data_t
*the_data
= 0;
25 /** The current database index for the next get_profiler_code_line() call */
26 static int current_index
= 0;
28 /** The file parameter for the last get_profiler_code_line() call */
29 static char* last_file_name
= 0;
31 void init_profiler_data(tcov_file_list
* p_file_list
)
33 the_files
= p_file_list
;
34 the_data
= (profiler_data_t
*)Malloc(sizeof(profiler_data_t
));
35 the_data
->nof_lines
= 0;
37 the_data
->lines
= (profiler_code_line_t
*)Malloc(
38 the_data
->size
* sizeof(profiler_code_line_t
));
41 boolean
is_file_profiled(const char* p_file_name
)
43 tcov_file_list
* file_walker
= the_files
;
44 while (0 != file_walker
) {
45 if (0 == strcmp(p_file_name
, file_walker
->file_name
)) {
48 /* check for .ttcnpp instead of .ttcn */
49 size_t file_name_len
= strlen(file_walker
->file_name
);
50 if ('p' == file_walker
->file_name
[file_name_len
- 1] &&
51 'p' == file_walker
->file_name
[file_name_len
- 2] &&
52 0 == strncmp(p_file_name
, file_walker
->file_name
, file_name_len
- 2)) {
55 file_walker
= file_walker
->next
;
60 void insert_profiler_code_line(const char* p_file_name
,
61 const char* p_function_name
, int p_line_no
)
63 /* check if the entry already exists */
65 for (i
= 0; i
< the_data
->nof_lines
; ++i
) {
66 if (0 == strcmp(p_file_name
,the_data
->lines
[i
].file_name
) &&
67 p_line_no
== the_data
->lines
[i
].line_no
) {
68 if (0 == the_data
->lines
[i
].function_name
&& 0 != p_function_name
) {
69 the_data
->lines
[i
].function_name
= mcopystr(p_function_name
);
74 if (the_data
->nof_lines
== the_data
->size
) {
75 /* database size reached, increase the buffer size (exponentially) */
77 the_data
->lines
= (profiler_code_line_t
*)Realloc(the_data
->lines
,
78 the_data
->size
* sizeof(profiler_code_line_t
));
80 the_data
->lines
[the_data
->nof_lines
].file_name
= mcopystr(p_file_name
);
81 if (0 != p_function_name
) {
82 the_data
->lines
[the_data
->nof_lines
].function_name
= mcopystr(p_function_name
);
85 the_data
->lines
[the_data
->nof_lines
].function_name
= 0;
87 the_data
->lines
[the_data
->nof_lines
].line_no
= p_line_no
;
88 ++the_data
->nof_lines
;
91 boolean
get_profiler_code_line(const char *p_file_name
,
92 char **p_function_name
, int *p_line_no
)
94 if (0 == last_file_name
|| 0 != strcmp(last_file_name
, p_file_name
)) {
95 /* file parameter changed, reset the current index and store the new file name */
98 last_file_name
= mcopystr(p_file_name
);
100 while (current_index
< the_data
->nof_lines
) {
101 /* find the first entry in the specified file and return it */
102 if (0 == strcmp(p_file_name
, the_data
->lines
[current_index
].file_name
)) {
103 *p_function_name
= the_data
->lines
[current_index
].function_name
;
104 *p_line_no
= the_data
->lines
[current_index
].line_no
;
110 /* no entry found with the specified file name */
114 void free_profiler_data()
117 for (i
= 0; i
< the_data
->nof_lines
; ++i
) {
118 Free(the_data
->lines
[i
].file_name
);
119 Free(the_data
->lines
[i
].function_name
);
121 Free(the_data
->lines
);
123 Free(last_file_name
);
125 while (0 != the_files
) {
126 tcov_file_list
*next_file
= the_files
->next
;
127 Free(the_files
->file_name
);
129 the_files
= next_file
;
This page took 0.033347 seconds and 5 git commands to generate.