#include <errno.h>
#include <unistd.h>
#include <math.h>
+#include <glib/gstdio.h>
// For realpath
#include <limits.h>
#define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
#define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
+#define g_close close
/* obtain the time of an event */
gint offsetParent, LttField *fld, void *evD, LttTrace* t);
/* read a fixed size or a block information from the file (fd) */
-int readFile(int fd, void * buf, size_t size, char * mesg);
+int readFile(int fd, void * buf, size_t size, gchar * mesg);
int readBlock(LttTracefile * tf, int whichBlock);
/* calculate cycles per nsec for current block */
* : a pointer to a tracefile
****************************************************************************/
-LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName)
+LttTracefile* ltt_tracefile_open(LttTrace * t, gchar * fileName)
{
LttTracefile * tf;
struct stat lTDFStat; /* Trace data file status */
//open the file
tf->name = g_strdup(fileName);
tf->trace = t;
- tf->fd = open(fileName, O_RDONLY, 0);
+ tf->fd = g_open(fileName, O_RDONLY, 0);
if(tf->fd < 0){
g_warning("Unable to open input data file %s\n", fileName);
g_free(tf->name);
if(fstat(tf->fd, &lTDFStat) < 0){
g_warning("Unable to get the status of the input data file %s\n", fileName);
g_free(tf->name);
- close(tf->fd);
+ g_close(tf->fd);
g_free(tf);
return NULL;
}
if(lTDFStat.st_size < (off_t)(sizeof(BlockStart) + EVENT_HEADER_SIZE)){
g_print("The input data file %s does not contain a trace\n", fileName);
g_free(tf->name);
- close(tf->fd);
+ g_close(tf->fd);
g_free(tf);
return NULL;
}
tf->which_block = 0;
//allocate memory to contain the info of a block
- tf->buffer = (void *) g_new(char, t->system_description->ltt_block_size);
+ tf->buffer = (void *) g_new(gchar, t->system_description->ltt_block_size);
//read the first block
if(readBlock(tf,1)) exit(1);
*Open control and per cpu tracefiles
****************************************************************************/
-void ltt_tracefile_open_cpu(LttTrace *t, char * tracefile_name)
+void ltt_tracefile_open_cpu(LttTrace *t, gchar * tracefile_name)
{
LttTracefile * tf;
tf = ltt_tracefile_open(t,tracefile_name);
g_ptr_array_add(t->per_cpu_tracefiles, tf);
}
-gint ltt_tracefile_open_control(LttTrace *t, char * control_name)
+gint ltt_tracefile_open_control(LttTrace *t, gchar * control_name)
{
LttTracefile * tf;
LttEvent ev;
if(ev.event_id == TRACE_FACILITY_LOAD){
pos = ev.data;
- fLoad.name = (char*)pos;
+ fLoad.name = (gchar*)pos;
fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
fLoad.base_code = *(guint32 *)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
/*****************************************************************************
*Get system information
****************************************************************************/
-gint getSystemInfo(LttSystemDescription* des, char * pathname)
+gint getSystemInfo(LttSystemDescription* des, gchar * pathname)
{
- FILE * fp;
- char buf[DIR_NAME_SIZE];
+ int fd;
+ GIOChannel *iochan;
+ gchar *buf = NULL;
+ gsize length;
GMarkupParseContext * context;
GError * error = NULL;
NULL /* error */
};
- fp = fopen(pathname,"r");
- if(!fp){
+ fd = g_open(pathname, O_RDONLY, 0);
+ if(fd == -1){
g_warning("Can not open file : %s\n", pathname);
return -1;
}
+ iochan = g_io_channel_unix_new(fd);
+
context = g_markup_parse_context_new(&markup_parser, 0, des,NULL);
- while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
- if(!g_markup_parse_context_parse(context, buf, DIR_NAME_SIZE, &error)){
+ //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
+ while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error)
+ != G_IO_STATUS_EOF) {
+
+ if(error != NULL) {
+ g_warning("Can not read xml file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+ if(!g_markup_parse_context_parse(context, buf, length, &error)){
if(error != NULL) {
g_warning("Can not parse xml file: \n%s\n", error->message);
g_error_free(error);
}
g_markup_parse_context_free(context);
- fclose(fp);
+
+ g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
+ if(error != NULL) {
+ g_warning("Can not close file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+
+ close(fd);
return -1;
}
}
g_markup_parse_context_free(context);
- fclose(fp);
+
+ g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
+ if(error != NULL) {
+ g_warning("Can not close file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+
+ g_close(fd);
+
+ g_free(buf);
return 0;
}
*The following functions get facility/tracefile information
****************************************************************************/
-gint getFacilityInfo(LttTrace *t, char* eventdefs)
+gint getFacilityInfo(LttTrace *t, gchar* eventdefs)
{
- DIR * dir;
- struct dirent *entry;
- char * ptr;
+ GDir * dir;
+ const gchar * name;
unsigned int i,j;
LttFacility * f;
LttEventType * et;
- char name[DIR_NAME_SIZE];
+ gchar fullname[DIR_NAME_SIZE];
+ GError * error = NULL;
+
+ dir = g_dir_open(eventdefs, 0, &error);
- dir = opendir(eventdefs);
- if(!dir) {
- g_warning("Can not open directory: %s\n", eventdefs);
+ if(error != NULL) {
+ g_warning("Can not open directory: %s, %s\n", eventdefs, error->message);
+ g_error_free(error);
return -1;
}
- while((entry = readdir(dir)) != NULL){
- ptr = &entry->d_name[strlen(entry->d_name)-4];
- if(strcmp(ptr,".xml") != 0) continue;
- strcpy(name,eventdefs);
- strcat(name,entry->d_name);
- ltt_facility_open(t,name);
- }
- closedir(dir);
+ while((name = g_dir_read_name(dir)) != NULL){
+ if(!g_pattern_match_simple("*.xml", name)) continue;
+ strcpy(fullname,eventdefs);
+ strcat(fullname,name);
+ ltt_facility_open(t,fullname);
+ }
+ g_dir_close(dir);
for(j=0;j<t->facility_number;j++){
f = (LttFacility*)g_ptr_array_index(t->facilities, j);
return 0;
}
-gint getControlFileInfo(LttTrace *t, char* control)
+gint getControlFileInfo(LttTrace *t, gchar* control)
{
- DIR * dir;
- struct dirent *entry;
- char name[DIR_NAME_SIZE];
+ GDir * dir;
+ const gchar *name;
+ gchar fullname[DIR_NAME_SIZE];
+ GError * error = NULL;
+
+ dir = g_dir_open(control, 0, &error);
- dir = opendir(control);
- if(!dir) {
- g_warning("Can not open directory: %s\n", control);
+ if(error != NULL) {
+ g_warning("Can not open directory: %s, %s\n", control, error->message);
+ g_error_free(error);
return -1;
}
- while((entry = readdir(dir)) != NULL){
- if(strcmp(entry->d_name,"facilities") != 0 &&
- strcmp(entry->d_name,"interrupts") != 0 &&
- strcmp(entry->d_name,"processes") != 0) continue;
+ while((name = g_dir_read_name(dir)) != NULL){
+ if(strcmp(name,"facilities") != 0 &&
+ strcmp(name,"interrupts") != 0 &&
+ strcmp(name,"processes") != 0) continue;
- strcpy(name,control);
- strcat(name,entry->d_name);
- if(ltt_tracefile_open_control(t,name))
+ strcpy(fullname,control);
+ strcat(fullname,name);
+ if(ltt_tracefile_open_control(t,fullname)) {
+ g_dir_close(dir);
return -1;
+ }
}
- closedir(dir);
+ g_dir_close(dir);
return 0;
}
gint getCpuFileInfo(LttTrace *t, char* cpu)
{
- DIR * dir;
- struct dirent *entry;
- char name[DIR_NAME_SIZE];
+ GDir * dir;
+ const gchar * name;
+ gchar fullname[DIR_NAME_SIZE];
+ GError * error = NULL;
+
+ dir = g_dir_open(cpu, 0, &error);
- dir = opendir(cpu);
- if(!dir) {
- g_warning("Can not open directory: %s\n", cpu);
+ if(error != NULL) {
+ g_warning("Can not open directory: %s, %s\n", cpu, error->message);
+ g_error_free(error);
return -1;
}
- while((entry = readdir(dir)) != NULL){
- if(strcmp(entry->d_name,".") != 0 &&
- strcmp(entry->d_name,"..") != 0 &&
- strcmp(entry->d_name,".svn") != 0){
- strcpy(name,cpu);
- strcat(name,entry->d_name);
- ltt_tracefile_open_cpu(t,name);
+ while((name = g_dir_read_name(dir)) != NULL){
+ if(strcmp(name,".svn") != 0){ /* . and .. already excluded */
+ strcpy(fullname,cpu);
+ strcat(fullname,name);
+ ltt_tracefile_open_cpu(t,fullname);
}else continue;
}
- closedir(dir);
+ g_dir_close(dir);
return 0;
}
* forgotten cases (.. were not used correctly before).
*
****************************************************************************/
-void get_absolute_pathname(const char *pathname, char * abs_pathname)
+void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname)
{
abs_pathname[0] = '\0';
return;
}
-LttTrace *ltt_trace_open(const char *pathname)
+LttTrace *ltt_trace_open(const gchar *pathname)
{
LttTrace * t;
LttSystemDescription * sys_description;
- char eventdefs[DIR_NAME_SIZE];
- char info[DIR_NAME_SIZE];
- char control[DIR_NAME_SIZE];
- char cpu[DIR_NAME_SIZE];
- char tmp[DIR_NAME_SIZE];
- char abs_path[DIR_NAME_SIZE];
+ gchar eventdefs[DIR_NAME_SIZE];
+ gchar info[DIR_NAME_SIZE];
+ gchar control[DIR_NAME_SIZE];
+ gchar cpu[DIR_NAME_SIZE];
+ gchar tmp[DIR_NAME_SIZE];
+ gchar abs_path[DIR_NAME_SIZE];
gboolean has_slash = FALSE;
get_absolute_pathname(pathname, abs_path);
for(i=0;i<t->control_tracefile_number;i++){
tf = g_ptr_array_index(t->control_tracefiles, i);
readBlock(tf,1);
- startTmp = tf->a_block_start->time;
+ startTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_start->time);
readBlock(tf,tf->block_number);
- endTmp = tf->a_block_end->time;
+ endTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_end->time);
if(i==0){
startSmall = startTmp;
endBig = endTmp;
for(i=0;i<t->per_cpu_tracefile_number;i++){
tf = g_ptr_array_index(t->per_cpu_tracefiles, i);
readBlock(tf,1);
- startTmp = tf->a_block_start->time;
+ startTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_start->time);
readBlock(tf,tf->block_number);
- endTmp = tf->a_block_end->time;
+ endTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_end->time);
if(j == 0 && i==0){
startSmall = startTmp;
endBig = endTmp;
if(err) g_error("Can not read tracefile: %s\n", t->name);
if(start_block == end_block)return;
- tailTime = ltt_time_compare(t->a_block_end->time, time);
+ tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(tailTime >= 0) return;
err=readBlock(t,end_block);
if(err) g_error("Can not read tracefile: %s\n", t->name);
if(start_block+1 == end_block)return;
- headTime = ltt_time_compare(t->a_block_start->time, time);
+ headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
if(headTime <= 0 ) return;
tmp_block = (end_block + start_block)/2;
err=readBlock(t,tmp_block);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- headTime = ltt_time_compare(t->a_block_start->time, time);
- tailTime = ltt_time_compare(t->a_block_end->time, time);
+ headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(headTime <= 0 && tailTime >= 0) return;
if(headTime > 0){
int t_time, h_time, err;
err=readBlock(t,t->which_block-1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- h_time = ltt_time_compare(t->a_block_start->time, time);
- t_time = ltt_time_compare(t->a_block_end->time, time);
+ h_time = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ t_time = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(h_time == 0){
int tmp;
if(t->which_block == 1) return;
err=readBlock(t,t->which_block-1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- tmp = ltt_time_compare(t->a_block_end->time, time);
+ tmp = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(tmp == 0) return ltt_tracefile_seek_time(t, time);
err=readBlock(t,t->which_block+1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
{
int err;
LttTime lttTime;
- int headTime = ltt_time_compare(t->a_block_start->time, time);
- int tailTime = ltt_time_compare(t->a_block_end->time, time);
+ int headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ int tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
LttEvent ev;
if(headTime < 0 && tailTime > 0){
- if(ltt_time_compare(t->a_block_end->time, t->current_event_time) !=0) {
+ if(ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time),
+ t->current_event_time) !=0) {
lttTime = getEventTime(t);
err = ltt_time_compare(lttTime, time);
if(err > 0){
if((guint)whichBlock == tf->which_block) return 0;
if(likely(whichBlock - tf->which_block == 1 && tf->which_block != 0)){
- tf->prev_block_end_time = tf->a_block_end->time;
- tf->prev_event_time = tf->a_block_end->time;
+ tf->prev_block_end_time = ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_end->time);
+ tf->prev_event_time = ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_end->time);
}else{
tf->prev_block_end_time.tv_sec = 0;
tf->prev_block_end_time.tv_nsec = 0;
tf->overflow_nsec =
(-((double)
- (ltt_get_uint32(tf->trace->reverse_byte_order,
+ (ltt_get_uint64(tf->trace->reverse_byte_order,
&tf->a_block_start->cycle_count)&0xFFFFFFFF))
* tf->nsec_per_cycle);
tf->count = 0;
tf->overflow_nsec =
- (-((double)ltt_get_uint32(tf->trace->reverse_byte_order,
+ (-((double)ltt_get_uint64(tf->trace->reverse_byte_order,
&tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */
/* Calculate the total time for this buffer */
- lBufTotalTime = ltt_time_sub(t->a_block_end->time, t->a_block_start->time);
+ lBufTotalTime = ltt_time_sub(
+ ltt_get_time(t->trace->reverse_byte_order, &t->a_block_end->time),
+ ltt_get_time(t->trace->reverse_byte_order, &t->a_block_start->time));
/* Calculate the total cycles for this bufffer */
- lBufTotalCycle = ltt_get_uint32(t->trace->reverse_byte_order,
+ lBufTotalCycle = ltt_get_uint64(t->trace->reverse_byte_order,
&t->a_block_end->cycle_count);
- lBufTotalCycle -= ltt_get_uint32(t->trace->reverse_byte_order,
+ lBufTotalCycle -= ltt_get_uint64(t->trace->reverse_byte_order,
&t->a_block_start->cycle_count);
/* Convert the total time to double */
lEventNSec = 0;
} else if(unlikely(evId == TRACE_BLOCK_END)) {
lEventNSec = ((double)
- (ltt_get_uint32(tf->trace->reverse_byte_order,
+ (ltt_get_uint64(tf->trace->reverse_byte_order,
&tf->a_block_end->cycle_count)
- - ltt_get_uint32(tf->trace->reverse_byte_order,
+ - ltt_get_uint64(tf->trace->reverse_byte_order,
&tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
}
lTimeOffset = ltt_time_from_uint64(lEventNSec);
- time = ltt_time_add(tf->a_block_start->time, lTimeOffset);
+ time = ltt_time_add(ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_start->time), lTimeOffset);
return time;
}