#include <stdio.h>
+#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <linux/errno.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include "LTTTypes.h"
#define PROCESS_EXIT_ID 21
#define INFO_ENTRY 9
-#define OVERFLOW_FIGURE 4294967295
+#define OVERFLOW_FIGURE 0x100000000ULL
typedef struct _new_process
{
int readFile(int fd, void * buf, size_t size, char * mesg)
{
- ssize_t nbBytes;
- nbBytes = read(fd, buf, size);
- if(nbBytes != size){
- printf("%s\n",mesg);
+ ssize_t nbBytes = read(fd, buf, size);
+
+ if((size_t)nbBytes != size) {
+ if(nbBytes < 0) {
+ perror("Error in readFile : ");
+ } else {
+ printf("%s\n",mesg);
+ }
exit(1);
}
return 0;
uint32_t block_id;
} __attribute__ ((packed)) buffer_start;
+typedef struct _buffer_end{
+ uint32_t seconds;
+ uint32_t nanoseconds;
+ uint64_t cycle_count;
+ uint32_t block_id;
+} __attribute__ ((packed)) buffer_end;
+
+
typedef struct _heartbeat{
uint32_t seconds;
uint32_t nanoseconds;
char hardware_platform[BUFFER_SIZE];
char operating_system[BUFFER_SIZE];
int cpu;
- int ltt_block_size;
- int ltt_major_version;
- int ltt_minor_version;
+ int ltt_block_size=0;
+ int ltt_major_version=0;
+ int ltt_minor_version=0;
int ltt_log_cpu;
char buf[BUFFER_SIZE];
- int i,j, k;
+ int i, k;
uint8_t cpu_id;
trace_file_system * tFileSys;
uint16_t newId, startId, tmpId;
uint8_t evId;
- uint32_t time_delta, startTimeDelta, previous_time_delta;
+ uint32_t time_delta, startTimeDelta;
void * cur_pos, *end_pos;
buffer_start start, start_proc, start_intr;
- buffer_start end, end_proc, end_intr;
+ buffer_end end, end_proc, end_intr;
heartbeat beat;
- int beat_count = 0;
+ uint64_t beat_count;
uint32_t size_lost;
int reserve_size = sizeof(buffer_start) + sizeof(uint16_t) + 2*sizeof(uint32_t);//lost_size and buffer_end event
int nb_para;
startId = newId;
startTimeDelta = time_delta;
start.seconds = tBufStart->Time.tv_sec;
- start.nanoseconds = tBufStart->Time.tv_usec;
+ /* Fix (Mathieu) */
+ start.nanoseconds = tBufStart->Time.tv_usec * 1000;
start.cycle_count = tBufStart->TSC;
start.block_id = tBufStart->ID;
end.block_id = start.block_id;
ltt_block_size = tStart->BufferSize;
ltt_log_cpu = tStart->LogCPUID;
- block_size = ltt_block_size;
- block_number = file_size/block_size;
+ block_size = ltt_block_size;//FIXME
+ block_number = file_size/ltt_block_size;
g_free(buffer);
- buffer = g_new(char, block_size);
+ buffer = g_new(char, ltt_block_size);
buf_fac = g_new(char, block_size);
write_pos_fac = buf_fac;
buf_intr = g_new(char, block_size);
buf_out = g_new(char, block_size);
write_pos = buf_out;
- sprintf(cpuStr,"%s/%d\0",foo_cpu,k);
+ sprintf(cpuStr,"%s/%d",foo_cpu,k);
fdCpu = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu k
if(fdCpu < 0) g_error("Unable to open cpu file %d\n", k);
lseek(fd,0,SEEK_SET);
for(i=0;i<block_number;i++){
int event_count = 0;
- beat_count = 0;
memset((void*)buf_out, 0, block_size);
write_pos = buf_out;
write_pos_fac = buf_fac;
write_pos_proc = buf_proc;
- memset((void*)buffer,0,block_size);
- readFile(fd,(void*)buffer, block_size, "Unable to read block header");
+ memset((void*)buffer,0,ltt_block_size);
+ readFile(fd,(void*)buffer, ltt_block_size, "Unable to read block header");
cur_pos= buffer;
evId = *(uint8_t *)cur_pos;
startId = newId;
startTimeDelta = time_delta;
- previous_time_delta = time_delta;
start.seconds = tBufStart->Time.tv_sec;
- start.nanoseconds = tBufStart->Time.tv_usec;
+ /* usec -> nsec (Mathieu) */
+ start.nanoseconds = tBufStart->Time.tv_usec * 1000;
start.cycle_count = tBufStart->TSC;
+ beat_count = start.cycle_count;
start.block_id = tBufStart->ID;
end.block_id = start.block_id;
- end_pos = buffer + block_size; //end of the buffer
+ end_pos = buffer + ltt_block_size; //end of the buffer
size_lost = *(uint32_t*)(end_pos - sizeof(uint32_t));
- end_pos = buffer + block_size - size_lost ; //buffer_end event
+ end_pos = buffer + ltt_block_size - size_lost ; //buffer_end event
if(ltt_log_cpu){
tBufEnd = (trace_buffer_end*)(end_pos + 2 * sizeof(uint8_t)+sizeof(uint32_t));
}else{
tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t));
}
end.seconds = tBufEnd->Time.tv_sec;
- end.nanoseconds = tBufEnd->Time.tv_usec;
+ /* usec -> nsec (Mathieu) */
+ end.nanoseconds = tBufEnd->Time.tv_usec * 1000;
end.cycle_count = tBufEnd->TSC;
//skip buffer start and trace start events
time_delta = *(uint32_t*)cur_pos;
cur_pos += sizeof(uint32_t);
- if(time_delta < previous_time_delta){
- end.cycle_count += OVERFLOW_FIGURE;
- }
- previous_time_delta = time_delta;
-
//write event_id and time_delta
write_to_buffer(write_pos,(void*)&newId,sizeof(uint16_t));
write_to_buffer(write_pos,(void*)&time_delta, sizeof(uint32_t));
if(evId == TRACE_BUFFER_END){
- int size = block_size + ((void*)buf_out - write_pos)+ sizeof(uint16_t) + sizeof(uint32_t);
- write_to_buffer(write_pos,(void*)&end,sizeof(buffer_start));
+#if 0 //(Mathieu : already set correctly to tBufEnd.TSC)
+ end.cycle_count = start.cycle_count
+ + beat_count * OVERFLOW_FIGURE;
+#endif //)
+ int size = (void*)buf_out + block_size - write_pos
+ - sizeof(buffer_end) - sizeof(uint32_t);
+
+ /* size _lost_ ? */
+ //int size = (void*)buf_out + block_size - write_pos
+ // + sizeof(uint16_t) + sizeof(uint32_t);
+ g_assert((void*)write_pos < (void*)buf_out + block_size);
+ write_to_buffer(write_pos,(void*)&end,sizeof(buffer_end));
write_pos = buf_out + block_size - sizeof(uint32_t);
write_to_buffer(write_pos,(void*)&size, sizeof(uint32_t));
write(fdCpu,(void*)buf_out, block_size);
//write out processes and intrrupts files
{
- int size_intr = block_size - (write_pos_intr - (void*)buf_intr);
- int size_proc = block_size - (write_pos_proc - (void*)buf_proc);
+ int size_intr = block_size + (void*)buf_intr - write_pos_intr
+ - sizeof(buffer_end) - sizeof(uint32_t);
+ int size_proc = block_size + (void*)buf_proc - write_pos_proc
+ - sizeof(buffer_end) - sizeof(uint32_t);
+ //int size_intr = block_size - (write_pos_intr - (void*)buf_intr);
+ //int size_proc = block_size - (write_pos_proc - (void*)buf_proc);
write_to_buffer(write_pos_intr,(void*)&newId,sizeof(uint16_t));
write_to_buffer(write_pos_intr,(void*)&time_delta, sizeof(uint32_t));
end_intr = end;
event_size = sizeof(trace_network);
break;
case TRACE_HEARTBEAT:
- beat_count++;
+ /* Fix (Mathieu) */
+ if(timeDelta < (0xFFFFFFFF&beat_count)) {
+ /* Overflow */
+ beat_count += 0x100000000ULL - (uint64_t)(0xFFFFFFFF&beat_count)
+ + (uint64_t)timeDelta;
+ } else {
+ /* No overflow */
+ beat_count += timeDelta - (0xFFFFFFFF&beat_count);
+ }
beat.seconds = 0;
beat.nanoseconds = 0;
- beat.cycle_count = start.cycle_count + beat_count * OVERFLOW_FIGURE;
+ beat.cycle_count = beat_count;
event_size = 0;
-
- // end.cycle_count += OVERFLOW_FIGURE;
write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
close(fdProc);
fclose(fp);
+ return 0;
}