1 #include "functional_trace.h"
\r
3 functional_trace dol_functional_trace;
\r
5 functional_trace::functional_trace()
\r
8 strcpy(trace_file_name, "trace1.txt");
\r
13 functional_trace::~functional_trace()
\r
16 char temp[NAME_LENGTH];
\r
17 #ifdef INCLUDE_TRACE
\r
18 strcpy(trace_file_name, "trace");
\r
19 sprintf(temp, "%d", file_index);
\r
20 strcat(trace_file_name, temp);
\r
21 strcat(trace_file_name, ".txt");
\r
22 write_to_file(trace_file_name);
\r
24 //printf("The traces in the memory have been freed\n");
\r
29 void functional_trace::add_event_node(TRACE_EVENT &trace_event)
\r
31 Process_Trace *process_trace_ptr;
\r
32 char temp[NAME_LENGTH];
\r
34 process_trace_ptr = get_process_trace(trace_event.process_name);
\r
35 if (process_trace_ptr == NULL)
\r
37 process_trace_ptr = new Process_Trace(trace_event.process_name);
\r
38 _list_process_trace.push_back(process_trace_ptr);
\r
41 process_trace_ptr->add_entry(&trace_event);
\r
44 if (event_num > 8000000)
\r
46 strcpy(trace_file_name, "trace");
\r
47 sprintf(temp, "%d", file_index);
\r
48 strcat(trace_file_name, temp);
\r
49 strcat(trace_file_name, ".txt");
\r
50 write_to_file(trace_file_name);
\r
59 void functional_trace::add_event_node(TRACE_EVENT &trace_event)
\r
61 XMLNode process_node;
\r
62 char temp[NAME_LENGTH];
\r
63 process_node = xml_main_node.getChildNode(trace_event.process_name);
\r
65 if(process_node.isEmpty())
\r
67 process_node = xml_main_node.addChild(trace_event.process_name);
\r
70 XMLNode event_node = process_node.addChild("event");
\r
72 event_node.addAttribute("type", trace_event_type_string[trace_event.event_type]);
\r
74 if(trace_event.event_type == COMPUTATION_EVENT)
\r
77 sprintf(temp, "%d", trace_event.computation_start_line);
\r
78 event_node.addAttribute("start", temp);
\r
79 sprintf(temp, "%d", trace_event.computation_end_line);
\r
80 event_node.addAttribute("end", temp);
\r
82 else if((trace_event.event_type == READ_EVENT) || (trace_event.event_type == WRITE_EVENT))
\r
84 sprintf(temp, "%d", trace_event.data_num);
\r
85 event_node.addAttribute("data_num", temp);
\r
86 event_node.addAttribute("channel_name", trace_event.channel_name);
\r
91 void functional_trace::create_computation_event(const char *process_name, int start_line, int end_line)
\r
93 TRACE_EVENT trace_event;
\r
95 trace_event.event_type = COMPUTATION_EVENT;
\r
96 strcpy(trace_event.process_name, process_name);
\r
97 trace_event.computation_start_line = start_line;
\r
98 trace_event.computation_end_line = end_line;
\r
99 strcpy(trace_event.channel_name, "");
\r
100 trace_event.data_num = 0;
\r
102 add_event_node(trace_event);
\r
105 void functional_trace::create_read_event(const char *process_name, int data_num, const char *channel_name)
\r
108 TRACE_EVENT trace_event;
\r
109 trace_event.event_type = READ_EVENT;
\r
110 strcpy(trace_event.process_name, process_name);
\r
111 trace_event.data_num = data_num;
\r
112 strcpy(trace_event.channel_name, channel_name);
\r
114 trace_event.computation_start_line = 0;
\r
115 trace_event.computation_end_line = 0;
\r
117 add_event_node(trace_event);
\r
120 void functional_trace::create_write_event(const char *process_name, int data_num, const char *channel_name)
\r
123 TRACE_EVENT trace_event;
\r
124 trace_event.event_type = WRITE_EVENT;
\r
125 strcpy(trace_event.process_name, process_name);
\r
126 trace_event.data_num = data_num;
\r
127 strcpy(trace_event.channel_name, channel_name);
\r
129 trace_event.computation_start_line = 0;
\r
130 trace_event.computation_end_line = 0;
\r
132 add_event_node(trace_event);
\r
136 Process_Trace *functional_trace::get_process_trace(const char *process_name)
\r
138 Process_Trace *process_trace_ptr;
\r
140 for (_iter_process_trace = _list_process_trace.begin();
\r
141 _iter_process_trace != _list_process_trace.end();
\r
142 _iter_process_trace++)
\r
144 process_trace_ptr = *_iter_process_trace;
\r
146 if (strcmp(process_trace_ptr->get_name(), process_name) == 0)
\r
152 if (_iter_process_trace == _list_process_trace.end())
\r
154 process_trace_ptr = NULL;
\r
157 return process_trace_ptr;
\r
160 void functional_trace::free_traces()
\r
162 Process_Trace *process_trace_ptr;
\r
164 for (_iter_process_trace = _list_process_trace.begin();
\r
165 _iter_process_trace != _list_process_trace.end();
\r
166 _iter_process_trace++)
\r
168 process_trace_ptr = *_iter_process_trace;
\r
169 delete process_trace_ptr;
\r
171 _list_process_trace.clear();
\r
174 int functional_trace::write_to_file(const char *trace_file_name) {
\r
176 Process_Trace *process_trace_ptr;
\r
177 FILE *trace_file_handle;
\r
178 EVENT_ENTRY *event_entry_ptr;
\r
180 if ((trace_file_handle = fopen(trace_file_name, "w")) == NULL) {
\r
182 printf("Can not create file: %s\n", trace_file_name);
\r
186 for (_iter_process_trace = _list_process_trace.begin();
\r
187 _iter_process_trace != _list_process_trace.end();
\r
188 _iter_process_trace++) {
\r
189 process_trace_ptr = *_iter_process_trace;
\r
190 fprintf(trace_file_handle, "$ %s\n", process_trace_ptr->get_name());
\r
192 event_entry_ptr = process_trace_ptr->get_head_entry();
\r
193 while (event_entry_ptr != NULL) {
\r
194 if (event_entry_ptr->event_type == COMPUTATION_EVENT) {
\r
195 if (event_entry_ptr->end_line!=(event_entry_ptr->start_line+1))
\r
196 fprintf(trace_file_handle, "c %d %d\n",
\r
197 event_entry_ptr->start_line,
\r
198 event_entry_ptr->end_line);
\r
200 else if (event_entry_ptr->event_type == WRITE_EVENT) {
\r
201 fprintf(trace_file_handle, "w %d %s\n",
\r
202 event_entry_ptr->data_num,
\r
203 event_entry_ptr->channel_name);
\r
205 else if (event_entry_ptr->event_type == READ_EVENT) {
\r
206 fprintf(trace_file_handle, "r %d %s\n",
\r
207 event_entry_ptr->data_num,
\r
208 event_entry_ptr->channel_name);
\r
211 event_entry_ptr = event_entry_ptr->next;
\r
215 fflush(trace_file_handle);
\r
216 fseek(trace_file_handle, 0, SEEK_SET);
\r
217 fclose(trace_file_handle);
\r
223 Process_Trace::Process_Trace(const char *process_name)
\r
225 strcpy(_process_name, process_name);
\r
230 Process_Trace::~Process_Trace()
\r
234 while (_head != NULL)
\r
237 _head = _head->next;
\r
238 if (temp->channel_name != NULL)
\r
239 delete [] temp->channel_name;
\r
244 const char *Process_Trace::get_name()
\r
246 return _process_name;
\r
249 EVENT_ENTRY *Process_Trace::get_head_entry()
\r
254 int Process_Trace::add_entry(TRACE_EVENT *trace_event_ptr)
\r
258 int channel_name_length;
\r
260 temp = new EVENT_ENTRY;
\r
261 memset(temp, 0, sizeof(EVENT_ENTRY));
\r
263 temp->event_type = trace_event_ptr->event_type;
\r
264 temp->start_line = trace_event_ptr->computation_start_line;
\r
265 temp->end_line = trace_event_ptr->computation_end_line;
\r
266 temp->data_num = trace_event_ptr->data_num;
\r
268 channel_name_length = strlen(trace_event_ptr->channel_name);
\r
269 if (channel_name_length != 0)
\r
271 temp->channel_name = new char[channel_name_length + 1];
\r
272 strcpy(temp->channel_name, trace_event_ptr->channel_name);
\r
276 temp->channel_name = NULL;
\r
287 _tail->next = temp;
\r