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