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