160d4bdb |
1 | #include <stdio.h> |
ee26cd96 |
2 | #include <unistd.h> |
160d4bdb |
3 | #include <fcntl.h> |
4 | #include <sys/stat.h> |
5 | #include <sys/types.h> |
ee26cd96 |
6 | #include <errno.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
160d4bdb |
9 | |
10 | #include <glib.h> |
11 | #include "LTTTypes.h" |
12 | #include "LinuxEvents.h" |
13 | |
c9e8ac96 |
14 | #define TRACE_HEARTBEAT_ID 19 |
1812dbb9 |
15 | #define PROCESS_FORK_ID 20 |
16 | #define PROCESS_EXIT_ID 21 |
17 | |
c9e8ac96 |
18 | #define INFO_ENTRY 9 |
ee26cd96 |
19 | #define OVERFLOW_FIGURE 0x100000000ULL |
c9e8ac96 |
20 | |
1812dbb9 |
21 | typedef struct _new_process |
22 | { |
23 | uint32_t event_data1; /* Data associated with event */ |
24 | uint32_t event_data2; |
25 | } LTT_PACKED_STRUCT new_process; |
26 | |
160d4bdb |
27 | #define write_to_buffer(DEST, SRC, SIZE) \ |
28 | do\ |
29 | {\ |
30 | memcpy(DEST, SRC, SIZE);\ |
31 | DEST += SIZE;\ |
32 | } while(0); |
33 | |
34 | int readFile(int fd, void * buf, size_t size, char * mesg) |
35 | { |
ee26cd96 |
36 | ssize_t nbBytes = read(fd, buf, size); |
37 | |
8d1e6362 |
38 | if((size_t)nbBytes != size) { |
39 | if(nbBytes < 0) { |
40 | perror("Error in readFile : "); |
41 | } else { |
42 | printf("%s\n",mesg); |
43 | } |
160d4bdb |
44 | exit(1); |
45 | } |
46 | return 0; |
47 | } |
48 | |
49 | void getDataEndianType(char * size, char * endian) |
50 | { |
51 | int i = 1; |
52 | char c = (char) i; |
53 | int sizeInt=sizeof(int), sizeLong=sizeof(long), sizePointer=sizeof(void *); |
54 | |
55 | if(c == 1) strcpy(endian,"LITTLE_ENDIAN"); |
56 | else strcpy(endian, "BIG_ENDIAN"); |
57 | |
58 | if(sizeInt == 2 && sizeLong == 4 && sizePointer == 4) |
59 | strcpy(size,"LP32"); |
60 | else if(sizeInt == 4 && sizeLong == 4 && sizePointer == 4) |
61 | strcpy(size,"ILP32"); |
62 | else if(sizeInt == 4 && sizeLong == 8 && sizePointer == 8) |
63 | strcpy(size,"LP64"); |
64 | else if(sizeInt == 8 && sizeLong == 8 && sizePointer == 8) |
65 | strcpy(size,"ILP64"); |
66 | else strcpy(size,"UNKNOWN"); |
67 | } |
68 | |
69 | #define BUFFER_SIZE 80 |
70 | |
71 | typedef struct _buffer_start{ |
72 | uint32_t seconds; |
73 | uint32_t nanoseconds; |
74 | uint64_t cycle_count; |
75 | uint32_t block_id; |
76 | } __attribute__ ((packed)) buffer_start; |
77 | |
78 | typedef struct _heartbeat{ |
79 | uint32_t seconds; |
80 | uint32_t nanoseconds; |
81 | uint64_t cycle_count; |
82 | } __attribute__ ((packed)) heartbeat; |
83 | |
84 | |
85 | int main(int argc, char ** argv){ |
86 | |
91a66e87 |
87 | int fd, fdCpu; |
160d4bdb |
88 | FILE * fp; |
89 | int fdFac, fdIntr, fdProc; |
90 | char arch_size[BUFFER_SIZE]; |
91 | char endian[BUFFER_SIZE]; |
92 | char node_name[BUFFER_SIZE]; |
93 | char domainname[BUFFER_SIZE]; |
94 | char kernel_name[BUFFER_SIZE]; |
95 | char kernel_release[BUFFER_SIZE]; |
96 | char kernel_version[BUFFER_SIZE]; |
97 | char machine[BUFFER_SIZE]; |
98 | char processor[BUFFER_SIZE]; |
99 | char hardware_platform[BUFFER_SIZE]; |
100 | char operating_system[BUFFER_SIZE]; |
101 | int cpu; |
cf74a6f1 |
102 | int ltt_block_size=0; |
103 | int ltt_major_version=0; |
104 | int ltt_minor_version=0; |
160d4bdb |
105 | int ltt_log_cpu; |
106 | char buf[BUFFER_SIZE]; |
ee26cd96 |
107 | int i, k; |
160d4bdb |
108 | |
109 | uint8_t cpu_id; |
110 | |
111 | char foo[4*BUFFER_SIZE]; |
112 | char foo_eventdefs[4*BUFFER_SIZE]; |
113 | char foo_control[4*BUFFER_SIZE]; |
114 | char foo_cpu[4*BUFFER_SIZE]; |
115 | char foo_info[4*BUFFER_SIZE]; |
116 | |
117 | char foo_control_facilities[4*BUFFER_SIZE]; |
118 | char foo_control_processes[4*BUFFER_SIZE]; |
119 | char foo_control_interrupts[4*BUFFER_SIZE]; |
120 | char foo_info_system[4*BUFFER_SIZE]; |
121 | |
122 | struct stat lTDFStat; |
123 | off_t file_size; |
124 | int block_number, block_size; |
91a66e87 |
125 | char * buffer, *buf_out, cpuStr[4*BUFFER_SIZE]; |
160d4bdb |
126 | char * buf_fac, * buf_intr, * buf_proc; |
91a66e87 |
127 | void * write_pos, *write_pos_fac, * write_pos_intr, *write_pos_proc; |
160d4bdb |
128 | trace_start *tStart; |
129 | trace_buffer_start *tBufStart; |
130 | trace_buffer_end *tBufEnd; |
131 | trace_file_system * tFileSys; |
1812dbb9 |
132 | uint16_t newId, startId, tmpId; |
160d4bdb |
133 | uint8_t evId; |
ee26cd96 |
134 | uint32_t time_delta, startTimeDelta; |
160d4bdb |
135 | void * cur_pos, *end_pos; |
c9e8ac96 |
136 | buffer_start start, start_proc, start_intr; |
137 | buffer_start end, end_proc, end_intr; |
160d4bdb |
138 | heartbeat beat; |
139 | int beat_count = 0; |
160d4bdb |
140 | uint32_t size_lost; |
141 | int reserve_size = sizeof(buffer_start) + sizeof(uint16_t) + 2*sizeof(uint32_t);//lost_size and buffer_end event |
91a66e87 |
142 | int nb_para; |
160d4bdb |
143 | |
1812dbb9 |
144 | new_process process; |
145 | |
91a66e87 |
146 | if(argc < 4){ |
bc61167f |
147 | printf("Usage : ./convert processfile_name number_of_cpu tracefile1 tracefile2 ... trace_creation_directory\n"); |
148 | printf("For more details, see README.\n"); |
160d4bdb |
149 | exit(1); |
150 | } |
151 | |
91a66e87 |
152 | cpu = atoi(argv[2]); |
153 | printf("cpu number = %d\n", cpu); |
154 | nb_para = 3 + cpu; |
155 | |
156 | if(argc != nb_para && argc != nb_para+1){ |
157 | printf("need trace files and cpu number or root directory for the new tracefile\n"); |
158 | exit(1); |
159 | } |
160 | |
161 | if(argc == nb_para){ |
160d4bdb |
162 | strcpy(foo, "foo"); |
163 | strcpy(foo_eventdefs, "foo/eventdefs"); |
164 | strcpy(foo_control, "foo/control"); |
165 | strcpy(foo_cpu, "foo/cpu"); |
166 | strcpy(foo_info, "foo/info"); |
167 | }else{ |
91a66e87 |
168 | strcpy(foo, argv[nb_para]); |
169 | strcpy(foo_eventdefs, argv[nb_para]); |
160d4bdb |
170 | strcat(foo_eventdefs,"/eventdefs"); |
91a66e87 |
171 | strcpy(foo_control, argv[nb_para]); |
160d4bdb |
172 | strcat(foo_control,"/control"); |
91a66e87 |
173 | strcpy(foo_cpu, argv[nb_para]); |
160d4bdb |
174 | strcat(foo_cpu,"/cpu"); |
91a66e87 |
175 | strcpy(foo_info, argv[nb_para]); |
160d4bdb |
176 | strcat(foo_info,"/info"); |
177 | } |
178 | strcpy(foo_control_facilities, foo_control); |
179 | strcat(foo_control_facilities,"/facilities"); |
180 | strcpy(foo_control_processes, foo_control); |
181 | strcat(foo_control_processes, "/processes"); |
182 | strcpy(foo_control_interrupts, foo_control); |
183 | strcat(foo_control_interrupts, "/interrupts"); |
184 | strcpy(foo_info_system, foo_info); |
185 | strcat(foo_info_system, "/system.xml"); |
186 | |
160d4bdb |
187 | |
188 | getDataEndianType(arch_size, endian); |
189 | printf("Arch_size: %s, Endian: %s\n", arch_size, endian); |
190 | |
191 | fp = fopen("sysInfo.out","r"); |
192 | if(!fp){ |
193 | g_error("Unable to open file sysInfo.out\n"); |
194 | } |
195 | |
c9e8ac96 |
196 | for(i=0;i<INFO_ENTRY;i++){ |
160d4bdb |
197 | if(!fgets(buf,BUFFER_SIZE-1,fp)) |
198 | g_error("The format of sysInfo.out is not right\n"); |
199 | if(strncmp(buf,"node_name=",10)==0){ |
200 | strcpy(node_name,&buf[10]); |
201 | node_name[strlen(node_name)-1] = '\0'; |
202 | }else if(strncmp(buf,"domainname=",11)==0){ |
203 | strcpy(domainname,&buf[11]); |
204 | domainname[strlen(domainname)-1] = '\0'; |
205 | }else if(strncmp(buf,"kernel_name=",12)==0){ |
206 | strcpy(kernel_name,&buf[12]); |
207 | kernel_name[strlen(kernel_name)-1] = '\0'; |
208 | }else if(strncmp(buf,"kernel_release=",15)==0){ |
209 | strcpy(kernel_release,&buf[15]); |
210 | kernel_release[strlen(kernel_release)-1] = '\0'; |
211 | }else if(strncmp(buf,"kernel_version=",15)==0){ |
212 | strcpy(kernel_version,&buf[15]); |
213 | kernel_version[strlen(kernel_version)-1] = '\0'; |
214 | }else if(strncmp(buf,"machine=",8)==0){ |
215 | strcpy(machine,&buf[8]); |
216 | machine[strlen(machine)-1] = '\0'; |
217 | }else if(strncmp(buf,"processor=",10)==0){ |
218 | strcpy(processor,&buf[10]); |
219 | processor[strlen(processor)-1] = '\0'; |
220 | }else if(strncmp(buf,"hardware_platform=",18)==0){ |
221 | strcpy(hardware_platform,&buf[18]); |
222 | hardware_platform[strlen(hardware_platform)-1] = '\0'; |
223 | }else if(strncmp(buf,"operating_system=",17)==0){ |
224 | strcpy(operating_system,&buf[17]); |
225 | operating_system[strlen(operating_system)-1] = '\0'; |
226 | } |
227 | } |
228 | fclose(fp); |
229 | |
230 | if(mkdir(foo, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH)) |
231 | g_error("can not make %s directory", foo); |
232 | if(mkdir(foo_info, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH)) |
233 | g_error("can not make %s directory", foo_info); |
234 | if(mkdir(foo_cpu, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH)) |
235 | g_error("can not make %s directory", foo_cpu); |
236 | if(mkdir(foo_control, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH)) |
237 | g_error("can not make %s directory", foo_control); |
238 | if(mkdir(foo_eventdefs, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH)) |
239 | g_error("can not make %s directory", foo_eventdefs); |
240 | |
241 | fp = fopen(foo_info_system,"w"); |
242 | if(!fp){ |
243 | g_error("Unable to open file system.xml\n"); |
244 | } |
245 | |
160d4bdb |
246 | fdFac = open(foo_control_facilities,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); |
247 | if(fdFac < 0){ |
248 | g_error("Unable to open file facilities\n"); |
249 | } |
250 | fdIntr = open(foo_control_interrupts,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); |
251 | if(fdIntr<0){ |
252 | g_error("Unable to open file interrupts\n"); |
253 | } |
254 | fdProc = open(foo_control_processes,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); |
a1fbc64f |
255 | if(fdProc<0){ |
160d4bdb |
256 | g_error("Unable to open file process\n"); |
257 | } |
258 | |
259 | |
91a66e87 |
260 | for(k=0;k<cpu;k++){ |
acd767ee |
261 | fd = open(argv[nb_para-cpu+k], O_RDONLY, 0); |
91a66e87 |
262 | if(fd < 0){ |
acd767ee |
263 | g_error("Unable to open input data file %s\n", argv[nb_para-cpu+k]); |
160d4bdb |
264 | } |
91a66e87 |
265 | |
266 | if(fstat(fd, &lTDFStat) < 0){ |
267 | g_error("Unable to get the status of the input data file\n"); |
268 | } |
269 | file_size = lTDFStat.st_size; |
160d4bdb |
270 | |
91a66e87 |
271 | buffer = g_new(char, 4000); |
272 | readFile(fd,(void*)buffer, 3500, "Unable to read block header"); |
273 | |
160d4bdb |
274 | cur_pos= buffer; |
275 | evId = *(uint8_t *)cur_pos; |
276 | cur_pos += sizeof(uint8_t); |
277 | newId = evId; |
278 | time_delta = *(uint32_t*)cur_pos; |
279 | cur_pos += sizeof(uint32_t); |
280 | tBufStart = (trace_buffer_start*)cur_pos; |
281 | cur_pos += sizeof(trace_buffer_start); |
282 | cur_pos += sizeof(uint16_t); //Skip event size |
283 | |
91a66e87 |
284 | evId = *(uint8_t *)cur_pos; |
285 | cur_pos += sizeof(uint8_t); |
286 | cur_pos += sizeof(uint32_t); |
287 | tStart = (trace_start*)cur_pos; |
288 | |
160d4bdb |
289 | startId = newId; |
290 | startTimeDelta = time_delta; |
291 | start.seconds = tBufStart->Time.tv_sec; |
292 | start.nanoseconds = tBufStart->Time.tv_usec; |
293 | start.cycle_count = tBufStart->TSC; |
294 | start.block_id = tBufStart->ID; |
295 | end.block_id = start.block_id; |
296 | |
91a66e87 |
297 | ltt_major_version = tStart->MajorVersion; |
298 | ltt_minor_version = tStart->MinorVersion; |
299 | ltt_block_size = tStart->BufferSize; |
300 | ltt_log_cpu = tStart->LogCPUID; |
c9e8ac96 |
301 | |
91a66e87 |
302 | block_size = ltt_block_size; |
303 | block_number = file_size/block_size; |
c9e8ac96 |
304 | |
91a66e87 |
305 | g_free(buffer); |
306 | buffer = g_new(char, block_size); |
307 | buf_fac = g_new(char, block_size); |
308 | write_pos_fac = buf_fac; |
309 | buf_intr = g_new(char, block_size); |
310 | write_pos_intr = buf_intr; |
311 | buf_proc = g_new(char, block_size); |
312 | write_pos_proc = buf_proc; |
160d4bdb |
313 | |
91a66e87 |
314 | buf_out = g_new(char, block_size); |
315 | write_pos = buf_out; |
ee26cd96 |
316 | sprintf(cpuStr,"%s/%d",foo_cpu,k); |
91a66e87 |
317 | fdCpu = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu k |
318 | if(fdCpu < 0) g_error("Unable to open cpu file %d\n", k); |
319 | lseek(fd,0,SEEK_SET); |
320 | |
321 | for(i=0;i<block_number;i++){ |
322 | int event_count = 0; |
323 | beat_count = 0; |
324 | |
325 | memset((void*)buf_out, 0, block_size); |
326 | write_pos = buf_out; |
327 | memset((void*)buf_intr, 0, block_size); |
328 | memset((void*)buf_fac, 0, block_size); |
329 | memset((void*)buf_proc, 0, block_size); |
330 | write_pos_intr = buf_intr; |
331 | write_pos_fac = buf_fac; |
332 | write_pos_proc = buf_proc; |
333 | |
334 | memset((void*)buffer,0,block_size); |
335 | readFile(fd,(void*)buffer, block_size, "Unable to read block header"); |
336 | |
337 | cur_pos= buffer; |
160d4bdb |
338 | evId = *(uint8_t *)cur_pos; |
160d4bdb |
339 | cur_pos += sizeof(uint8_t); |
91a66e87 |
340 | newId = evId; |
160d4bdb |
341 | time_delta = *(uint32_t*)cur_pos; |
342 | cur_pos += sizeof(uint32_t); |
91a66e87 |
343 | tBufStart = (trace_buffer_start*)cur_pos; |
344 | cur_pos += sizeof(trace_buffer_start); |
345 | cur_pos += sizeof(uint16_t); //Skip event size |
160d4bdb |
346 | |
91a66e87 |
347 | startId = newId; |
348 | startTimeDelta = time_delta; |
91a66e87 |
349 | start.seconds = tBufStart->Time.tv_sec; |
350 | start.nanoseconds = tBufStart->Time.tv_usec; |
351 | start.cycle_count = tBufStart->TSC; |
352 | start.block_id = tBufStart->ID; |
353 | end.block_id = start.block_id; |
354 | |
355 | end_pos = buffer + block_size; //end of the buffer |
356 | size_lost = *(uint32_t*)(end_pos - sizeof(uint32_t)); |
357 | |
358 | end_pos = buffer + block_size - size_lost ; //buffer_end event |
160d4bdb |
359 | if(ltt_log_cpu){ |
91a66e87 |
360 | tBufEnd = (trace_buffer_end*)(end_pos + 2 * sizeof(uint8_t)+sizeof(uint32_t)); |
361 | }else{ |
362 | tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t)); |
160d4bdb |
363 | } |
91a66e87 |
364 | end.seconds = tBufEnd->Time.tv_sec; |
365 | end.nanoseconds = tBufEnd->Time.tv_usec; |
366 | end.cycle_count = tBufEnd->TSC; |
367 | |
368 | //skip buffer start and trace start events |
369 | if(i==0) //the first block |
370 | cur_pos = buffer + sizeof(trace_buffer_start) + sizeof(trace_start) + 2*(sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint32_t)); |
371 | else //other blocks |
372 | cur_pos = buffer + sizeof(trace_buffer_start) + sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint32_t); |
160d4bdb |
373 | |
91a66e87 |
374 | //write start block event |
375 | write_to_buffer(write_pos,(void*)&startId, sizeof(uint16_t)); |
376 | write_to_buffer(write_pos,(void*)&startTimeDelta, sizeof(uint32_t)); |
377 | write_to_buffer(write_pos,(void*)&start, sizeof(buffer_start)); |
378 | |
379 | //write start block event into processes and interrupts files |
380 | write_to_buffer(write_pos_intr,(void*)&startId, sizeof(uint16_t)); |
381 | write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t)); |
382 | start_intr = start; |
383 | start_intr.nanoseconds -= 20; |
384 | write_to_buffer(write_pos_intr,(void*)&start_intr, sizeof(buffer_start)); |
385 | |
386 | write_to_buffer(write_pos_proc,(void*)&startId, sizeof(uint16_t)); |
387 | write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t)); |
388 | start_proc = start; |
389 | start_proc.nanoseconds -= 40; |
390 | write_to_buffer(write_pos_proc,(void*)&start_proc, sizeof(buffer_start)); |
391 | |
392 | //parse *.proc file to get process and irq info |
393 | if(i == 0){ |
394 | int lIntID; /* Interrupt ID */ |
395 | int lPID, lPPID; /* Process PID and Parent PID */ |
396 | char lName[256]; /* Process name */ |
397 | FILE * fProc; |
398 | uint16_t defaultId; |
399 | trace_irq_entry irq; |
400 | |
401 | fProc = fopen(argv[1],"r"); |
402 | if(!fProc){ |
403 | g_error("Unable to open file %s\n", argv[1]); |
160d4bdb |
404 | } |
91a66e87 |
405 | |
406 | while(fscanf(fProc, "PID: %d; PPID: %d; NAME: %s\n", &lPID, &lPPID, lName) > 0){ |
407 | defaultId = PROCESS_FORK_ID; |
408 | process.event_data1 = lPID; |
409 | process.event_data2 = lPPID; |
410 | write_to_buffer(write_pos_proc,(void*)&defaultId, sizeof(uint16_t)); |
411 | write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t)); |
412 | write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process)); |
413 | } |
414 | |
415 | while(fscanf(fProc, "IRQ: %d; NAME: ", &lIntID) > 0){ |
416 | /* Read 'til the end of the line */ |
417 | fgets(lName, 200, fProc); |
418 | |
419 | defaultId = TRACE_IRQ_ENTRY; |
420 | irq.irq_id = lIntID; |
421 | irq.kernel = 1; |
422 | write_to_buffer(write_pos_intr,(void*)&defaultId, sizeof(uint16_t)); |
423 | write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t)); |
424 | write_to_buffer(write_pos_intr,(void*)&irq, sizeof(trace_irq_entry)); |
160d4bdb |
425 | } |
91a66e87 |
426 | fclose(fProc); |
160d4bdb |
427 | } |
428 | |
91a66e87 |
429 | while(1){ |
430 | int event_size; |
431 | uint64_t timeDelta; |
432 | uint8_t subId; |
433 | |
160d4bdb |
434 | if(ltt_log_cpu){ |
91a66e87 |
435 | cpu_id = *(uint8_t*)cur_pos; |
436 | cur_pos += sizeof(uint8_t); |
437 | } |
438 | evId = *(uint8_t *)cur_pos; |
439 | newId = evId; |
440 | if(evId == TRACE_HEARTBEAT) { |
441 | newId = TRACE_HEARTBEAT_ID; |
160d4bdb |
442 | } |
91a66e87 |
443 | cur_pos += sizeof(uint8_t); |
444 | time_delta = *(uint32_t*)cur_pos; |
445 | cur_pos += sizeof(uint32_t); |
160d4bdb |
446 | |
91a66e87 |
447 | //write event_id and time_delta |
448 | write_to_buffer(write_pos,(void*)&newId,sizeof(uint16_t)); |
449 | write_to_buffer(write_pos,(void*)&time_delta, sizeof(uint32_t)); |
450 | |
451 | if(evId == TRACE_BUFFER_END){ |
ee26cd96 |
452 | end.cycle_count = start.cycle_count |
453 | + beat_count * OVERFLOW_FIGURE; |
91a66e87 |
454 | int size = block_size + ((void*)buf_out - write_pos)+ sizeof(uint16_t) + sizeof(uint32_t); |
455 | write_to_buffer(write_pos,(void*)&end,sizeof(buffer_start)); |
456 | write_pos = buf_out + block_size - sizeof(uint32_t); |
457 | write_to_buffer(write_pos,(void*)&size, sizeof(uint32_t)); |
458 | write(fdCpu,(void*)buf_out, block_size); |
459 | |
460 | //write out processes and intrrupts files |
461 | { |
462 | int size_intr = block_size - (write_pos_intr - (void*)buf_intr); |
463 | int size_proc = block_size - (write_pos_proc - (void*)buf_proc); |
464 | write_to_buffer(write_pos_intr,(void*)&newId,sizeof(uint16_t)); |
465 | write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t)); |
466 | end_intr = end; |
467 | end_intr.nanoseconds -= 20; |
468 | write_to_buffer(write_pos_intr,(void*)&end_intr,sizeof(buffer_start)); |
469 | |
470 | write_to_buffer(write_pos_proc,(void*)&newId,sizeof(uint16_t)); |
471 | write_to_buffer(write_pos_proc,(void*)&time_delta, sizeof(uint32_t)); |
472 | end_proc = end; |
473 | end_proc.nanoseconds -= 40; |
474 | write_to_buffer(write_pos_proc,(void*)&end_proc,sizeof(buffer_start)); |
475 | |
476 | write_pos_intr = buf_intr + block_size - sizeof(uint32_t); |
477 | write_pos_proc = buf_proc + block_size - sizeof(uint32_t); |
478 | write_to_buffer(write_pos_intr,(void*)&size_intr, sizeof(uint32_t)); |
479 | write_to_buffer(write_pos_proc,(void*)&size_proc, sizeof(uint32_t)); |
480 | //for now don't output processes and interrupt information |
481 | // write(fdIntr,(void*)buf_intr,block_size); |
482 | // write(fdProc,(void*)buf_proc,block_size); |
483 | } |
484 | break; |
485 | } |
160d4bdb |
486 | |
91a66e87 |
487 | event_count++; |
488 | switch(evId){ |
489 | case TRACE_SYSCALL_ENTRY: |
490 | event_size = sizeof(trace_syscall_entry); |
491 | break; |
492 | case TRACE_SYSCALL_EXIT: |
493 | event_size = 0; |
494 | break; |
495 | case TRACE_TRAP_ENTRY: |
496 | event_size = sizeof(trace_trap_entry); |
497 | break; |
498 | case TRACE_TRAP_EXIT: |
499 | event_size = 0; |
500 | break; |
501 | case TRACE_IRQ_ENTRY: |
502 | event_size = sizeof(trace_irq_entry); |
503 | timeDelta = time_delta; |
504 | write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t)); |
505 | write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t)); |
506 | write_to_buffer(write_pos_intr,cur_pos, event_size); |
507 | break; |
508 | case TRACE_IRQ_EXIT: |
509 | event_size = 0; |
510 | timeDelta = time_delta; |
511 | write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t)); |
512 | write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t)); |
513 | break; |
514 | case TRACE_SCHEDCHANGE: |
515 | event_size = sizeof(trace_schedchange); |
516 | break; |
517 | case TRACE_KERNEL_TIMER: |
518 | event_size = 0; |
519 | break; |
520 | case TRACE_SOFT_IRQ: |
521 | event_size = sizeof(trace_soft_irq); |
522 | // timeDelta = time_delta; |
523 | // write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t)); |
524 | // write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t)); |
525 | // write_to_buffer(write_pos_intr,cur_pos, event_size); |
526 | break; |
527 | case TRACE_PROCESS: |
528 | event_size = sizeof(trace_process); |
529 | timeDelta = time_delta; |
530 | subId = *(uint8_t*)cur_pos; |
531 | if(subId == TRACE_PROCESS_FORK || subId ==TRACE_PROCESS_EXIT){ |
532 | if( subId == TRACE_PROCESS_FORK)tmpId = PROCESS_FORK_ID; |
533 | else tmpId = PROCESS_EXIT_ID; |
534 | write_to_buffer(write_pos_proc,(void*)&tmpId, sizeof(uint16_t)); |
535 | write_to_buffer(write_pos_proc,(void*)&timeDelta, sizeof(uint32_t)); |
536 | |
537 | process = *(new_process*)(cur_pos + sizeof(uint8_t)); |
538 | write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process)); |
539 | } |
540 | break; |
541 | case TRACE_FILE_SYSTEM: |
542 | event_size = sizeof(trace_file_system)- sizeof(char*); |
543 | break; |
544 | case TRACE_TIMER: |
545 | event_size = sizeof(trace_timer); |
546 | break; |
547 | case TRACE_MEMORY: |
548 | event_size = sizeof(trace_memory); |
549 | break; |
550 | case TRACE_SOCKET: |
551 | event_size = sizeof(trace_socket); |
552 | break; |
553 | case TRACE_IPC: |
554 | event_size = sizeof(trace_ipc); |
555 | break; |
556 | case TRACE_NETWORK: |
557 | event_size = sizeof(trace_network); |
558 | break; |
559 | case TRACE_HEARTBEAT: |
560 | beat_count++; |
561 | beat.seconds = 0; |
562 | beat.nanoseconds = 0; |
ee26cd96 |
563 | beat.cycle_count = (uint64_t)start.cycle_count |
564 | + (uint64_t)beat_count * OVERFLOW_FIGURE; |
91a66e87 |
565 | event_size = 0; |
91a66e87 |
566 | |
567 | write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t)); |
568 | write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t)); |
569 | write_to_buffer(write_pos_intr,(void*)&beat, sizeof(heartbeat)); |
570 | write_to_buffer(write_pos_proc,(void*)&newId, sizeof(uint16_t)); |
571 | write_to_buffer(write_pos_proc,(void*)&timeDelta, sizeof(uint32_t)); |
572 | write_to_buffer(write_pos_proc,(void*)&beat, sizeof(heartbeat)); |
573 | break; |
574 | default: |
575 | event_size = -1; |
576 | break; |
577 | } |
578 | if(evId != TRACE_FILE_SYSTEM && event_size >=0){ |
579 | write_to_buffer(write_pos, cur_pos, event_size); |
580 | |
581 | if(evId == TRACE_HEARTBEAT){ |
582 | write_to_buffer(write_pos, (void*)&beat, sizeof(heartbeat)); |
160d4bdb |
583 | } |
91a66e87 |
584 | |
585 | cur_pos += event_size + sizeof(uint16_t); //skip data_size |
586 | }else if(evId == TRACE_FILE_SYSTEM){ |
587 | size_t nbBytes; |
588 | char c = '\0'; |
589 | tFileSys = (trace_file_system*)cur_pos; |
590 | subId = tFileSys->event_sub_id; |
591 | if(subId == TRACE_FILE_SYSTEM_OPEN || subId == TRACE_FILE_SYSTEM_EXEC){ |
592 | nbBytes = tFileSys->event_data2 +1; |
593 | }else nbBytes = 0; |
594 | |
595 | write_to_buffer(write_pos, cur_pos, event_size); |
160d4bdb |
596 | cur_pos += event_size + sizeof(char*); |
597 | if(nbBytes){ |
91a66e87 |
598 | write_to_buffer(write_pos, cur_pos, nbBytes); |
160d4bdb |
599 | }else{ |
91a66e87 |
600 | write_to_buffer(write_pos, (void*)&c, 1); |
160d4bdb |
601 | } |
91a66e87 |
602 | cur_pos += nbBytes + sizeof(uint16_t); //skip data_size |
603 | }else if(event_size == -1){ |
604 | printf("Unknown event: evId=%d, i=%d, event_count=%d\n", newId, i, event_count); |
605 | exit(1); |
160d4bdb |
606 | } |
91a66e87 |
607 | } //end while(1) |
608 | } |
609 | close(fd); |
610 | close(fdCpu); |
611 | g_free(buffer); |
612 | buffer = NULL; |
613 | g_free(buf_fac); |
614 | g_free(buf_intr); |
615 | g_free(buf_proc); |
616 | g_free(buf_out); |
160d4bdb |
617 | } |
618 | |
619 | |
620 | |
621 | |
622 | |
623 | //write to system.xml |
43da6a59 |
624 | fprintf(fp,"<system \n"); |
625 | fprintf(fp,"node_name=\"%s\" \n", node_name); |
626 | fprintf(fp,"domainname=\"%s\" \n", domainname); |
627 | fprintf(fp,"cpu=\"%d\" \n", cpu); |
628 | fprintf(fp,"arch_size=\"%s\" \n", arch_size); |
629 | fprintf(fp,"endian=\"%s\" \n",endian); |
630 | fprintf(fp,"kernel_name=\"%s\" \n",kernel_name); |
631 | fprintf(fp,"kernel_release=\"%s\" \n",kernel_release); |
632 | fprintf(fp,"kernel_version=\"%s\" \n",kernel_version); |
633 | fprintf(fp,"machine=\"%s\" \n",machine); |
634 | fprintf(fp,"processor=\"%s\" \n",processor); |
635 | fprintf(fp,"hardware_platform=\"%s\" \n",hardware_platform); |
636 | fprintf(fp,"operating_system=\"%s\" \n",operating_system); |
637 | fprintf(fp,"ltt_major_version=\"%d\" \n",ltt_major_version); |
638 | fprintf(fp,"ltt_minor_version=\"%d\" \n",ltt_minor_version); |
639 | fprintf(fp,"ltt_block_size=\"%d\" \n",ltt_block_size); |
160d4bdb |
640 | fprintf(fp,">\n"); |
641 | fprintf(fp,"This is just a test\n"); |
642 | fprintf(fp,"</system>\n"); |
643 | fflush(fp); |
644 | |
160d4bdb |
645 | close(fdFac); |
646 | close(fdIntr); |
647 | close(fdProc); |
91a66e87 |
648 | fclose(fp); |
160d4bdb |
649 | |
ee26cd96 |
650 | return 0; |
160d4bdb |
651 | } |
652 | |