X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fevent.c;h=a7772d5daf40d10eee243350e5935daba6bd4f7b;hb=2a74fbf4e7e641f94517b3e996c674291248bb1d;hp=8a3174cff8a8e124322dd5ed75b2fa217f10c72f;hpb=a5dcde2f975b43a9c6069c4a346528588bf1f8c8;p=lttv.git diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index 8a3174cf..a7772d5d 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -1,3 +1,21 @@ +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2003-2004 Xiangxiu Yang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + #include #include #include @@ -242,6 +260,80 @@ void ltt_event_position_set(LttEventPosition *ep, ep->event_num = index_in_block; } +/***************************************************************************** + * Function name + * ltt_event_position_compare : compare two positions + * Input params + * ep1 : a pointer to event's position structure + * ep2 : a pointer to event's position structure + * Return + * -1 is ep1 < ep2 + * 1 if ep1 > ep2 + * 0 if ep1 == ep2 + ****************************************************************************/ + + +gint ltt_event_position_compare(const LttEventPosition *ep1, + const LttEventPosition *ep2) +{ + if(ep1->tf != ep2->tf) + g_error("ltt_event_position_compare on different tracefiles makes no sense"); + if(ep1->block_num < ep2->block_num) + return -1; + if(ep1->block_num > ep2->block_num) + return 1; + if(ep1->event_num < ep2->event_num) + return -1; + if(ep1->event_num > ep2->event_num) + return 1; + return 0; +} + +/***************************************************************************** + * Function name + * ltt_event_event_position_compare : compare two positions, one in event, + * other in position opaque structure. + * Input params + * event : a pointer to event structure + * ep : a pointer to event's position structure + * Return + * -1 is event < ep + * 1 if event > ep + * 0 if event == ep + ****************************************************************************/ + +gint ltt_event_event_position_compare(const LttEvent *event, + const LttEventPosition *ep) +{ + g_assert(event->tracefile == ep->tf); + + if(event->which_block < ep->block_num) + return -1; + if(event->which_block > ep->block_num) + return 1; + if(event->which_event < ep->event_num) + return -1; + if(event->which_event > ep->event_num) + return 1; + return 0; +} + +/***************************************************************************** + * Function name + * ltt_event_position_copy : copy position + * Input params + * src : a pointer to event's position structure source + * dest : a pointer to event's position structure dest + * Return + * void + ****************************************************************************/ +void ltt_event_position_copy(LttEventPosition *dest, + const LttEventPosition *src) +{ + *dest = *src; +} + + /***************************************************************************** *Function name * ltt_event_cpu_i: get the cpu id where the event happens @@ -252,8 +344,23 @@ void ltt_event_position_set(LttEventPosition *ep, ****************************************************************************/ unsigned ltt_event_cpu_id(LttEvent *e) -{ - return (unsigned)atoi(e->tracefile->name); +{ + char * c1, * c2, * c3; + c1 = strrchr(e->tracefile->name,'\\'); + c2 = strrchr(e->tracefile->name,'/'); + if(c1 == NULL && c2 == NULL){ + return (unsigned)atoi(e->tracefile->name); + }else if(c1 == NULL){ + c2++; + return (unsigned)atoi(c2); + }else if(c2 == NULL){ + c1++; + return (unsigned)atoi(c1); + }else{ + c3 = (c1 > c2) ? c1 : c2; + c3++; + return (unsigned)atoi(c3); + } } /***************************************************************************** @@ -341,8 +448,7 @@ unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f) e->tracefile->trace->system_description->endian ? 0:1; LttTypeEnum t = f->field_type->type_class; - if(t != LTT_UINT && t != LTT_ENUM) - g_error("The type of the field is not unsigned int\n"); + g_assert(t == LTT_UINT || t == LTT_ENUM); if(f->field_size == 1){ guint8 x = *(guint8 *)(e->data + f->offset_root); @@ -373,8 +479,7 @@ int ltt_event_get_int(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_INT) - g_error("The type of the field is not int\n"); + g_assert(f->field_type->type_class == LTT_INT); if(f->field_size == 1){ gint8 x = *(gint8 *)(e->data + f->offset_root); @@ -406,8 +511,7 @@ unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) e->tracefile->trace->system_description->endian ? 0:1; LttTypeEnum t = f->field_type->type_class; - if(t != LTT_UINT && t != LTT_ENUM) - g_error("The type of the field is not unsigned long\n"); + g_assert(t == LTT_UINT || t == LTT_ENUM); if(f->field_size == 1){ guint8 x = *(guint8 *)(e->data + f->offset_root); @@ -438,8 +542,7 @@ long int ltt_event_get_long_int(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if( f->field_type->type_class != LTT_INT) - g_error("The type of the field is not long int\n"); + g_assert( f->field_type->type_class == LTT_INT); if(f->field_size == 1){ gint8 x = *(gint8 *)(e->data + f->offset_root); @@ -470,9 +573,7 @@ float ltt_event_get_float(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_FLOAT || - (f->field_type->type_class == LTT_FLOAT && f->field_size != 4)) - g_error("The type of the field is not float\n"); + g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 4); if(revFlag == 0) return *(float *)(e->data + f->offset_root); else{ @@ -488,9 +589,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f) int revFlag = e->tracefile->trace->my_arch_endian == e->tracefile->trace->system_description->endian ? 0:1; - if(f->field_type->type_class != LTT_FLOAT || - (f->field_type->type_class == LTT_FLOAT && f->field_size != 8)) - g_error("The type of the field is not double\n"); + g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 8); if(revFlag == 0) return *(double *)(e->data + f->offset_root); else{ @@ -508,7 +607,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f) char *ltt_event_get_string(LttEvent *e, LttField *f) { - if(f->field_type->type_class != LTT_STRING) - g_error("The field contains no string\n"); + g_assert(f->field_type->type_class == LTT_STRING); + return (char*)g_strdup((char*)(e->data + f->offset_root)); }