#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 0x100000000
-//#define OVERFLOW_FIGURE 0xffffffff
+#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){
+ ssize_t nbBytes = read(fd, buf, size);
+
+ if(nbBytes < 0) {
+ perror("Error in readFile : ");
+ exit(1);
+ } else if((size_t)nbBytes != size) {
printf("%s\n",mesg);
exit(1);
}
int ltt_minor_version;
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;
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);
startId = newId;
startTimeDelta = time_delta;
- previous_time_delta = time_delta;
start.seconds = tBufStart->Time.tv_sec;
start.nanoseconds = tBufStart->Time.tv_usec;
start.cycle_count = tBufStart->TSC;
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){
+ end.cycle_count = start.cycle_count
+ + beat_count * OVERFLOW_FIGURE;
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));
write_pos = buf_out + block_size - sizeof(uint32_t);
beat_count++;
beat.seconds = 0;
beat.nanoseconds = 0;
- beat.cycle_count = start.cycle_count + beat_count * OVERFLOW_FIGURE;
+ beat.cycle_count = (uint64_t)start.cycle_count
+ + (uint64_t)beat_count * OVERFLOW_FIGURE;
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;
}