#include "parser.h"
#include <ltt/event.h>
+/*****************************************************************************
+ *Function name
+ * ltt_event_refresh_fields : refresh fields of an event
+ *Input params
+ * offsetRoot : offset from the root
+ * offsetParent : offset from the parrent
+ * fld : field
+ * evD : event data
+ *Return value
+ * int : size of the field
+ ****************************************************************************/
+
+int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
+ LttField * fld, void *evD)
+{
+ int size, size1, element_number, i, offset1, offset2;
+ LttType * type = fld->field_type;
+
+ if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY &&
+ type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){
+ size = fld->field_size;
+ }else if(type->type_class == LTT_ARRAY){
+ element_number = (int) type->element_number;
+ if(fld->field_fixed == 0){// has string or sequence
+ size = 0;
+ for(i=0;i<element_number;i++){
+ size += ltt_event_refresh_fields(offsetRoot+size,size,
+ fld->child[0], evD+size);
+ }
+ }else size = fld->field_size;
+ }else if(type->type_class == LTT_SEQUENCE){
+ size1 = fld->sequ_number_size;
+ element_number = getIntNumber(size1,evD);
+ type->element_number = element_number;
+ if(fld->element_size > 0){
+ size = element_number * fld->element_size;
+ }else{//sequence has string or sequence
+ size = 0;
+ for(i=0;i<element_number;i++){
+ size += ltt_event_refresh_fields(offsetRoot+size+size1,size+size1,
+ fld->child[0], evD+size+size1);
+ }
+ size += size1;
+ }
+ }else if(type->type_class == LTT_STRING){
+ size = strlen((char*)evD) + 1; //include end : '\0'
+ }else if(type->type_class == LTT_STRUCT){
+ element_number = (int) type->element_number;
+ if(fld->field_fixed == 0){
+ offset1 = offsetRoot;
+ offset2 = 0;
+ for(i=0;i<element_number;i++){
+ size=ltt_event_refresh_fields(offset1,offset2,fld->child[i],evD+offset2);
+ offset1 += size;
+ offset2 += size;
+ }
+ size = offset2;
+ }else size = fld->field_size;
+ }
+
+ fld->offset_root = offsetRoot;
+ fld->offset_parent = offsetParent;
+ fld->fixed_root = (offsetRoot==-1) ? 0 : 1;
+ fld->fixed_parent = (offsetParent==-1) ? 0 : 1;
+ fld->field_size = size;
+
+ return size;
+}
+
/*****************************************************************************
*Function name
* ltt_event_eventtype_id: get event type id
LttField *ltt_event_field(LttEvent *e)
{
+ LttField * field;
LttEventType * event_type = ltt_event_eventtype(e);
if(!event_type) return NULL;
- return event_type->root_field;
+ field = event_type->root_field;
+
+ //check if the field need refresh
+ if(e->which_block != event_type->latest_block ||
+ e->which_event != event_type->latest_event){
+
+ event_type->latest_block = e->which_block;
+ event_type->latest_event = e->which_event;
+
+ if(field->field_fixed == 1)return field;
+
+ //refresh the field
+ ltt_event_refresh_fields(0, 0, field, e->data);
+ }
+ return field;
}
/*****************************************************************************
* to each event. This function returns the number of
* elements for an array or sequence field in an event.
*Input params
- * e : an instance of an event type ????
+ * e : an instance of an event type
* f : a field of the instance
*Return value
* unsigned : the number of elements for an array/sequence field
if(f->field_type->type_class != LTT_ARRAY &&
f->field_type->type_class != LTT_SEQUENCE)
return 0;
-
- return f->field_type->element_number;
+
+ if(f->field_type->type_class == LTT_ARRAY)
+ return f->field_type->element_number;
+ return (unsigned) getIntNumber(f->sequ_number_size, e + f->offset_root);
}
/*****************************************************************************
* : Set the currently selected element for a sequence or
* array field
*Input params
- * e : an instance of an event type ????
+ * e : an instance of an event type
* f : a field of the instance
* i : the ith element
****************************************************************************/
void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i)
{
- if(f->field_type->type_class != LTT_ARRAY &&
+ unsigned element_number;
+ LttField *fld;
+ int k, size;
+ void *evD;
+
+ if(f->field_type->type_class != LTT_ARRAY &&
f->field_type->type_class != LTT_SEQUENCE)
- return ;
-
- if(f->field_type->element_number < i || i == 0) return;
+ return ;
+
+ element_number = ltt_event_field_element_number(e,f);
+ if(element_number < i || i == 0) return;
+
+ fld = f->child[0];
+
+ evD = e->data + f->offset_root;
+ size = 0;
+ for(k=0;k<i;k++){
+ size += ltt_event_refresh_fields(f->offset_root+size,size, fld, evD+size);
+ }
- f->current_element = i - 1;
+ f->current_element = i - 1;
}
/*****************************************************************************
/*****************************************************************************
* The string obtained is only valid until the next read from
- * the same tracefile. ????
+ * the same tracefile.
****************************************************************************/
char *ltt_event_get_string(LttEvent *e, LttField *f)
void freeEventtype(LttEventType * evType);
void freeLttType(LttType ** type);
void freeLttField(LttField * fld);
+void freeLttNamedType(LttType * type);
/*****************************************************************************
void constructTypeAndFields(LttFacility * fac,type_descriptor * td,
LttField * fld)
{
- int i;
+ int i, flag;
type_descriptor * tmpTd;
// if(td->type == LTT_STRING || td->type == LTT_SEQUENCE)
constructTypeAndFields(fac, tmpTd, fld->child[0]);
}else if(td->type == LTT_STRUCT){
fld->field_type->element_number = td->fields.position;
- fld->field_type->element_type = g_new(LttType*, td->fields.position);
+
+ if(fld->field_type->element_type == NULL){
+ fld->field_type->element_type = g_new(LttType*, td->fields.position);
+ flag = 1;
+ }else{
+ flag = 0;
+ }
+
fld->child = g_new(LttField*, td->fields.position);
for(i=0;i<td->fields.position;i++){
tmpTd = ((field*)(td->fields.array[i]))->type;
- fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
+
+ if(flag)
+ fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
fld->child[i] = g_new(LttField,1);
fld->child[i]->field_pos = i;
fld->child[i]->field_type = fld->field_type->element_type[i];
- fld->child[i]->field_type->element_name
- = g_strdup(((field*)(td->fields.array[i]))->name);
+
+ if(flag){
+ fld->child[i]->field_type->element_name
+ = g_strdup(((field*)(td->fields.array[i]))->name);
+ }
+
fld->child[i]->offset_root = -1;
fld->child[i]->fixed_root = -1;
fld->child[i]->offset_parent = -1;
if(td->type_name){
for(i=0;i<fac->named_types_number; i++){
if(fac->named_types[i] == NULL) break;
- name = fac->named_types[i]->element_name;
+ name = fac->named_types[i]->type_name;
if(strcmp(name, td->type_name)==0){
- lttType = fac->named_types[i];
+ lttType = fac->named_types[i];
+ // if(lttType->element_name) g_free(lttType->element_name);
+ // lttType->element_name = NULL;
break;
}
}
lttType->enum_strings = NULL;
lttType->element_type = NULL;
lttType->element_number = 0;
+ lttType->element_name = NULL;
if(td->type_name){
- lttType->element_name = g_strdup(td->type_name);
+ lttType->type_name = g_strdup(td->type_name);
fac->named_types[i] = lttType;
}
else{
- lttType->element_name = NULL;
+ lttType->type_name = NULL;
}
}
g_free(fac->events);
//free all named types
+ for(i=0;i<fac->named_types_number;i++){
+ freeLttNamedType(fac->named_types[i]);
+ fac->named_types[i] = NULL;
+ }
g_free(fac->named_types);
//free the facility itself
void freeEventtype(LttEventType * evType)
{
+ LttType * root_type;
g_free(evType->name);
if(evType->description)
g_free(evType->description);
if(evType->root_field){
+ root_type = evType->root_field->field_type;
freeLttField(evType->root_field);
+ freeLttType(&root_type);
}
g_free(evType);
}
+void freeLttNamedType(LttType * type)
+{
+ int i;
+ g_free(type->type_name);
+ type->type_name = NULL;
+ freeLttType(&type);
+}
+
void freeLttType(LttType ** type)
{
int i;
if(*type == NULL) return;
+ if((*type)->type_name){
+ return; //this is a named type
+ }
if((*type)->element_name)
g_free((*type)->element_name);
if((*type)->fmt)
}
if((*type)->element_type){
- // for(i=0;i<(*type)->element_number;i++)
- // freeLttType(&((*type)->element_type[i]));
+ for(i=0;i<(*type)->element_number;i++)
+ freeLttType(&((*type)->element_type[i]));
g_free((*type)->element_type);
}
g_free(*type);
void freeLttField(LttField * fld)
{
int i;
- int size;
+ int size = 0;
if(fld->field_type){
if(fld->field_type->type_class == LTT_ARRAY ||
}else if(fld->field_type->type_class == LTT_STRUCT){
size = fld->field_type->element_number;
}
- freeLttType(&(fld->field_type));
}
if(fld->child){
t->type_name = allocAndCopy(name);
t->type = NONE;
t->fmt = NULL;
- table_insert(named_types,allocAndCopy(name),t);
+ table_insert(named_types,t->type_name,t);
+ // table_insert(named_types,allocAndCopy(name),t);
}
return t;
}
/* compare two time (LttTime), 0:t1=t2, -1:t1<t2, 1:t1>t2 */
int timecmp(LttTime * t1, LttTime * t2);
-/* get an integer number */
-int getIntNumber(int size1, void *evD);
-
/*****************************************************************************
lttEvent->tracefile = t;
lttEvent->data = t->cur_event_pos + EVENT_HEADER_SIZE;
+ lttEvent->which_block = t->which_block;
+ lttEvent->which_event = t->which_event;
//update the fields of the current event and go to the next event
err = skipEvent(t);
evId = (int)(*(uint16_t *)(t->cur_event_pos));
evData = t->cur_event_pos + EVENT_HEADER_SIZE;
- //regard BLOCK_START, END and HEARTBEAT as special case, there are buildin events
- if(evId != TRACE_BLOCK_START && evId != TRACE_BLOCK_END && evId != TRACE_TIME_HEARTBEAT){
- evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
+ evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
- if(evT) rootFld = evT->root_field;
- else return ERANGE;
+ if(evT) rootFld = evT->root_field;
+ else return ERANGE;
- if(rootFld){
- //event has string/sequence or the last event is not the same event
- if((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
- && rootFld->field_fixed == 0){
- setFieldsOffset(t, evT, evData, t->trace);
- }
- t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
- }else t->cur_event_pos += EVENT_HEADER_SIZE;
-
- evT->latest_block = t->which_block;
- evT->latest_event = t->which_event;
- }else{
- if(evId == TRACE_BLOCK_START || evId == TRACE_BLOCK_END){
- t->cur_event_pos += sizeof(BlockStart) + EVENT_HEADER_SIZE;
- }else{
- t->cur_event_pos += sizeof(TimeHeartbeat) + EVENT_HEADER_SIZE;
+ if(rootFld){
+ //event has string/sequence or the last event is not the same event
+ if((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
+ && rootFld->field_fixed == 0){
+ setFieldsOffset(t, evT, evData, t->trace);
}
- }
-
+ t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
+ }else t->cur_event_pos += EVENT_HEADER_SIZE;
+
+ evT->latest_block = t->which_block;
+ evT->latest_event = t->which_event;
+
//the next event is in the next block
if(evId == TRACE_BLOCK_END){
if(t->which_block == t->block_number){
}else if(type->type_class == LTT_SEQUENCE){
size1 = (int) ltt_type_size(trace, type);
if(fld->field_fixed == -1){
+ fld->sequ_number_size = size1;
fld->field_fixed = 0;
size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
fld->element_size = size;