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