update compat
[lttv.git] / tags / LinuxTraceToolkitViewer-0.10.0-pre-115102007 / ltt / convert-old / convert.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <errno.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include <glib.h>
15 #include "LTTTypes.h"
16 #include "LinuxEvents.h"
17
18 #define TRACE_HEARTBEAT_ID 19
19 #define PROCESS_FORK_ID 20
20 #define PROCESS_EXIT_ID 21
21
22 #define INFO_ENTRY 9
23 #define OVERFLOW_FIGURE 0x100000000ULL
24
25 typedef struct _new_process
26 {
27 uint32_t event_data1; /* Data associated with event */
28 uint32_t event_data2;
29 } LTT_PACKED_STRUCT new_process;
30
31 #define write_to_buffer(DEST, SRC, SIZE) \
32 do\
33 {\
34 memcpy(DEST, SRC, SIZE);\
35 DEST += SIZE;\
36 } while(0);
37
38 int readFile(int fd, void * buf, size_t size, char * mesg)
39 {
40 ssize_t nbBytes = read(fd, buf, size);
41
42 if((size_t)nbBytes != size) {
43 if(nbBytes < 0) {
44 perror("Error in readFile : ");
45 } else {
46 printf("%s\n",mesg);
47 }
48 exit(1);
49 }
50 return 0;
51 }
52
53 void getDataEndianType(char * size, char * endian)
54 {
55 int i = 1;
56 char c = (char) i;
57 int sizeInt=sizeof(int), sizeLong=sizeof(long), sizePointer=sizeof(void *);
58
59 if(c == 1) strcpy(endian,"LITTLE_ENDIAN");
60 else strcpy(endian, "BIG_ENDIAN");
61
62 if(sizeInt == 2 && sizeLong == 4 && sizePointer == 4)
63 strcpy(size,"LP32");
64 else if(sizeInt == 4 && sizeLong == 4 && sizePointer == 4)
65 strcpy(size,"ILP32");
66 else if(sizeInt == 4 && sizeLong == 8 && sizePointer == 8)
67 strcpy(size,"LP64");
68 else if(sizeInt == 8 && sizeLong == 8 && sizePointer == 8)
69 strcpy(size,"ILP64");
70 else strcpy(size,"UNKNOWN");
71 }
72
73 #define BUFFER_SIZE 80
74
75 typedef struct _buffer_start{
76 uint32_t seconds;
77 uint32_t nanoseconds;
78 uint64_t cycle_count;
79 uint32_t block_id;
80 } __attribute__ ((packed)) buffer_start;
81
82 typedef struct _buffer_end{
83 uint32_t seconds;
84 uint32_t nanoseconds;
85 uint64_t cycle_count;
86 uint32_t block_id;
87 } __attribute__ ((packed)) buffer_end;
88
89
90 typedef struct _heartbeat{
91 uint32_t seconds;
92 uint32_t nanoseconds;
93 uint64_t cycle_count;
94 } __attribute__ ((packed)) heartbeat;
95
96
97 int main(int argc, char ** argv){
98
99 int fd, fdCpu;
100 FILE * fp;
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];
113 int cpu;
114 int ltt_block_size=0;
115 int ltt_major_version=0;
116 int ltt_minor_version=0;
117 int ltt_log_cpu;
118 guint ltt_trace_start_size = 0;
119 char buf[BUFFER_SIZE];
120 int i, k;
121
122 uint8_t cpu_id;
123
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];
129
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];
134
135 struct stat lTDFStat;
136 off_t file_size;
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;
146 uint8_t evId;
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;
151 heartbeat beat;
152 uint64_t adaptation_tsc; // (Mathieu)
153 uint32_t size_lost;
154 int nb_para;
155
156 new_process process;
157
158 if(argc < 4){
159 printf("Usage : ./convert processfile_name number_of_cpu tracefile1 tracefile2 ... trace_creation_directory\n");
160 printf("For more details, see README.\n");
161 exit(1);
162 }
163
164 cpu = atoi(argv[2]);
165 printf("cpu number = %d\n", cpu);
166 nb_para = 3 + cpu;
167
168 if(argc != nb_para && argc != nb_para+1){
169 printf("need trace files and cpu number or root directory for the new tracefile\n");
170 exit(1);
171 }
172
173 if(argc == nb_para){
174 strcpy(foo, "foo");
175 strcpy(foo_eventdefs, "foo/eventdefs");
176 strcpy(foo_control, "foo/control");
177 strcpy(foo_cpu, "foo/cpu");
178 strcpy(foo_info, "foo/info");
179 }else{
180 strcpy(foo, argv[nb_para]);
181 strcpy(foo_eventdefs, argv[nb_para]);
182 strcat(foo_eventdefs,"/eventdefs");
183 strcpy(foo_control, argv[nb_para]);
184 strcat(foo_control,"/control");
185 strcpy(foo_cpu, argv[nb_para]);
186 strcat(foo_cpu,"/cpu");
187 strcpy(foo_info, argv[nb_para]);
188 strcat(foo_info,"/info");
189 }
190 strcpy(foo_control_facilities, foo_control);
191 strcat(foo_control_facilities,"/facilities");
192 strcpy(foo_control_processes, foo_control);
193 strcat(foo_control_processes, "/processes");
194 strcpy(foo_control_interrupts, foo_control);
195 strcat(foo_control_interrupts, "/interrupts");
196 strcpy(foo_info_system, foo_info);
197 strcat(foo_info_system, "/system.xml");
198
199
200 getDataEndianType(arch_size, endian);
201 printf("Arch_size: %s, Endian: %s\n", arch_size, endian);
202
203 fp = fopen("sysInfo.out","r");
204 if(!fp){
205 g_error("Unable to open file sysInfo.out\n");
206 }
207
208 for(i=0;i<INFO_ENTRY;i++){
209 if(!fgets(buf,BUFFER_SIZE-1,fp))
210 g_error("The format of sysInfo.out is not right\n");
211 if(strncmp(buf,"node_name=",10)==0){
212 strcpy(node_name,&buf[10]);
213 node_name[strlen(node_name)-1] = '\0';
214 }else if(strncmp(buf,"domainname=",11)==0){
215 strcpy(domainname,&buf[11]);
216 domainname[strlen(domainname)-1] = '\0';
217 }else if(strncmp(buf,"kernel_name=",12)==0){
218 strcpy(kernel_name,&buf[12]);
219 kernel_name[strlen(kernel_name)-1] = '\0';
220 }else if(strncmp(buf,"kernel_release=",15)==0){
221 strcpy(kernel_release,&buf[15]);
222 kernel_release[strlen(kernel_release)-1] = '\0';
223 }else if(strncmp(buf,"kernel_version=",15)==0){
224 strcpy(kernel_version,&buf[15]);
225 kernel_version[strlen(kernel_version)-1] = '\0';
226 }else if(strncmp(buf,"machine=",8)==0){
227 strcpy(machine,&buf[8]);
228 machine[strlen(machine)-1] = '\0';
229 }else if(strncmp(buf,"processor=",10)==0){
230 strcpy(processor,&buf[10]);
231 processor[strlen(processor)-1] = '\0';
232 }else if(strncmp(buf,"hardware_platform=",18)==0){
233 strcpy(hardware_platform,&buf[18]);
234 hardware_platform[strlen(hardware_platform)-1] = '\0';
235 }else if(strncmp(buf,"operating_system=",17)==0){
236 strcpy(operating_system,&buf[17]);
237 operating_system[strlen(operating_system)-1] = '\0';
238 }
239 }
240 fclose(fp);
241
242 if(mkdir(foo, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH))
243 g_error("can not make %s directory", foo);
244 if(mkdir(foo_info, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH))
245 g_error("can not make %s directory", foo_info);
246 if(mkdir(foo_cpu, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH))
247 g_error("can not make %s directory", foo_cpu);
248 if(mkdir(foo_control, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH))
249 g_error("can not make %s directory", foo_control);
250 if(mkdir(foo_eventdefs, S_IFDIR | S_IRWXU | S_IRGRP | S_IROTH))
251 g_error("can not make %s directory", foo_eventdefs);
252
253 fp = fopen(foo_info_system,"w");
254 if(!fp){
255 g_error("Unable to open file system.xml\n");
256 }
257
258 fdFac = open(foo_control_facilities,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
259 if(fdFac < 0){
260 g_error("Unable to open file facilities\n");
261 }
262 fdIntr = open(foo_control_interrupts,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
263 if(fdIntr<0){
264 g_error("Unable to open file interrupts\n");
265 }
266 fdProc = open(foo_control_processes,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
267 if(fdProc<0){
268 g_error("Unable to open file process\n");
269 }
270
271
272 for(k=0;k<cpu;k++){
273 fd = open(argv[nb_para-cpu+k], O_RDONLY, 0);
274 if(fd < 0){
275 g_error("Unable to open input data file %s\n", argv[nb_para-cpu+k]);
276 }
277
278 if(fstat(fd, &lTDFStat) < 0){
279 g_error("Unable to get the status of the input data file\n");
280 }
281 file_size = lTDFStat.st_size;
282
283 buffer = g_new(char, 4000);
284 readFile(fd,(void*)buffer, 3500, "Unable to read block header");
285
286 cur_pos= buffer;
287 evId = *(uint8_t *)cur_pos;
288 cur_pos += sizeof(uint8_t);
289 newId = evId;
290 time_delta = *(uint32_t*)cur_pos;
291 cur_pos += sizeof(uint32_t);
292 tBufStart = (trace_buffer_start*)cur_pos;
293 cur_pos += sizeof(trace_buffer_start);
294 cur_pos += sizeof(uint16_t); //Skip event size
295
296 evId = *(uint8_t *)cur_pos;
297 g_assert(evId == TRACE_START);
298 cur_pos += sizeof(uint8_t); //skip EvId
299 cur_pos += sizeof(uint32_t); //skip time delta
300 tStart = (trace_start_any*)cur_pos;
301 if(tStart->MagicNumber != TRACER_MAGIC_NUMBER)
302 g_error("Trace magic number does not match : %x, should be %x",
303 tStart->MagicNumber, TRACER_MAGIC_NUMBER);
304 if(tStart->MajorVersion != TRACER_SUP_VERSION_MAJOR)
305 g_error("Trace Major number does match : %hu, should be %u",
306 tStart->MajorVersion, TRACER_SUP_VERSION_MAJOR);
307
308 startId = newId;
309 startTimeDelta = time_delta;
310 start.seconds = tBufStart->Time.tv_sec;
311 /* Fix (Mathieu) */
312 start.nanoseconds = tBufStart->Time.tv_usec * 1000;
313 start.cycle_count = tBufStart->TSC;
314 start.block_id = tBufStart->ID;
315 end.block_id = start.block_id;
316
317
318 g_message("Trace version %hu.%hu detected\n",
319 tStart->MajorVersion,
320 tStart->MinorVersion);
321 if(tStart->MinorVersion == 2) {
322 trace_start_2_2* tStart_2_2 = (trace_start_2_2*)tStart;
323 ltt_major_version = tStart_2_2->MajorVersion;
324 ltt_minor_version = tStart_2_2->MinorVersion;
325 ltt_block_size = tStart_2_2->BufferSize;
326 ltt_log_cpu = tStart_2_2->LogCPUID;
327 ltt_trace_start_size = sizeof(trace_start_2_2);
328 /* Verify if it's a broken 2.2 format */
329 if(*(uint8_t*)(cur_pos + sizeof(trace_start_2_2)) == 0) {
330 /* Cannot have two trace start events. We cannot detect the problem
331 * if the flight recording flag is set to 1, as it conflicts
332 * with TRACE_SYSCALL_ENTRY.
333 */
334 g_warning("This is a 2.3 trace format that has a 2.2 tag. Please upgrade your kernel");
335 g_message("Processing the trace as a 2.3 format\n");
336
337 tStart->MinorVersion = 3;
338 }
339 }
340
341 if(tStart->MinorVersion == 3) {
342 trace_start_2_3* tStart_2_3 = (trace_start_2_3*)tStart;
343 ltt_major_version = tStart_2_3->MajorVersion;
344 ltt_minor_version = tStart_2_3->MinorVersion;
345 ltt_block_size = tStart_2_3->BufferSize;
346 ltt_log_cpu = tStart_2_3->LogCPUID;
347 ltt_trace_start_size = sizeof(trace_start_2_3);
348 /* We do not use the flight recorder information for now, because we
349 * never use the .proc file anyway */
350 }
351
352 if(ltt_trace_start_size == 0)
353 g_error("Minor version unknown : %hu. Supported minors : 2, 3",
354 tStart->MinorVersion);
355
356 block_size = ltt_block_size;//FIXME
357 block_number = file_size/ltt_block_size;
358
359 g_free(buffer);
360 buffer = g_new(char, ltt_block_size);
361 buf_fac = g_new(char, block_size);
362 write_pos_fac = buf_fac;
363 buf_intr = g_new(char, block_size);
364 write_pos_intr = buf_intr;
365 buf_proc = g_new(char, block_size);
366 write_pos_proc = buf_proc;
367
368 buf_out = g_new(char, block_size);
369 write_pos = buf_out;
370 sprintf(cpuStr,"%s/%d",foo_cpu,k);
371 fdCpu = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu k
372 if(fdCpu < 0) g_error("Unable to open cpu file %d\n", k);
373 lseek(fd,0,SEEK_SET);
374
375 for(i=0;i<block_number;i++){
376 int event_count = 0;
377
378 memset((void*)buf_out, 0, block_size);
379 write_pos = buf_out;
380 memset((void*)buf_intr, 0, block_size);
381 memset((void*)buf_fac, 0, block_size);
382 memset((void*)buf_proc, 0, block_size);
383 write_pos_intr = buf_intr;
384 write_pos_fac = buf_fac;
385 write_pos_proc = buf_proc;
386
387 memset((void*)buffer,0,ltt_block_size);
388 readFile(fd,(void*)buffer, ltt_block_size, "Unable to read block header");
389
390 cur_pos= buffer;
391 evId = *(uint8_t *)cur_pos;
392 cur_pos += sizeof(uint8_t);
393 newId = evId;
394 time_delta = *(uint32_t*)cur_pos;
395 cur_pos += sizeof(uint32_t);
396 tBufStart = (trace_buffer_start*)cur_pos;
397 cur_pos += sizeof(trace_buffer_start);
398 cur_pos += sizeof(uint16_t); //Skip event size
399
400 startId = newId;
401 startTimeDelta = time_delta;
402 start.seconds = tBufStart->Time.tv_sec;
403 /* usec -> nsec (Mathieu) */
404 start.nanoseconds = tBufStart->Time.tv_usec * 1000;
405 start.block_id = tBufStart->ID;
406 end.block_id = start.block_id;
407
408 end_pos = buffer + ltt_block_size; //end of the buffer
409 size_lost = *(uint32_t*)(end_pos - sizeof(uint32_t));
410
411 end_pos = buffer + ltt_block_size - size_lost ; //buffer_end event
412 if(ltt_log_cpu){
413 tBufEnd = (trace_buffer_end*)(end_pos + 2 * sizeof(uint8_t)+sizeof(uint32_t));
414 }else{
415 tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t));
416 }
417 end.seconds = tBufEnd->Time.tv_sec;
418 /* usec -> nsec (Mathieu) */
419 end.nanoseconds = tBufEnd->Time.tv_usec * 1000;
420 // only 32 bits :(
421 //end.cycle_count = tBufEnd->TSC;
422
423 //skip buffer start and trace start events
424 if(i==0) {
425 //the first block
426 adaptation_tsc = (uint64_t)tBufStart->TSC;
427 cur_pos = buffer + sizeof(trace_buffer_start)
428 + ltt_trace_start_size
429 + 2*(sizeof(uint8_t)
430 + sizeof(uint16_t)+sizeof(uint32_t));
431 } else {
432 //other blocks
433 cur_pos = buffer + sizeof(trace_buffer_start)
434 + sizeof(uint8_t)
435 + sizeof(uint16_t)+sizeof(uint32_t);
436
437 /* Fix (Mathieu) */
438 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
439 /* Overflow */
440 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL)
441 + 0x100000000ULL
442 + (uint64_t)time_delta;
443 } else {
444 /* No overflow */
445 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
446 }
447
448 }
449 start.cycle_count = adaptation_tsc;
450
451 //write start block event
452 write_to_buffer(write_pos,(void*)&startId, sizeof(uint16_t));
453 write_to_buffer(write_pos,(void*)&startTimeDelta, sizeof(uint32_t));
454 write_to_buffer(write_pos,(void*)&start, sizeof(buffer_start));
455
456 //write start block event into processes and interrupts files
457 write_to_buffer(write_pos_intr,(void*)&startId, sizeof(uint16_t));
458 write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t));
459 start_intr = start;
460 start_intr.nanoseconds -= 20;
461 write_to_buffer(write_pos_intr,(void*)&start_intr, sizeof(buffer_start));
462
463 write_to_buffer(write_pos_proc,(void*)&startId, sizeof(uint16_t));
464 write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t));
465 start_proc = start;
466 start_proc.nanoseconds -= 40;
467 write_to_buffer(write_pos_proc,(void*)&start_proc, sizeof(buffer_start));
468
469 //parse *.proc file to get process and irq info
470 if(i == 0){
471 int lIntID; /* Interrupt ID */
472 int lPID, lPPID; /* Process PID and Parent PID */
473 char lName[256]; /* Process name */
474 FILE * fProc;
475 uint16_t defaultId;
476 trace_irq_entry irq;
477
478 fProc = fopen(argv[1],"r");
479 if(!fProc){
480 g_error("Unable to open file %s\n", argv[1]);
481 }
482
483 while(fscanf(fProc, "PID: %d; PPID: %d; NAME: %s\n", &lPID, &lPPID, lName) > 0){
484 defaultId = PROCESS_FORK_ID;
485 process.event_data1 = lPID;
486 process.event_data2 = lPPID;
487 write_to_buffer(write_pos_proc,(void*)&defaultId, sizeof(uint16_t));
488 write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t));
489 write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process));
490 }
491
492 while(fscanf(fProc, "IRQ: %d; NAME: ", &lIntID) > 0){
493 /* Read 'til the end of the line */
494 fgets(lName, 200, fProc);
495
496 defaultId = TRACE_IRQ_ENTRY;
497 irq.irq_id = lIntID;
498 irq.kernel = 1;
499 write_to_buffer(write_pos_intr,(void*)&defaultId, sizeof(uint16_t));
500 write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t));
501 write_to_buffer(write_pos_intr,(void*)&irq, sizeof(trace_irq_entry));
502 }
503 fclose(fProc);
504 }
505
506 while(1){
507 int event_size;
508 uint64_t timeDelta;
509 uint8_t subId;
510
511 if(ltt_log_cpu){
512 cpu_id = *(uint8_t*)cur_pos;
513 cur_pos += sizeof(uint8_t);
514 }
515 evId = *(uint8_t *)cur_pos;
516 newId = evId;
517 if(evId == TRACE_HEARTBEAT) {
518 newId = TRACE_HEARTBEAT_ID;
519 }
520 cur_pos += sizeof(uint8_t);
521 time_delta = *(uint32_t*)cur_pos;
522 cur_pos += sizeof(uint32_t);
523
524
525 //write event_id and time_delta
526 write_to_buffer(write_pos,(void*)&newId,sizeof(uint16_t));
527 write_to_buffer(write_pos,(void*)&time_delta, sizeof(uint32_t));
528
529 /* Fix (Mathieu) */
530 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
531 /* Overflow */
532 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + 0x100000000ULL
533 + (uint64_t)time_delta;
534 } else {
535 /* No overflow */
536 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
537 }
538
539
540 if(evId == TRACE_BUFFER_END){
541 #if 0
542 /* Fix (Mathieu) */
543 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
544 /* Overflow */
545 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + 0x100000000ULL
546 + (uint64_t)time_delta;
547 } else {
548 /* No overflow */
549 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
550 }
551 #endif //0
552 end.cycle_count = adaptation_tsc;
553 int size = (void*)buf_out + block_size - write_pos
554 - sizeof(buffer_end) - sizeof(uint32_t);
555
556 /* size _lost_ ? */
557 //int size = (void*)buf_out + block_size - write_pos
558 // + sizeof(uint16_t) + sizeof(uint32_t);
559 g_assert((void*)write_pos < (void*)buf_out + block_size);
560 write_to_buffer(write_pos,(void*)&end,sizeof(buffer_end));
561 write_pos = buf_out + block_size - sizeof(uint32_t);
562 write_to_buffer(write_pos,(void*)&size, sizeof(uint32_t));
563 write(fdCpu,(void*)buf_out, block_size);
564
565 //write out processes and intrrupts files
566 {
567 int size_intr = block_size + (void*)buf_intr - write_pos_intr
568 - sizeof(buffer_end) - sizeof(uint32_t);
569 int size_proc = block_size + (void*)buf_proc - write_pos_proc
570 - sizeof(buffer_end) - sizeof(uint32_t);
571 //int size_intr = block_size - (write_pos_intr - (void*)buf_intr);
572 //int size_proc = block_size - (write_pos_proc - (void*)buf_proc);
573 write_to_buffer(write_pos_intr,(void*)&newId,sizeof(uint16_t));
574 write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t));
575 end_intr = end;
576 end_intr.nanoseconds -= 20;
577 write_to_buffer(write_pos_intr,(void*)&end_intr,sizeof(buffer_start));
578
579 write_to_buffer(write_pos_proc,(void*)&newId,sizeof(uint16_t));
580 write_to_buffer(write_pos_proc,(void*)&time_delta, sizeof(uint32_t));
581 end_proc = end;
582 end_proc.nanoseconds -= 40;
583 write_to_buffer(write_pos_proc,(void*)&end_proc,sizeof(buffer_start));
584
585 write_pos_intr = buf_intr + block_size - sizeof(uint32_t);
586 write_pos_proc = buf_proc + block_size - sizeof(uint32_t);
587 write_to_buffer(write_pos_intr,(void*)&size_intr, sizeof(uint32_t));
588 write_to_buffer(write_pos_proc,(void*)&size_proc, sizeof(uint32_t));
589 //for now don't output processes and interrupt information
590 // write(fdIntr,(void*)buf_intr,block_size);
591 // write(fdProc,(void*)buf_proc,block_size);
592 }
593 break;
594 }
595
596 event_count++;
597 switch(evId){
598 case TRACE_SYSCALL_ENTRY:
599 event_size = sizeof(trace_syscall_entry);
600 break;
601 case TRACE_SYSCALL_EXIT:
602 event_size = 0;
603 break;
604 case TRACE_TRAP_ENTRY:
605 event_size = sizeof(trace_trap_entry);
606 break;
607 case TRACE_TRAP_EXIT:
608 event_size = 0;
609 break;
610 case TRACE_IRQ_ENTRY:
611 event_size = sizeof(trace_irq_entry);
612 timeDelta = time_delta;
613 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
614 write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
615 write_to_buffer(write_pos_intr,cur_pos, event_size);
616 break;
617 case TRACE_IRQ_EXIT:
618 event_size = 0;
619 timeDelta = time_delta;
620 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
621 write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
622 break;
623 case TRACE_SCHEDCHANGE:
624 event_size = sizeof(trace_schedchange);
625 break;
626 case TRACE_KERNEL_TIMER:
627 event_size = 0;
628 break;
629 case TRACE_SOFT_IRQ:
630 event_size = sizeof(trace_soft_irq);
631 // timeDelta = time_delta;
632 // write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
633 // write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
634 // write_to_buffer(write_pos_intr,cur_pos, event_size);
635 break;
636 case TRACE_PROCESS:
637 event_size = sizeof(trace_process);
638 timeDelta = time_delta;
639 subId = *(uint8_t*)cur_pos;
640 if(subId == TRACE_PROCESS_FORK || subId ==TRACE_PROCESS_EXIT){
641 if( subId == TRACE_PROCESS_FORK)tmpId = PROCESS_FORK_ID;
642 else tmpId = PROCESS_EXIT_ID;
643 write_to_buffer(write_pos_proc,(void*)&tmpId, sizeof(uint16_t));
644 write_to_buffer(write_pos_proc,(void*)&timeDelta, sizeof(uint32_t));
645
646 process = *(new_process*)(cur_pos + sizeof(uint8_t));
647 write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process));
648 }
649 break;
650 case TRACE_FILE_SYSTEM:
651 event_size = sizeof(trace_file_system)- sizeof(char*);
652 break;
653 case TRACE_TIMER:
654 event_size = sizeof(trace_timer);
655 break;
656 case TRACE_MEMORY:
657 event_size = sizeof(trace_memory);
658 break;
659 case TRACE_SOCKET:
660 event_size = sizeof(trace_socket);
661 break;
662 case TRACE_IPC:
663 event_size = sizeof(trace_ipc);
664 break;
665 case TRACE_NETWORK:
666 event_size = sizeof(trace_network);
667 break;
668 case TRACE_HEARTBEAT:
669 beat.seconds = 0;
670 beat.nanoseconds = 0;
671 beat.cycle_count = adaptation_tsc;
672 event_size = 0;
673
674 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
675 write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t));
676 write_to_buffer(write_pos_intr,(void*)&beat, sizeof(heartbeat));
677 write_to_buffer(write_pos_proc,(void*)&newId, sizeof(uint16_t));
678 write_to_buffer(write_pos_proc,(void*)&time_delta, sizeof(uint32_t));
679 write_to_buffer(write_pos_proc,(void*)&beat, sizeof(heartbeat));
680 break;
681 default:
682 event_size = -1;
683 break;
684 }
685 if(evId != TRACE_FILE_SYSTEM && event_size >=0){
686 write_to_buffer(write_pos, cur_pos, event_size);
687
688 if(evId == TRACE_HEARTBEAT){
689 write_to_buffer(write_pos, (void*)&beat, sizeof(heartbeat));
690 }
691
692 cur_pos += event_size + sizeof(uint16_t); //skip data_size
693 }else if(evId == TRACE_FILE_SYSTEM){
694 size_t nbBytes;
695 char c = '\0';
696 tFileSys = (trace_file_system*)cur_pos;
697 subId = tFileSys->event_sub_id;
698 if(subId == TRACE_FILE_SYSTEM_OPEN || subId == TRACE_FILE_SYSTEM_EXEC){
699 nbBytes = tFileSys->event_data2 +1;
700 }else nbBytes = 0;
701
702 write_to_buffer(write_pos, cur_pos, event_size);
703 cur_pos += event_size + sizeof(char*);
704 if(nbBytes){
705 write_to_buffer(write_pos, cur_pos, nbBytes);
706 }else{
707 write_to_buffer(write_pos, (void*)&c, 1);
708 }
709 cur_pos += nbBytes + sizeof(uint16_t); //skip data_size
710 }else if(event_size == -1){
711 printf("Unknown event: evId=%d, i=%d, event_count=%d\n", newId, i, event_count);
712 exit(1);
713 }
714 } //end while(1)
715 }
716 close(fd);
717 close(fdCpu);
718 g_free(buffer);
719 buffer = NULL;
720 g_free(buf_fac);
721 g_free(buf_intr);
722 g_free(buf_proc);
723 g_free(buf_out);
724 }
725
726
727
728
729
730 //write to system.xml
731 fprintf(fp,"<system \n");
732 fprintf(fp,"node_name=\"%s\" \n", node_name);
733 fprintf(fp,"domainname=\"%s\" \n", domainname);
734 fprintf(fp,"cpu=\"%d\" \n", cpu);
735 fprintf(fp,"arch_size=\"%s\" \n", arch_size);
736 fprintf(fp,"endian=\"%s\" \n",endian);
737 fprintf(fp,"kernel_name=\"%s\" \n",kernel_name);
738 fprintf(fp,"kernel_release=\"%s\" \n",kernel_release);
739 fprintf(fp,"kernel_version=\"%s\" \n",kernel_version);
740 fprintf(fp,"machine=\"%s\" \n",machine);
741 fprintf(fp,"processor=\"%s\" \n",processor);
742 fprintf(fp,"hardware_platform=\"%s\" \n",hardware_platform);
743 fprintf(fp,"operating_system=\"%s\" \n",operating_system);
744 fprintf(fp,"ltt_major_version=\"%d\" \n",ltt_major_version);
745 fprintf(fp,"ltt_minor_version=\"%d\" \n",ltt_minor_version);
746 fprintf(fp,"ltt_block_size=\"%d\" \n",ltt_block_size);
747 fprintf(fp,">\n");
748 fprintf(fp,"This is just a test\n");
749 fprintf(fp,"</system>\n");
750 fflush(fp);
751
752 close(fdFac);
753 close(fdIntr);
754 close(fdProc);
755 fclose(fp);
756
757 g_message("Conversion completed. Don't forget to copy core.xml to eventdefs directory\n");
758
759 return 0;
760 }
761
This page took 0.045931 seconds and 4 git commands to generate.