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