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