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