| 1 | #include <glib.h> |
| 2 | #include "ltt/ltt.h" |
| 3 | |
| 4 | /* structure definition */ |
| 5 | |
| 6 | typedef struct _trace_header_event { |
| 7 | //information of the machine type |
| 8 | uint32_t arch_type; /* Type of architecture */ |
| 9 | uint32_t arch_variant; /* Variant of the given type of architecture */ |
| 10 | uint32_t system_type; /* Operating system type */ |
| 11 | char system_name[32]; /* system name */ |
| 12 | // uint32_t magic_number; /* Magic number to identify a trace */ |
| 13 | ltt_arch_size arch_size; /* data type size */ |
| 14 | ltt_arch_endian arch_endian; /* endian type : little or big */ |
| 15 | |
| 16 | //format of fields |
| 17 | uint8_t time_size; /* time size */ |
| 18 | uint8_t time_granul; /* time granularity */ |
| 19 | uint8_t id_size; /* size of combined facility/event ids */ |
| 20 | |
| 21 | //other elements |
| 22 | uint32_t ip_addr; /* IP of the machine */ |
| 23 | uint8_t cpu_number; /* number of CPU */ |
| 24 | uint8_t cpu_id; /* cpu id */ |
| 25 | uint8_t cpu_number_used; /* the number of the cpu used in the tracefile */ |
| 26 | uint32_t buffer_size; /* Size of blocks */ |
| 27 | } LTT_PACKED_STRUCT trace_header_event; |
| 28 | |
| 29 | |
| 30 | typedef struct _block_header { |
| 31 | ltt_time time; /* Time stamp of this block */ |
| 32 | ltt_cycle_count cycle_count; /* cycle count of the event */ |
| 33 | uint32_t event_count; /* event count */ |
| 34 | } LTT_PACKED_STRUCT block_header; |
| 35 | |
| 36 | |
| 37 | typedef struct _block_footer { |
| 38 | uint32_t unused_bytes; /* unused bytes at the end of the block */ |
| 39 | ltt_time time; /* Time stamp of this block */ |
| 40 | ltt_cycle_count cycle_count; /* cycle count of the event */ |
| 41 | } LTT_PACKED_STRUCT block_footer; |
| 42 | |
| 43 | |
| 44 | struct _ltt_type{ |
| 45 | char * element_name; //elements name of the struct or type name |
| 46 | char * fmt; |
| 47 | int size; |
| 48 | ltt_type_enum type_class; //which type |
| 49 | char ** enum_strings; //for enum labels |
| 50 | struct _ltt_type ** element_type; //for array, sequence and struct |
| 51 | unsigned element_number; //the number of elements |
| 52 | //for enum, array, sequence and structure |
| 53 | }; |
| 54 | |
| 55 | struct _ltt_eventtype{ |
| 56 | char * name; |
| 57 | char * description; |
| 58 | int index; //id of the event type within the facility |
| 59 | ltt_facility * facility; //the facility that contains the event type |
| 60 | ltt_field * root_field; //root field |
| 61 | int latest_block; //the latest block using the event type |
| 62 | int latest_event; //the latest event using the event type |
| 63 | }; |
| 64 | |
| 65 | struct _ltt_field{ |
| 66 | unsigned field_pos; //field position within its parent |
| 67 | ltt_type * field_type; //field type, if it is root field |
| 68 | //then it must be struct type |
| 69 | |
| 70 | off_t offset_root; //offset from the root, -1:uninitialized |
| 71 | short fixed_root; //offset fixed according to the root |
| 72 | //-1:uninitialized, 0:unfixed, 1:fixed |
| 73 | off_t offset_parent; //offset from the parent,-1:uninitialized |
| 74 | short fixed_parent; //offset fixed according to its parent |
| 75 | //-1:uninitialized, 0:unfixed, 1:fixed |
| 76 | // void * base_address; //base address of the field ???? |
| 77 | |
| 78 | int field_size; //>0: size of the field, |
| 79 | //0 : uncertain |
| 80 | //-1: uninitialize |
| 81 | int element_size; //the element size of the sequence |
| 82 | int field_fixed; //0: field has string or sequence |
| 83 | //1: field has no string or sequenc |
| 84 | //-1: uninitialize |
| 85 | |
| 86 | struct _ltt_field * parent; |
| 87 | struct _ltt_field ** child;//for array, sequence and struct: |
| 88 | //list of fields, it may have only one |
| 89 | //field if the element is not a struct |
| 90 | unsigned current_element; //which element is currently processed |
| 91 | }; |
| 92 | |
| 93 | struct _ltt_event{ |
| 94 | int event_id; |
| 95 | ltt_cycle_count cycle_count; |
| 96 | ltt_tracefile * tracefile; |
| 97 | void * data; //event data |
| 98 | }; |
| 99 | |
| 100 | struct _ltt_facility{ |
| 101 | char * name; //facility name |
| 102 | int event_number; //number of events in the facility |
| 103 | ltt_checksum checksum; //checksum of the facility |
| 104 | ltt_eventtype ** events; //array of event types |
| 105 | unsigned usage_count; //usage count |
| 106 | table all_named_types; //an array of named ltt_type |
| 107 | sequence all_unnamed_types;//an array of unnamed ltt_type |
| 108 | sequence all_fields; //an array of fields |
| 109 | }; |
| 110 | |
| 111 | struct _ltt_tracefile{ |
| 112 | int fd; /* file descriptor */ |
| 113 | off_t file_size; /* file size */ |
| 114 | int block_number; /* number of blocks in the file */ |
| 115 | int which_block; /* which block the current block is */ |
| 116 | int which_event; /* which event of the current block |
| 117 | is currently processed */ |
| 118 | ltt_time current_event_time; /* time of the current event */ |
| 119 | trace_header_event * trace_header; /* the first event in the first block */ |
| 120 | block_header * a_block_header; /* block header of the block*/ |
| 121 | block_footer * a_block_footer; /* block footer of the block*/ |
| 122 | void * first_event_pos; /* the position of the first event */ |
| 123 | void * cur_event_pos; /* the position of the current event */ |
| 124 | void * buffer; /* the buffer containing the block */ |
| 125 | double cycle_per_nsec; /* Cycles per nsec */ |
| 126 | unsigned int cur_heart_beat_number;/* the number of heart beat so far |
| 127 | in the block */ |
| 128 | |
| 129 | ltt_time start_time; /* trace start time */ |
| 130 | ltt_time end_time; /* trace end time */ |
| 131 | ltt_time prev_block_end_time; /* the end time of previous block */ |
| 132 | ltt_time prev_event_time; /* the time of the previous event */ |
| 133 | |
| 134 | int eventtype_number; /* the number of event type |
| 135 | in the tracefile */ |
| 136 | int facility_number; /* the number of the facility in |
| 137 | the tracefile */ |
| 138 | GHashTable * index_facility; /* facility index and facility pair */ |
| 139 | GHashTable * facility_name; /* name and facility pair */ |
| 140 | GHashTable * base_id_name; /* facility name and base id pair*/ |
| 141 | |
| 142 | GPtrArray * eventtype_event_id; /* an array of eventtypes accessed |
| 143 | by event id */ |
| 144 | |
| 145 | ltt_arch_size my_arch_size; /* data type size of the local machine */ |
| 146 | ltt_arch_endian my_arch_endian; /* endian type of the local machine */ |
| 147 | }; |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | /***************************************************************************** |
| 154 | macro for size of some data types |
| 155 | *****************************************************************************/ |
| 156 | #define EVENT_ID_SIZE sizeof(int8_t) |
| 157 | #define CYCLE_COUNT_SIZE sizeof(ltt_cycle_count) |
| 158 | //event id and time delta(cycle count) |
| 159 | //yxx disable during the test |
| 160 | //#define EVENT_HEADER_SIZE (EVENT_ID_SIZE + CYCLE_COUNT_SIZE) |
| 161 | #define EVENT_HEADER_SIZE (EVENT_ID_SIZE + sizeof(uint32_t)) |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | /* obtain the time of an event */ |
| 167 | ltt_time getEventTime(ltt_tracefile * tf); |
| 168 | |
| 169 | /* get the data type size and endian type of the local machine */ |
| 170 | void getDataEndianType(ltt_arch_size * size, ltt_arch_endian * endian); |
| 171 | |
| 172 | |
| 173 | typedef struct _ptr_wrap{ |
| 174 | gpointer ptr; |
| 175 | } ptr_wrap; |
| 176 | |