16 #include "LinuxEvents.h"
18 #define TRACE_HEARTBEAT_ID 19
19 #define PROCESS_FORK_ID 20
20 #define PROCESS_EXIT_ID 21
23 #define OVERFLOW_FIGURE 0x100000000ULL
25 typedef struct _new_process
27 uint32_t event_data1
; /* Data associated with event */
29 } LTT_PACKED_STRUCT new_process
;
31 #define write_to_buffer(DEST, SRC, SIZE) \
34 memcpy(DEST, SRC, SIZE);\
38 int readFile(int fd
, void * buf
, size_t size
, char * mesg
)
40 ssize_t nbBytes
= read(fd
, buf
, size
);
42 if((size_t)nbBytes
!= size
) {
44 perror("Error in readFile : ");
53 void getDataEndianType(char * size
, char * endian
)
57 int sizeInt
=sizeof(int), sizeLong
=sizeof(long), sizePointer
=sizeof(void *);
59 if(c
== 1) strcpy(endian
,"LITTLE_ENDIAN");
60 else strcpy(endian
, "BIG_ENDIAN");
62 if(sizeInt
== 2 && sizeLong
== 4 && sizePointer
== 4)
64 else if(sizeInt
== 4 && sizeLong
== 4 && sizePointer
== 4)
66 else if(sizeInt
== 4 && sizeLong
== 8 && sizePointer
== 8)
68 else if(sizeInt
== 8 && sizeLong
== 8 && sizePointer
== 8)
70 else strcpy(size
,"UNKNOWN");
73 #define BUFFER_SIZE 80
75 typedef struct _buffer_start
{
80 } __attribute__ ((packed
)) buffer_start
;
82 typedef struct _buffer_end
{
87 } __attribute__ ((packed
)) buffer_end
;
90 typedef struct _heartbeat
{
94 } __attribute__ ((packed
)) heartbeat
;
97 int main(int argc
, char ** argv
){
101 int fdFac
, fdIntr
, fdProc
;
102 char arch_size
[BUFFER_SIZE
];
103 char endian
[BUFFER_SIZE
];
104 char node_name
[BUFFER_SIZE
];
105 char domainname
[BUFFER_SIZE
];
106 char kernel_name
[BUFFER_SIZE
];
107 char kernel_release
[BUFFER_SIZE
];
108 char kernel_version
[BUFFER_SIZE
];
109 char machine
[BUFFER_SIZE
];
110 char processor
[BUFFER_SIZE
];
111 char hardware_platform
[BUFFER_SIZE
];
112 char operating_system
[BUFFER_SIZE
];
114 int ltt_block_size
=0;
115 int ltt_major_version
=0;
116 int ltt_minor_version
=0;
118 guint ltt_trace_start_size
= 0;
119 char buf
[BUFFER_SIZE
];
124 char foo
[4*BUFFER_SIZE
];
125 char foo_eventdefs
[4*BUFFER_SIZE
];
126 char foo_control
[4*BUFFER_SIZE
];
127 char foo_cpu
[4*BUFFER_SIZE
];
128 char foo_info
[4*BUFFER_SIZE
];
130 char foo_control_facilities
[4*BUFFER_SIZE
];
131 char foo_control_processes
[4*BUFFER_SIZE
];
132 char foo_control_interrupts
[4*BUFFER_SIZE
];
133 char foo_info_system
[4*BUFFER_SIZE
];
135 struct stat lTDFStat
;
137 int block_number
, block_size
;
138 char * buffer
, *buf_out
, cpuStr
[4*BUFFER_SIZE
];
139 char * buf_fac
, * buf_intr
, * buf_proc
;
140 void * write_pos
, *write_pos_fac
, * write_pos_intr
, *write_pos_proc
;
141 trace_start_any
*tStart
;
142 trace_buffer_start
*tBufStart
;
143 trace_buffer_end
*tBufEnd
;
144 trace_file_system
* tFileSys
;
145 uint16_t newId
, startId
, tmpId
;
147 uint32_t time_delta
, startTimeDelta
;
148 void * cur_pos
, *end_pos
;
149 buffer_start start
, start_proc
, start_intr
;
150 buffer_end end
, end_proc
, end_intr
;
152 uint64_t adaptation_tsc
; // (Mathieu)
154 int reserve_size
= sizeof(buffer_start
) +
155 sizeof(buffer_end
) + //buffer_end event
156 sizeof(uint32_t); //lost size
162 printf("Usage : ./convert processfile_name number_of_cpu tracefile1 tracefile2 ... trace_creation_directory\n");
163 printf("For more details, see README.\n");
168 printf("cpu number = %d\n", cpu
);
171 if(argc
!= nb_para
&& argc
!= nb_para
+1){
172 printf("need trace files and cpu number or root directory for the new tracefile\n");
178 strcpy(foo_eventdefs
, "foo/eventdefs");
179 strcpy(foo_control
, "foo/control");
180 strcpy(foo_cpu
, "foo/cpu");
181 strcpy(foo_info
, "foo/info");
183 strcpy(foo
, argv
[nb_para
]);
184 strcpy(foo_eventdefs
, argv
[nb_para
]);
185 strcat(foo_eventdefs
,"/eventdefs");
186 strcpy(foo_control
, argv
[nb_para
]);
187 strcat(foo_control
,"/control");
188 strcpy(foo_cpu
, argv
[nb_para
]);
189 strcat(foo_cpu
,"/cpu");
190 strcpy(foo_info
, argv
[nb_para
]);
191 strcat(foo_info
,"/info");
193 strcpy(foo_control_facilities
, foo_control
);
194 strcat(foo_control_facilities
,"/facilities");
195 strcpy(foo_control_processes
, foo_control
);
196 strcat(foo_control_processes
, "/processes");
197 strcpy(foo_control_interrupts
, foo_control
);
198 strcat(foo_control_interrupts
, "/interrupts");
199 strcpy(foo_info_system
, foo_info
);
200 strcat(foo_info_system
, "/system.xml");
203 getDataEndianType(arch_size
, endian
);
204 printf("Arch_size: %s, Endian: %s\n", arch_size
, endian
);
206 fp
= fopen("sysInfo.out","r");
208 g_error("Unable to open file sysInfo.out\n");
211 for(i
=0;i
<INFO_ENTRY
;i
++){
212 if(!fgets(buf
,BUFFER_SIZE
-1,fp
))
213 g_error("The format of sysInfo.out is not right\n");
214 if(strncmp(buf
,"node_name=",10)==0){
215 strcpy(node_name
,&buf
[10]);
216 node_name
[strlen(node_name
)-1] = '\0';
217 }else if(strncmp(buf
,"domainname=",11)==0){
218 strcpy(domainname
,&buf
[11]);
219 domainname
[strlen(domainname
)-1] = '\0';
220 }else if(strncmp(buf
,"kernel_name=",12)==0){
221 strcpy(kernel_name
,&buf
[12]);
222 kernel_name
[strlen(kernel_name
)-1] = '\0';
223 }else if(strncmp(buf
,"kernel_release=",15)==0){
224 strcpy(kernel_release
,&buf
[15]);
225 kernel_release
[strlen(kernel_release
)-1] = '\0';
226 }else if(strncmp(buf
,"kernel_version=",15)==0){
227 strcpy(kernel_version
,&buf
[15]);
228 kernel_version
[strlen(kernel_version
)-1] = '\0';
229 }else if(strncmp(buf
,"machine=",8)==0){
230 strcpy(machine
,&buf
[8]);
231 machine
[strlen(machine
)-1] = '\0';
232 }else if(strncmp(buf
,"processor=",10)==0){
233 strcpy(processor
,&buf
[10]);
234 processor
[strlen(processor
)-1] = '\0';
235 }else if(strncmp(buf
,"hardware_platform=",18)==0){
236 strcpy(hardware_platform
,&buf
[18]);
237 hardware_platform
[strlen(hardware_platform
)-1] = '\0';
238 }else if(strncmp(buf
,"operating_system=",17)==0){
239 strcpy(operating_system
,&buf
[17]);
240 operating_system
[strlen(operating_system
)-1] = '\0';
245 if(mkdir(foo
, S_IFDIR
| S_IRWXU
| S_IRGRP
| S_IROTH
))
246 g_error("can not make %s directory", foo
);
247 if(mkdir(foo_info
, S_IFDIR
| S_IRWXU
| S_IRGRP
| S_IROTH
))
248 g_error("can not make %s directory", foo_info
);
249 if(mkdir(foo_cpu
, S_IFDIR
| S_IRWXU
| S_IRGRP
| S_IROTH
))
250 g_error("can not make %s directory", foo_cpu
);
251 if(mkdir(foo_control
, S_IFDIR
| S_IRWXU
| S_IRGRP
| S_IROTH
))
252 g_error("can not make %s directory", foo_control
);
253 if(mkdir(foo_eventdefs
, S_IFDIR
| S_IRWXU
| S_IRGRP
| S_IROTH
))
254 g_error("can not make %s directory", foo_eventdefs
);
256 fp
= fopen(foo_info_system
,"w");
258 g_error("Unable to open file system.xml\n");
261 fdFac
= open(foo_control_facilities
,O_CREAT
| O_RDWR
| O_TRUNC
,S_IRUSR
|S_IWUSR
| S_IRGRP
| S_IROTH
);
263 g_error("Unable to open file facilities\n");
265 fdIntr
= open(foo_control_interrupts
,O_CREAT
| O_RDWR
| O_TRUNC
,S_IRUSR
|S_IWUSR
| S_IRGRP
| S_IROTH
);
267 g_error("Unable to open file interrupts\n");
269 fdProc
= open(foo_control_processes
,O_CREAT
| O_RDWR
| O_TRUNC
,S_IRUSR
|S_IWUSR
| S_IRGRP
| S_IROTH
);
271 g_error("Unable to open file process\n");
276 fd
= open(argv
[nb_para
-cpu
+k
], O_RDONLY
, 0);
278 g_error("Unable to open input data file %s\n", argv
[nb_para
-cpu
+k
]);
281 if(fstat(fd
, &lTDFStat
) < 0){
282 g_error("Unable to get the status of the input data file\n");
284 file_size
= lTDFStat
.st_size
;
286 buffer
= g_new(char, 4000);
287 readFile(fd
,(void*)buffer
, 3500, "Unable to read block header");
290 evId
= *(uint8_t *)cur_pos
;
291 cur_pos
+= sizeof(uint8_t);
293 time_delta
= *(uint32_t*)cur_pos
;
294 cur_pos
+= sizeof(uint32_t);
295 tBufStart
= (trace_buffer_start
*)cur_pos
;
296 cur_pos
+= sizeof(trace_buffer_start
);
297 cur_pos
+= sizeof(uint16_t); //Skip event size
299 evId
= *(uint8_t *)cur_pos
;
300 g_assert(evId
== TRACE_START
);
301 cur_pos
+= sizeof(uint8_t); //skip EvId
302 cur_pos
+= sizeof(uint32_t); //skip time delta
303 tStart
= (trace_start_any
*)cur_pos
;
304 if(tStart
->MagicNumber
!= TRACER_MAGIC_NUMBER
)
305 g_error("Trace magic number does not match : %x, should be %x",
306 tStart
->MagicNumber
, TRACER_MAGIC_NUMBER
);
307 if(tStart
->MajorVersion
!= TRACER_SUP_VERSION_MAJOR
)
308 g_error("Trace Major number does match : %hu, should be %u",
309 tStart
->MajorVersion
, TRACER_SUP_VERSION_MAJOR
);
312 startTimeDelta
= time_delta
;
313 start
.seconds
= tBufStart
->Time
.tv_sec
;
315 start
.nanoseconds
= tBufStart
->Time
.tv_usec
* 1000;
316 start
.cycle_count
= tBufStart
->TSC
;
317 start
.block_id
= tBufStart
->ID
;
318 end
.block_id
= start
.block_id
;
321 g_printf("Trace version %hu.%hu detected\n",
322 tStart
->MajorVersion
,
323 tStart
->MinorVersion
);
324 if(tStart
->MinorVersion
== 2) {
325 trace_start_2_2
* tStart_2_2
= (trace_start_2_2
*)tStart
;
326 ltt_major_version
= tStart_2_2
->MajorVersion
;
327 ltt_minor_version
= tStart_2_2
->MinorVersion
;
328 ltt_block_size
= tStart_2_2
->BufferSize
;
329 ltt_log_cpu
= tStart_2_2
->LogCPUID
;
330 ltt_trace_start_size
= sizeof(trace_start_2_2
);
331 /* Verify if it's a broken 2.2 format */
332 if(*(uint8_t*)(cur_pos
+ sizeof(trace_start_2_2
)) == 0) {
333 /* Cannot have two trace start events. We cannot detect the problem
334 * if the flight recording flag is set to 1, as it conflicts
335 * with TRACE_SYSCALL_ENTRY.
337 g_warning("This is a 2.3 trace format that has a 2.2 tag. Please upgrade your kernel");
338 g_printf("Processing the trace as a 2.3 format\n");
340 tStart
->MinorVersion
= 3;
344 if(tStart
->MinorVersion
== 3) {
345 trace_start_2_3
* tStart_2_3
= (trace_start_2_3
*)tStart
;
346 ltt_major_version
= tStart_2_3
->MajorVersion
;
347 ltt_minor_version
= tStart_2_3
->MinorVersion
;
348 ltt_block_size
= tStart_2_3
->BufferSize
;
349 ltt_log_cpu
= tStart_2_3
->LogCPUID
;
350 ltt_trace_start_size
= sizeof(trace_start_2_3
);
351 /* We do not use the flight recorder information for now, because we
352 * never use the .proc file anyway */
355 if(ltt_trace_start_size
== 0)
356 g_error("Minor version unknown : %hu. Supported minors : 2, 3",
357 tStart
->MinorVersion
);
359 block_size
= ltt_block_size
;//FIXME
360 block_number
= file_size
/ltt_block_size
;
363 buffer
= g_new(char, ltt_block_size
);
364 buf_fac
= g_new(char, block_size
);
365 write_pos_fac
= buf_fac
;
366 buf_intr
= g_new(char, block_size
);
367 write_pos_intr
= buf_intr
;
368 buf_proc
= g_new(char, block_size
);
369 write_pos_proc
= buf_proc
;
371 buf_out
= g_new(char, block_size
);
373 sprintf(cpuStr
,"%s/%d",foo_cpu
,k
);
374 fdCpu
= open(cpuStr
, O_CREAT
| O_RDWR
| O_TRUNC
,S_IRUSR
|S_IWUSR
| S_IRGRP
| S_IROTH
); //for cpu k
375 if(fdCpu
< 0) g_error("Unable to open cpu file %d\n", k
);
376 lseek(fd
,0,SEEK_SET
);
378 for(i
=0;i
<block_number
;i
++){
381 memset((void*)buf_out
, 0, block_size
);
383 memset((void*)buf_intr
, 0, block_size
);
384 memset((void*)buf_fac
, 0, block_size
);
385 memset((void*)buf_proc
, 0, block_size
);
386 write_pos_intr
= buf_intr
;
387 write_pos_fac
= buf_fac
;
388 write_pos_proc
= buf_proc
;
390 memset((void*)buffer
,0,ltt_block_size
);
391 readFile(fd
,(void*)buffer
, ltt_block_size
, "Unable to read block header");
394 evId
= *(uint8_t *)cur_pos
;
395 cur_pos
+= sizeof(uint8_t);
397 time_delta
= *(uint32_t*)cur_pos
;
398 cur_pos
+= sizeof(uint32_t);
399 tBufStart
= (trace_buffer_start
*)cur_pos
;
400 cur_pos
+= sizeof(trace_buffer_start
);
401 cur_pos
+= sizeof(uint16_t); //Skip event size
404 startTimeDelta
= time_delta
;
405 start
.seconds
= tBufStart
->Time
.tv_sec
;
406 /* usec -> nsec (Mathieu) */
407 start
.nanoseconds
= tBufStart
->Time
.tv_usec
* 1000;
408 start
.block_id
= tBufStart
->ID
;
409 end
.block_id
= start
.block_id
;
411 end_pos
= buffer
+ ltt_block_size
; //end of the buffer
412 size_lost
= *(uint32_t*)(end_pos
- sizeof(uint32_t));
414 end_pos
= buffer
+ ltt_block_size
- size_lost
; //buffer_end event
416 tBufEnd
= (trace_buffer_end
*)(end_pos
+ 2 * sizeof(uint8_t)+sizeof(uint32_t));
418 tBufEnd
= (trace_buffer_end
*)(end_pos
+sizeof(uint8_t)+sizeof(uint32_t));
420 end
.seconds
= tBufEnd
->Time
.tv_sec
;
421 /* usec -> nsec (Mathieu) */
422 end
.nanoseconds
= tBufEnd
->Time
.tv_usec
* 1000;
424 //end.cycle_count = tBufEnd->TSC;
426 //skip buffer start and trace start events
429 adaptation_tsc
= (uint64_t)tBufStart
->TSC
;
430 cur_pos
= buffer
+ sizeof(trace_buffer_start
)
431 + ltt_trace_start_size
433 + sizeof(uint16_t)+sizeof(uint32_t));
436 cur_pos
= buffer
+ sizeof(trace_buffer_start
)
438 + sizeof(uint16_t)+sizeof(uint32_t);
441 if(time_delta
< (0xFFFFFFFFULL
&adaptation_tsc
)) {
443 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
)
445 + (uint64_t)time_delta
;
448 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
) + time_delta
;
452 start
.cycle_count
= adaptation_tsc
;
454 //write start block event
455 write_to_buffer(write_pos
,(void*)&startId
, sizeof(uint16_t));
456 write_to_buffer(write_pos
,(void*)&startTimeDelta
, sizeof(uint32_t));
457 write_to_buffer(write_pos
,(void*)&start
, sizeof(buffer_start
));
459 //write start block event into processes and interrupts files
460 write_to_buffer(write_pos_intr
,(void*)&startId
, sizeof(uint16_t));
461 write_to_buffer(write_pos_intr
,(void*)&startTimeDelta
, sizeof(uint32_t));
463 start_intr
.nanoseconds
-= 20;
464 write_to_buffer(write_pos_intr
,(void*)&start_intr
, sizeof(buffer_start
));
466 write_to_buffer(write_pos_proc
,(void*)&startId
, sizeof(uint16_t));
467 write_to_buffer(write_pos_proc
,(void*)&startTimeDelta
, sizeof(uint32_t));
469 start_proc
.nanoseconds
-= 40;
470 write_to_buffer(write_pos_proc
,(void*)&start_proc
, sizeof(buffer_start
));
472 //parse *.proc file to get process and irq info
474 int lIntID
; /* Interrupt ID */
475 int lPID
, lPPID
; /* Process PID and Parent PID */
476 char lName
[256]; /* Process name */
481 fProc
= fopen(argv
[1],"r");
483 g_error("Unable to open file %s\n", argv
[1]);
486 while(fscanf(fProc
, "PID: %d; PPID: %d; NAME: %s\n", &lPID
, &lPPID
, lName
) > 0){
487 defaultId
= PROCESS_FORK_ID
;
488 process
.event_data1
= lPID
;
489 process
.event_data2
= lPPID
;
490 write_to_buffer(write_pos_proc
,(void*)&defaultId
, sizeof(uint16_t));
491 write_to_buffer(write_pos_proc
,(void*)&startTimeDelta
, sizeof(uint32_t));
492 write_to_buffer(write_pos_proc
,(void*)&process
, sizeof(new_process
));
495 while(fscanf(fProc
, "IRQ: %d; NAME: ", &lIntID
) > 0){
496 /* Read 'til the end of the line */
497 fgets(lName
, 200, fProc
);
499 defaultId
= TRACE_IRQ_ENTRY
;
502 write_to_buffer(write_pos_intr
,(void*)&defaultId
, sizeof(uint16_t));
503 write_to_buffer(write_pos_intr
,(void*)&startTimeDelta
, sizeof(uint32_t));
504 write_to_buffer(write_pos_intr
,(void*)&irq
, sizeof(trace_irq_entry
));
515 cpu_id
= *(uint8_t*)cur_pos
;
516 cur_pos
+= sizeof(uint8_t);
518 evId
= *(uint8_t *)cur_pos
;
520 if(evId
== TRACE_HEARTBEAT
) {
521 newId
= TRACE_HEARTBEAT_ID
;
523 cur_pos
+= sizeof(uint8_t);
524 time_delta
= *(uint32_t*)cur_pos
;
525 cur_pos
+= sizeof(uint32_t);
528 //write event_id and time_delta
529 write_to_buffer(write_pos
,(void*)&newId
,sizeof(uint16_t));
530 write_to_buffer(write_pos
,(void*)&time_delta
, sizeof(uint32_t));
533 if(time_delta
< (0xFFFFFFFFULL
&adaptation_tsc
)) {
535 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
) + 0x100000000ULL
536 + (uint64_t)time_delta
;
539 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
) + time_delta
;
543 if(evId
== TRACE_BUFFER_END
){
546 if(time_delta
< (0xFFFFFFFFULL
&adaptation_tsc
)) {
548 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
) + 0x100000000ULL
549 + (uint64_t)time_delta
;
552 adaptation_tsc
= (adaptation_tsc
&0xFFFFFFFF00000000ULL
) + time_delta
;
555 end
.cycle_count
= adaptation_tsc
;
556 int size
= (void*)buf_out
+ block_size
- write_pos
557 - sizeof(buffer_end
) - sizeof(uint32_t);
560 //int size = (void*)buf_out + block_size - write_pos
561 // + sizeof(uint16_t) + sizeof(uint32_t);
562 g_assert((void*)write_pos
< (void*)buf_out
+ block_size
);
563 write_to_buffer(write_pos
,(void*)&end
,sizeof(buffer_end
));
564 write_pos
= buf_out
+ block_size
- sizeof(uint32_t);
565 write_to_buffer(write_pos
,(void*)&size
, sizeof(uint32_t));
566 write(fdCpu
,(void*)buf_out
, block_size
);
568 //write out processes and intrrupts files
570 int size_intr
= block_size
+ (void*)buf_intr
- write_pos_intr
571 - sizeof(buffer_end
) - sizeof(uint32_t);
572 int size_proc
= block_size
+ (void*)buf_proc
- write_pos_proc
573 - sizeof(buffer_end
) - sizeof(uint32_t);
574 //int size_intr = block_size - (write_pos_intr - (void*)buf_intr);
575 //int size_proc = block_size - (write_pos_proc - (void*)buf_proc);
576 write_to_buffer(write_pos_intr
,(void*)&newId
,sizeof(uint16_t));
577 write_to_buffer(write_pos_intr
,(void*)&time_delta
, sizeof(uint32_t));
579 end_intr
.nanoseconds
-= 20;
580 write_to_buffer(write_pos_intr
,(void*)&end_intr
,sizeof(buffer_start
));
582 write_to_buffer(write_pos_proc
,(void*)&newId
,sizeof(uint16_t));
583 write_to_buffer(write_pos_proc
,(void*)&time_delta
, sizeof(uint32_t));
585 end_proc
.nanoseconds
-= 40;
586 write_to_buffer(write_pos_proc
,(void*)&end_proc
,sizeof(buffer_start
));
588 write_pos_intr
= buf_intr
+ block_size
- sizeof(uint32_t);
589 write_pos_proc
= buf_proc
+ block_size
- sizeof(uint32_t);
590 write_to_buffer(write_pos_intr
,(void*)&size_intr
, sizeof(uint32_t));
591 write_to_buffer(write_pos_proc
,(void*)&size_proc
, sizeof(uint32_t));
592 //for now don't output processes and interrupt information
593 // write(fdIntr,(void*)buf_intr,block_size);
594 // write(fdProc,(void*)buf_proc,block_size);
601 case TRACE_SYSCALL_ENTRY
:
602 event_size
= sizeof(trace_syscall_entry
);
604 case TRACE_SYSCALL_EXIT
:
607 case TRACE_TRAP_ENTRY
:
608 event_size
= sizeof(trace_trap_entry
);
610 case TRACE_TRAP_EXIT
:
613 case TRACE_IRQ_ENTRY
:
614 event_size
= sizeof(trace_irq_entry
);
615 timeDelta
= time_delta
;
616 write_to_buffer(write_pos_intr
,(void*)&newId
, sizeof(uint16_t));
617 write_to_buffer(write_pos_intr
,(void*)&timeDelta
, sizeof(uint32_t));
618 write_to_buffer(write_pos_intr
,cur_pos
, event_size
);
622 timeDelta
= time_delta
;
623 write_to_buffer(write_pos_intr
,(void*)&newId
, sizeof(uint16_t));
624 write_to_buffer(write_pos_intr
,(void*)&timeDelta
, sizeof(uint32_t));
626 case TRACE_SCHEDCHANGE
:
627 event_size
= sizeof(trace_schedchange
);
629 case TRACE_KERNEL_TIMER
:
633 event_size
= sizeof(trace_soft_irq
);
634 // timeDelta = time_delta;
635 // write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
636 // write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
637 // write_to_buffer(write_pos_intr,cur_pos, event_size);
640 event_size
= sizeof(trace_process
);
641 timeDelta
= time_delta
;
642 subId
= *(uint8_t*)cur_pos
;
643 if(subId
== TRACE_PROCESS_FORK
|| subId
==TRACE_PROCESS_EXIT
){
644 if( subId
== TRACE_PROCESS_FORK
)tmpId
= PROCESS_FORK_ID
;
645 else tmpId
= PROCESS_EXIT_ID
;
646 write_to_buffer(write_pos_proc
,(void*)&tmpId
, sizeof(uint16_t));
647 write_to_buffer(write_pos_proc
,(void*)&timeDelta
, sizeof(uint32_t));
649 process
= *(new_process
*)(cur_pos
+ sizeof(uint8_t));
650 write_to_buffer(write_pos_proc
,(void*)&process
, sizeof(new_process
));
653 case TRACE_FILE_SYSTEM
:
654 event_size
= sizeof(trace_file_system
)- sizeof(char*);
657 event_size
= sizeof(trace_timer
);
660 event_size
= sizeof(trace_memory
);
663 event_size
= sizeof(trace_socket
);
666 event_size
= sizeof(trace_ipc
);
669 event_size
= sizeof(trace_network
);
671 case TRACE_HEARTBEAT
:
673 beat
.nanoseconds
= 0;
674 beat
.cycle_count
= adaptation_tsc
;
677 write_to_buffer(write_pos_intr
,(void*)&newId
, sizeof(uint16_t));
678 write_to_buffer(write_pos_intr
,(void*)&time_delta
, sizeof(uint32_t));
679 write_to_buffer(write_pos_intr
,(void*)&beat
, sizeof(heartbeat
));
680 write_to_buffer(write_pos_proc
,(void*)&newId
, sizeof(uint16_t));
681 write_to_buffer(write_pos_proc
,(void*)&time_delta
, sizeof(uint32_t));
682 write_to_buffer(write_pos_proc
,(void*)&beat
, sizeof(heartbeat
));
688 if(evId
!= TRACE_FILE_SYSTEM
&& event_size
>=0){
689 write_to_buffer(write_pos
, cur_pos
, event_size
);
691 if(evId
== TRACE_HEARTBEAT
){
692 write_to_buffer(write_pos
, (void*)&beat
, sizeof(heartbeat
));
695 cur_pos
+= event_size
+ sizeof(uint16_t); //skip data_size
696 }else if(evId
== TRACE_FILE_SYSTEM
){
699 tFileSys
= (trace_file_system
*)cur_pos
;
700 subId
= tFileSys
->event_sub_id
;
701 if(subId
== TRACE_FILE_SYSTEM_OPEN
|| subId
== TRACE_FILE_SYSTEM_EXEC
){
702 nbBytes
= tFileSys
->event_data2
+1;
705 write_to_buffer(write_pos
, cur_pos
, event_size
);
706 cur_pos
+= event_size
+ sizeof(char*);
708 write_to_buffer(write_pos
, cur_pos
, nbBytes
);
710 write_to_buffer(write_pos
, (void*)&c
, 1);
712 cur_pos
+= nbBytes
+ sizeof(uint16_t); //skip data_size
713 }else if(event_size
== -1){
714 printf("Unknown event: evId=%d, i=%d, event_count=%d\n", newId
, i
, event_count
);
733 //write to system.xml
734 fprintf(fp
,"<system \n");
735 fprintf(fp
,"node_name=\"%s\" \n", node_name
);
736 fprintf(fp
,"domainname=\"%s\" \n", domainname
);
737 fprintf(fp
,"cpu=\"%d\" \n", cpu
);
738 fprintf(fp
,"arch_size=\"%s\" \n", arch_size
);
739 fprintf(fp
,"endian=\"%s\" \n",endian
);
740 fprintf(fp
,"kernel_name=\"%s\" \n",kernel_name
);
741 fprintf(fp
,"kernel_release=\"%s\" \n",kernel_release
);
742 fprintf(fp
,"kernel_version=\"%s\" \n",kernel_version
);
743 fprintf(fp
,"machine=\"%s\" \n",machine
);
744 fprintf(fp
,"processor=\"%s\" \n",processor
);
745 fprintf(fp
,"hardware_platform=\"%s\" \n",hardware_platform
);
746 fprintf(fp
,"operating_system=\"%s\" \n",operating_system
);
747 fprintf(fp
,"ltt_major_version=\"%d\" \n",ltt_major_version
);
748 fprintf(fp
,"ltt_minor_version=\"%d\" \n",ltt_minor_version
);
749 fprintf(fp
,"ltt_block_size=\"%d\" \n",ltt_block_size
);
751 fprintf(fp
,"This is just a test\n");
752 fprintf(fp
,"</system>\n");
760 g_printf("Conversion completed. Don't forget to copy core.xml to eventdefs directory\n");