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