fix offset at trace start
[lttv.git] / ltt / branches / poly / ltt / convert / convert.c
CommitLineData
160d4bdb 1#include <stdio.h>
ee26cd96 2#include <unistd.h>
160d4bdb 3#include <fcntl.h>
4#include <sys/stat.h>
5#include <sys/types.h>
ee26cd96 6#include <errno.h>
7#include <stdlib.h>
8#include <string.h>
160d4bdb 9
10#include <glib.h>
11#include "LTTTypes.h"
12#include "LinuxEvents.h"
13
c9e8ac96 14#define TRACE_HEARTBEAT_ID 19
1812dbb9 15#define PROCESS_FORK_ID 20
16#define PROCESS_EXIT_ID 21
17
c9e8ac96 18#define INFO_ENTRY 9
ee26cd96 19#define OVERFLOW_FIGURE 0x100000000ULL
c9e8ac96 20
1812dbb9 21typedef 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
160d4bdb 27#define write_to_buffer(DEST, SRC, SIZE) \
28do\
29{\
30 memcpy(DEST, SRC, SIZE);\
31 DEST += SIZE;\
32} while(0);
33
34int readFile(int fd, void * buf, size_t size, char * mesg)
35{
ee26cd96 36 ssize_t nbBytes = read(fd, buf, size);
37
8d1e6362 38 if((size_t)nbBytes != size) {
39 if(nbBytes < 0) {
40 perror("Error in readFile : ");
41 } else {
42 printf("%s\n",mesg);
43 }
160d4bdb 44 exit(1);
45 }
46 return 0;
47}
48
49void 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
71typedef 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
63c35f6c 78typedef 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
160d4bdb 86typedef struct _heartbeat{
87 uint32_t seconds;
88 uint32_t nanoseconds;
89 uint64_t cycle_count;
90} __attribute__ ((packed)) heartbeat;
91
92
93int main(int argc, char ** argv){
94
91a66e87 95 int fd, fdCpu;
160d4bdb 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;
cf74a6f1 110 int ltt_block_size=0;
111 int ltt_major_version=0;
112 int ltt_minor_version=0;
160d4bdb 113 int ltt_log_cpu;
3fc51411 114 guint ltt_trace_start_size;
160d4bdb 115 char buf[BUFFER_SIZE];
ee26cd96 116 int i, k;
160d4bdb 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;
91a66e87 134 char * buffer, *buf_out, cpuStr[4*BUFFER_SIZE];
160d4bdb 135 char * buf_fac, * buf_intr, * buf_proc;
91a66e87 136 void * write_pos, *write_pos_fac, * write_pos_intr, *write_pos_proc;
3fc51411 137 trace_start_any *tStart;
160d4bdb 138 trace_buffer_start *tBufStart;
139 trace_buffer_end *tBufEnd;
140 trace_file_system * tFileSys;
1812dbb9 141 uint16_t newId, startId, tmpId;
160d4bdb 142 uint8_t evId;
ee26cd96 143 uint32_t time_delta, startTimeDelta;
160d4bdb 144 void * cur_pos, *end_pos;
c9e8ac96 145 buffer_start start, start_proc, start_intr;
63c35f6c 146 buffer_end end, end_proc, end_intr;
160d4bdb 147 heartbeat beat;
8ee1c3d5 148 uint64_t adaptation_tsc; // (Mathieu)
160d4bdb 149 uint32_t size_lost;
3fc51411 150 int reserve_size = sizeof(buffer_start) +
151 sizeof(buffer_end) + //buffer_end event
152 sizeof(uint32_t); //lost size
91a66e87 153 int nb_para;
160d4bdb 154
1812dbb9 155 new_process process;
156
91a66e87 157 if(argc < 4){
bc61167f 158 printf("Usage : ./convert processfile_name number_of_cpu tracefile1 tracefile2 ... trace_creation_directory\n");
159 printf("For more details, see README.\n");
160d4bdb 160 exit(1);
161 }
162
91a66e87 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){
160d4bdb 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{
91a66e87 179 strcpy(foo, argv[nb_para]);
180 strcpy(foo_eventdefs, argv[nb_para]);
160d4bdb 181 strcat(foo_eventdefs,"/eventdefs");
91a66e87 182 strcpy(foo_control, argv[nb_para]);
160d4bdb 183 strcat(foo_control,"/control");
91a66e87 184 strcpy(foo_cpu, argv[nb_para]);
160d4bdb 185 strcat(foo_cpu,"/cpu");
91a66e87 186 strcpy(foo_info, argv[nb_para]);
160d4bdb 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
160d4bdb 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
c9e8ac96 207 for(i=0;i<INFO_ENTRY;i++){
160d4bdb 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
160d4bdb 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);
a1fbc64f 266 if(fdProc<0){
160d4bdb 267 g_error("Unable to open file process\n");
268 }
269
270
91a66e87 271 for(k=0;k<cpu;k++){
acd767ee 272 fd = open(argv[nb_para-cpu+k], O_RDONLY, 0);
91a66e87 273 if(fd < 0){
acd767ee 274 g_error("Unable to open input data file %s\n", argv[nb_para-cpu+k]);
160d4bdb 275 }
91a66e87 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;
160d4bdb 281
91a66e87 282 buffer = g_new(char, 4000);
283 readFile(fd,(void*)buffer, 3500, "Unable to read block header");
284
160d4bdb 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
91a66e87 295 evId = *(uint8_t *)cur_pos;
0ff39ce4 296 g_assert(evId == TRACE_START);
297 cur_pos += sizeof(uint8_t); //skip EvId
298 cur_pos += sizeof(uint32_t); //skip time delta
3fc51411 299 tStart = (trace_start_any*)cur_pos;
0ff39ce4 300 if(tStart->MagicNumber != TRACER_MAGIC_NUMBER)
301 g_error("Trace magic number does not match : %lx, should be %lx",
302 tStart->MagicNumber, TRACER_MAGIC_NUMBER);
3fc51411 303 if(tStart->MajorVersion != TRACER_SUP_VERSION_MAJOR)
304 g_error("Trace Major number does match : %hu, should be %u",
305 tStart->MajorVersion, TRACER_SUP_VERSION_MAJOR);
91a66e87 306
160d4bdb 307 startId = newId;
308 startTimeDelta = time_delta;
309 start.seconds = tBufStart->Time.tv_sec;
63c35f6c 310 /* Fix (Mathieu) */
311 start.nanoseconds = tBufStart->Time.tv_usec * 1000;
160d4bdb 312 start.cycle_count = tBufStart->TSC;
313 start.block_id = tBufStart->ID;
314 end.block_id = start.block_id;
315
0ff39ce4 316
317 g_printf("Trace version %hu.%hu detected\n",
318 tStart->MajorVersion,
319 tStart->MinorVersion);
3fc51411 320 if(tStart->MinorVersion == 2) {
321 trace_start_2_2* tStart_2_2 = (trace_start_2_2*)tStart;
322 ltt_major_version = tStart_2_2->MajorVersion;
323 ltt_minor_version = tStart_2_2->MinorVersion;
324 ltt_block_size = tStart_2_2->BufferSize;
325 ltt_log_cpu = tStart_2_2->LogCPUID;
326 ltt_trace_start_size = sizeof(trace_start_2_2);
327 } else if(tStart->MinorVersion == 3) {
328 trace_start_2_3* tStart_2_3 = (trace_start_2_3*)tStart;
329 ltt_major_version = tStart_2_3->MajorVersion;
330 ltt_minor_version = tStart_2_3->MinorVersion;
331 ltt_block_size = tStart_2_3->BufferSize;
332 ltt_log_cpu = tStart_2_3->LogCPUID;
333 ltt_trace_start_size = sizeof(trace_start_2_3);
334 /* We do not use the flight recorder information for now, because we
335 * never use the .proc file anyway */
336 } else {
337 ltt_trace_start_size = 0;
338 g_error("Minor version unknown : %hu. Supported minors : 2, 3",
339 tStart->MinorVersion);
340 }
c9e8ac96 341
63c35f6c 342 block_size = ltt_block_size;//FIXME
343 block_number = file_size/ltt_block_size;
c9e8ac96 344
91a66e87 345 g_free(buffer);
63c35f6c 346 buffer = g_new(char, ltt_block_size);
91a66e87 347 buf_fac = g_new(char, block_size);
348 write_pos_fac = buf_fac;
349 buf_intr = g_new(char, block_size);
350 write_pos_intr = buf_intr;
351 buf_proc = g_new(char, block_size);
352 write_pos_proc = buf_proc;
160d4bdb 353
91a66e87 354 buf_out = g_new(char, block_size);
355 write_pos = buf_out;
ee26cd96 356 sprintf(cpuStr,"%s/%d",foo_cpu,k);
91a66e87 357 fdCpu = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu k
358 if(fdCpu < 0) g_error("Unable to open cpu file %d\n", k);
359 lseek(fd,0,SEEK_SET);
360
361 for(i=0;i<block_number;i++){
362 int event_count = 0;
91a66e87 363
364 memset((void*)buf_out, 0, block_size);
365 write_pos = buf_out;
366 memset((void*)buf_intr, 0, block_size);
367 memset((void*)buf_fac, 0, block_size);
368 memset((void*)buf_proc, 0, block_size);
369 write_pos_intr = buf_intr;
370 write_pos_fac = buf_fac;
371 write_pos_proc = buf_proc;
372
63c35f6c 373 memset((void*)buffer,0,ltt_block_size);
374 readFile(fd,(void*)buffer, ltt_block_size, "Unable to read block header");
91a66e87 375
376 cur_pos= buffer;
160d4bdb 377 evId = *(uint8_t *)cur_pos;
160d4bdb 378 cur_pos += sizeof(uint8_t);
91a66e87 379 newId = evId;
160d4bdb 380 time_delta = *(uint32_t*)cur_pos;
381 cur_pos += sizeof(uint32_t);
91a66e87 382 tBufStart = (trace_buffer_start*)cur_pos;
383 cur_pos += sizeof(trace_buffer_start);
384 cur_pos += sizeof(uint16_t); //Skip event size
160d4bdb 385
91a66e87 386 startId = newId;
387 startTimeDelta = time_delta;
91a66e87 388 start.seconds = tBufStart->Time.tv_sec;
9c57bb37 389 /* usec -> nsec (Mathieu) */
390 start.nanoseconds = tBufStart->Time.tv_usec * 1000;
91a66e87 391 start.block_id = tBufStart->ID;
392 end.block_id = start.block_id;
393
63c35f6c 394 end_pos = buffer + ltt_block_size; //end of the buffer
91a66e87 395 size_lost = *(uint32_t*)(end_pos - sizeof(uint32_t));
396
63c35f6c 397 end_pos = buffer + ltt_block_size - size_lost ; //buffer_end event
160d4bdb 398 if(ltt_log_cpu){
91a66e87 399 tBufEnd = (trace_buffer_end*)(end_pos + 2 * sizeof(uint8_t)+sizeof(uint32_t));
400 }else{
401 tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t));
160d4bdb 402 }
91a66e87 403 end.seconds = tBufEnd->Time.tv_sec;
9c57bb37 404 /* usec -> nsec (Mathieu) */
405 end.nanoseconds = tBufEnd->Time.tv_usec * 1000;
8ee1c3d5 406 // only 32 bits :(
407 //end.cycle_count = tBufEnd->TSC;
91a66e87 408
409 //skip buffer start and trace start events
8ee1c3d5 410 if(i==0) {
411 //the first block
412 adaptation_tsc = (uint64_t)tBufStart->TSC;
413 cur_pos = buffer + sizeof(trace_buffer_start)
3fc51411 414 + ltt_trace_start_size
8ee1c3d5 415 + 2*(sizeof(uint8_t)
416 + sizeof(uint16_t)+sizeof(uint32_t));
417 } else {
418 //other blocks
419 cur_pos = buffer + sizeof(trace_buffer_start)
420 + sizeof(uint8_t)
421 + sizeof(uint16_t)+sizeof(uint32_t);
422
423 /* Fix (Mathieu) */
424 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
425 /* Overflow */
426 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL)
427 + 0x100000000ULL
428 + (uint64_t)time_delta;
429 } else {
430 /* No overflow */
431 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
432 }
433
434 }
435 start.cycle_count = adaptation_tsc;
436
91a66e87 437 //write start block event
438 write_to_buffer(write_pos,(void*)&startId, sizeof(uint16_t));
439 write_to_buffer(write_pos,(void*)&startTimeDelta, sizeof(uint32_t));
440 write_to_buffer(write_pos,(void*)&start, sizeof(buffer_start));
441
442 //write start block event into processes and interrupts files
443 write_to_buffer(write_pos_intr,(void*)&startId, sizeof(uint16_t));
444 write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t));
445 start_intr = start;
446 start_intr.nanoseconds -= 20;
447 write_to_buffer(write_pos_intr,(void*)&start_intr, sizeof(buffer_start));
448
449 write_to_buffer(write_pos_proc,(void*)&startId, sizeof(uint16_t));
450 write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t));
451 start_proc = start;
452 start_proc.nanoseconds -= 40;
453 write_to_buffer(write_pos_proc,(void*)&start_proc, sizeof(buffer_start));
454
455 //parse *.proc file to get process and irq info
456 if(i == 0){
457 int lIntID; /* Interrupt ID */
458 int lPID, lPPID; /* Process PID and Parent PID */
459 char lName[256]; /* Process name */
460 FILE * fProc;
461 uint16_t defaultId;
462 trace_irq_entry irq;
463
464 fProc = fopen(argv[1],"r");
465 if(!fProc){
466 g_error("Unable to open file %s\n", argv[1]);
160d4bdb 467 }
91a66e87 468
469 while(fscanf(fProc, "PID: %d; PPID: %d; NAME: %s\n", &lPID, &lPPID, lName) > 0){
470 defaultId = PROCESS_FORK_ID;
471 process.event_data1 = lPID;
472 process.event_data2 = lPPID;
473 write_to_buffer(write_pos_proc,(void*)&defaultId, sizeof(uint16_t));
474 write_to_buffer(write_pos_proc,(void*)&startTimeDelta, sizeof(uint32_t));
475 write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process));
476 }
477
478 while(fscanf(fProc, "IRQ: %d; NAME: ", &lIntID) > 0){
479 /* Read 'til the end of the line */
480 fgets(lName, 200, fProc);
481
482 defaultId = TRACE_IRQ_ENTRY;
483 irq.irq_id = lIntID;
484 irq.kernel = 1;
485 write_to_buffer(write_pos_intr,(void*)&defaultId, sizeof(uint16_t));
486 write_to_buffer(write_pos_intr,(void*)&startTimeDelta, sizeof(uint32_t));
487 write_to_buffer(write_pos_intr,(void*)&irq, sizeof(trace_irq_entry));
160d4bdb 488 }
91a66e87 489 fclose(fProc);
160d4bdb 490 }
491
91a66e87 492 while(1){
493 int event_size;
494 uint64_t timeDelta;
495 uint8_t subId;
496
160d4bdb 497 if(ltt_log_cpu){
91a66e87 498 cpu_id = *(uint8_t*)cur_pos;
499 cur_pos += sizeof(uint8_t);
500 }
501 evId = *(uint8_t *)cur_pos;
502 newId = evId;
503 if(evId == TRACE_HEARTBEAT) {
504 newId = TRACE_HEARTBEAT_ID;
160d4bdb 505 }
91a66e87 506 cur_pos += sizeof(uint8_t);
507 time_delta = *(uint32_t*)cur_pos;
508 cur_pos += sizeof(uint32_t);
8ee1c3d5 509
510
91a66e87 511 //write event_id and time_delta
512 write_to_buffer(write_pos,(void*)&newId,sizeof(uint16_t));
513 write_to_buffer(write_pos,(void*)&time_delta, sizeof(uint32_t));
0e122455 514
515 /* Fix (Mathieu) */
516 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
517 /* Overflow */
518 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + 0x100000000ULL
519 + (uint64_t)time_delta;
520 } else {
521 /* No overflow */
522 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
523 }
524
525
91a66e87 526 if(evId == TRACE_BUFFER_END){
0e122455 527#if 0
8ee1c3d5 528 /* Fix (Mathieu) */
529 if(time_delta < (0xFFFFFFFFULL&adaptation_tsc)) {
530 /* Overflow */
531 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + 0x100000000ULL
532 + (uint64_t)time_delta;
533 } else {
534 /* No overflow */
535 adaptation_tsc = (adaptation_tsc&0xFFFFFFFF00000000ULL) + time_delta;
536 }
0e122455 537#endif //0
8ee1c3d5 538 end.cycle_count = adaptation_tsc;
63c35f6c 539 int size = (void*)buf_out + block_size - write_pos
540 - sizeof(buffer_end) - sizeof(uint32_t);
541
542 /* size _lost_ ? */
543 //int size = (void*)buf_out + block_size - write_pos
544 // + sizeof(uint16_t) + sizeof(uint32_t);
545 g_assert((void*)write_pos < (void*)buf_out + block_size);
546 write_to_buffer(write_pos,(void*)&end,sizeof(buffer_end));
91a66e87 547 write_pos = buf_out + block_size - sizeof(uint32_t);
548 write_to_buffer(write_pos,(void*)&size, sizeof(uint32_t));
549 write(fdCpu,(void*)buf_out, block_size);
550
551 //write out processes and intrrupts files
552 {
63c35f6c 553 int size_intr = block_size + (void*)buf_intr - write_pos_intr
554 - sizeof(buffer_end) - sizeof(uint32_t);
555 int size_proc = block_size + (void*)buf_proc - write_pos_proc
556 - sizeof(buffer_end) - sizeof(uint32_t);
557 //int size_intr = block_size - (write_pos_intr - (void*)buf_intr);
558 //int size_proc = block_size - (write_pos_proc - (void*)buf_proc);
91a66e87 559 write_to_buffer(write_pos_intr,(void*)&newId,sizeof(uint16_t));
560 write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t));
561 end_intr = end;
562 end_intr.nanoseconds -= 20;
563 write_to_buffer(write_pos_intr,(void*)&end_intr,sizeof(buffer_start));
564
565 write_to_buffer(write_pos_proc,(void*)&newId,sizeof(uint16_t));
566 write_to_buffer(write_pos_proc,(void*)&time_delta, sizeof(uint32_t));
567 end_proc = end;
568 end_proc.nanoseconds -= 40;
569 write_to_buffer(write_pos_proc,(void*)&end_proc,sizeof(buffer_start));
570
571 write_pos_intr = buf_intr + block_size - sizeof(uint32_t);
572 write_pos_proc = buf_proc + block_size - sizeof(uint32_t);
573 write_to_buffer(write_pos_intr,(void*)&size_intr, sizeof(uint32_t));
574 write_to_buffer(write_pos_proc,(void*)&size_proc, sizeof(uint32_t));
575 //for now don't output processes and interrupt information
576 // write(fdIntr,(void*)buf_intr,block_size);
577 // write(fdProc,(void*)buf_proc,block_size);
578 }
579 break;
580 }
160d4bdb 581
91a66e87 582 event_count++;
583 switch(evId){
584 case TRACE_SYSCALL_ENTRY:
585 event_size = sizeof(trace_syscall_entry);
586 break;
587 case TRACE_SYSCALL_EXIT:
588 event_size = 0;
589 break;
590 case TRACE_TRAP_ENTRY:
591 event_size = sizeof(trace_trap_entry);
592 break;
593 case TRACE_TRAP_EXIT:
594 event_size = 0;
595 break;
596 case TRACE_IRQ_ENTRY:
597 event_size = sizeof(trace_irq_entry);
598 timeDelta = time_delta;
599 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
600 write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
601 write_to_buffer(write_pos_intr,cur_pos, event_size);
602 break;
603 case TRACE_IRQ_EXIT:
604 event_size = 0;
605 timeDelta = time_delta;
606 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
607 write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
608 break;
609 case TRACE_SCHEDCHANGE:
610 event_size = sizeof(trace_schedchange);
611 break;
612 case TRACE_KERNEL_TIMER:
613 event_size = 0;
614 break;
615 case TRACE_SOFT_IRQ:
616 event_size = sizeof(trace_soft_irq);
617 // timeDelta = time_delta;
618 // write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
619 // write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
620 // write_to_buffer(write_pos_intr,cur_pos, event_size);
621 break;
622 case TRACE_PROCESS:
623 event_size = sizeof(trace_process);
624 timeDelta = time_delta;
625 subId = *(uint8_t*)cur_pos;
626 if(subId == TRACE_PROCESS_FORK || subId ==TRACE_PROCESS_EXIT){
627 if( subId == TRACE_PROCESS_FORK)tmpId = PROCESS_FORK_ID;
628 else tmpId = PROCESS_EXIT_ID;
629 write_to_buffer(write_pos_proc,(void*)&tmpId, sizeof(uint16_t));
630 write_to_buffer(write_pos_proc,(void*)&timeDelta, sizeof(uint32_t));
631
632 process = *(new_process*)(cur_pos + sizeof(uint8_t));
633 write_to_buffer(write_pos_proc,(void*)&process, sizeof(new_process));
634 }
635 break;
636 case TRACE_FILE_SYSTEM:
637 event_size = sizeof(trace_file_system)- sizeof(char*);
638 break;
639 case TRACE_TIMER:
640 event_size = sizeof(trace_timer);
641 break;
642 case TRACE_MEMORY:
643 event_size = sizeof(trace_memory);
644 break;
645 case TRACE_SOCKET:
646 event_size = sizeof(trace_socket);
647 break;
648 case TRACE_IPC:
649 event_size = sizeof(trace_ipc);
650 break;
651 case TRACE_NETWORK:
652 event_size = sizeof(trace_network);
653 break;
654 case TRACE_HEARTBEAT:
91a66e87 655 beat.seconds = 0;
656 beat.nanoseconds = 0;
8ee1c3d5 657 beat.cycle_count = adaptation_tsc;
91a66e87 658 event_size = 0;
91a66e87 659
660 write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
8ee1c3d5 661 write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t));
91a66e87 662 write_to_buffer(write_pos_intr,(void*)&beat, sizeof(heartbeat));
663 write_to_buffer(write_pos_proc,(void*)&newId, sizeof(uint16_t));
8ee1c3d5 664 write_to_buffer(write_pos_proc,(void*)&time_delta, sizeof(uint32_t));
91a66e87 665 write_to_buffer(write_pos_proc,(void*)&beat, sizeof(heartbeat));
666 break;
667 default:
668 event_size = -1;
669 break;
670 }
671 if(evId != TRACE_FILE_SYSTEM && event_size >=0){
672 write_to_buffer(write_pos, cur_pos, event_size);
673
674 if(evId == TRACE_HEARTBEAT){
675 write_to_buffer(write_pos, (void*)&beat, sizeof(heartbeat));
160d4bdb 676 }
91a66e87 677
678 cur_pos += event_size + sizeof(uint16_t); //skip data_size
679 }else if(evId == TRACE_FILE_SYSTEM){
680 size_t nbBytes;
681 char c = '\0';
682 tFileSys = (trace_file_system*)cur_pos;
683 subId = tFileSys->event_sub_id;
684 if(subId == TRACE_FILE_SYSTEM_OPEN || subId == TRACE_FILE_SYSTEM_EXEC){
685 nbBytes = tFileSys->event_data2 +1;
686 }else nbBytes = 0;
687
688 write_to_buffer(write_pos, cur_pos, event_size);
160d4bdb 689 cur_pos += event_size + sizeof(char*);
690 if(nbBytes){
91a66e87 691 write_to_buffer(write_pos, cur_pos, nbBytes);
160d4bdb 692 }else{
91a66e87 693 write_to_buffer(write_pos, (void*)&c, 1);
160d4bdb 694 }
91a66e87 695 cur_pos += nbBytes + sizeof(uint16_t); //skip data_size
696 }else if(event_size == -1){
697 printf("Unknown event: evId=%d, i=%d, event_count=%d\n", newId, i, event_count);
698 exit(1);
160d4bdb 699 }
91a66e87 700 } //end while(1)
701 }
702 close(fd);
703 close(fdCpu);
704 g_free(buffer);
705 buffer = NULL;
706 g_free(buf_fac);
707 g_free(buf_intr);
708 g_free(buf_proc);
709 g_free(buf_out);
160d4bdb 710 }
711
712
713
714
715
716 //write to system.xml
43da6a59 717 fprintf(fp,"<system \n");
718 fprintf(fp,"node_name=\"%s\" \n", node_name);
719 fprintf(fp,"domainname=\"%s\" \n", domainname);
720 fprintf(fp,"cpu=\"%d\" \n", cpu);
721 fprintf(fp,"arch_size=\"%s\" \n", arch_size);
722 fprintf(fp,"endian=\"%s\" \n",endian);
723 fprintf(fp,"kernel_name=\"%s\" \n",kernel_name);
724 fprintf(fp,"kernel_release=\"%s\" \n",kernel_release);
725 fprintf(fp,"kernel_version=\"%s\" \n",kernel_version);
726 fprintf(fp,"machine=\"%s\" \n",machine);
727 fprintf(fp,"processor=\"%s\" \n",processor);
728 fprintf(fp,"hardware_platform=\"%s\" \n",hardware_platform);
729 fprintf(fp,"operating_system=\"%s\" \n",operating_system);
730 fprintf(fp,"ltt_major_version=\"%d\" \n",ltt_major_version);
731 fprintf(fp,"ltt_minor_version=\"%d\" \n",ltt_minor_version);
732 fprintf(fp,"ltt_block_size=\"%d\" \n",ltt_block_size);
160d4bdb 733 fprintf(fp,">\n");
734 fprintf(fp,"This is just a test\n");
735 fprintf(fp,"</system>\n");
736 fflush(fp);
737
160d4bdb 738 close(fdFac);
739 close(fdIntr);
740 close(fdProc);
91a66e87 741 fclose(fp);
160d4bdb 742
ee26cd96 743 return 0;
160d4bdb 744}
745
This page took 0.099147 seconds and 4 git commands to generate.