| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
| 3 | * 2006 Mathieu Desnoyers |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License Version 2.1 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 | * Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #ifndef LTT_PRIVATE_H |
| 21 | #define LTT_PRIVATE_H |
| 22 | |
| 23 | #include <glib.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <ltt/ltt.h> |
| 26 | #include <endian.h> |
| 27 | #include <ltt/event.h> |
| 28 | #include <ltt/marker.h> |
| 29 | #include <ltt/trace.h> |
| 30 | |
| 31 | #ifndef max |
| 32 | #define max(a,b) ((a)>(b)?(a):(b)) |
| 33 | #endif |
| 34 | |
| 35 | #ifndef min |
| 36 | #define min(a,b) ((a)<(b)?(a):(b)) |
| 37 | #endif |
| 38 | |
| 39 | |
| 40 | |
| 41 | #define LTT_MAGIC_NUMBER 0x00D6B7ED |
| 42 | #define LTT_REV_MAGIC_NUMBER 0xEDB7D600 |
| 43 | |
| 44 | #define NSEC_PER_USEC 1000 |
| 45 | |
| 46 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
| 47 | |
| 48 | /* Hardcoded facilities */ |
| 49 | #define LTT_FACILITY_CORE 0 |
| 50 | |
| 51 | /* Byte ordering */ |
| 52 | #define LTT_GET_BO(t) ((t)->reverse_bo) |
| 53 | |
| 54 | #define LTT_HAS_FLOAT(t) ((t)->float_word_order!=0) |
| 55 | #define LTT_GET_FLOAT_BO(t) \ |
| 56 | (((t)->float_word_order==__BYTE_ORDER)?0:1) |
| 57 | |
| 58 | #define SEQUENCE_AVG_ELEMENTS 1000 |
| 59 | |
| 60 | /* Hardcoded core events */ |
| 61 | enum ltt_core_events { |
| 62 | LTT_EVENT_FACILITY_LOAD, |
| 63 | LTT_EVENT_FACILITY_UNLOAD, |
| 64 | LTT_EVENT_HEARTBEAT, |
| 65 | LTT_EVENT_HEARTBEAT_FULL, |
| 66 | LTT_EVENT_STATE_DUMP_FACILITY_LOAD |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | #if 0 |
| 71 | /* enumeration definition */ |
| 72 | |
| 73 | typedef enum _BuildinEvent{ |
| 74 | TRACE_FACILITY_LOAD = 0, |
| 75 | TRACE_BLOCK_START = 17, |
| 76 | TRACE_BLOCK_END = 18, |
| 77 | TRACE_TIME_HEARTBEAT= 19 |
| 78 | } BuildinEvent; |
| 79 | |
| 80 | |
| 81 | /* structure definition */ |
| 82 | |
| 83 | typedef struct _FacilityLoad{ |
| 84 | gchar * name; |
| 85 | LttChecksum checksum; |
| 86 | guint32 base_code; |
| 87 | } LTT_PACKED_STRUCT FacilityLoad; |
| 88 | |
| 89 | typedef struct _BlockStart { |
| 90 | LttTime time; //Time stamp of this block |
| 91 | LttCycleCount cycle_count; //cycle count of the event |
| 92 | guint32 block_id; //block id |
| 93 | } LTT_PACKED_STRUCT BlockStart; |
| 94 | |
| 95 | typedef struct _BlockEnd { |
| 96 | LttTime time; //Time stamp of this block |
| 97 | LttCycleCount cycle_count; //cycle count of the event |
| 98 | guint32 block_id; //block id |
| 99 | } LTT_PACKED_STRUCT BlockEnd; |
| 100 | #endif //0 |
| 101 | |
| 102 | |
| 103 | typedef guint8 uint8_t; |
| 104 | typedef guint16 uint16_t; |
| 105 | typedef guint32 uint32_t; |
| 106 | typedef guint64 uint64_t; |
| 107 | |
| 108 | struct ltt_event_header_hb { |
| 109 | uint32_t timestamp; |
| 110 | uint16_t event_id; |
| 111 | uint16_t event_size; |
| 112 | } LTT_PACKED_STRUCT; |
| 113 | |
| 114 | struct ltt_event_header_nohb { |
| 115 | uint64_t timestamp; |
| 116 | uint16_t event_id; |
| 117 | uint16_t event_size; |
| 118 | } LTT_PACKED_STRUCT; |
| 119 | |
| 120 | |
| 121 | /* Block and trace headers */ |
| 122 | |
| 123 | struct ltt_trace_header_any { |
| 124 | uint32_t magic_number; |
| 125 | uint32_t arch_type; |
| 126 | uint32_t arch_variant; |
| 127 | uint32_t float_word_order; |
| 128 | uint8_t arch_size; |
| 129 | uint8_t major_version; |
| 130 | uint8_t minor_version; |
| 131 | uint8_t flight_recorder; |
| 132 | uint8_t has_heartbeat; |
| 133 | uint8_t alignment; /* Event header alignment */ |
| 134 | uint32_t freq_scale; |
| 135 | } LTT_PACKED_STRUCT; |
| 136 | |
| 137 | struct ltt_trace_header_1_0 { |
| 138 | uint32_t magic_number; |
| 139 | uint32_t arch_type; |
| 140 | uint32_t arch_variant; |
| 141 | uint32_t float_word_order; |
| 142 | uint8_t arch_size; |
| 143 | uint8_t major_version; |
| 144 | uint8_t minor_version; |
| 145 | uint8_t flight_recorder; |
| 146 | uint8_t has_heartbeat; |
| 147 | uint8_t alignment; /* Event header alignment */ |
| 148 | uint8_t tsc_lsb_truncate; |
| 149 | uint8_t tscbits; |
| 150 | uint32_t freq_scale; |
| 151 | uint64_t start_freq; |
| 152 | uint64_t start_tsc; |
| 153 | uint64_t start_monotonic; |
| 154 | uint64_t start_time_sec; |
| 155 | uint64_t start_time_usec; |
| 156 | } LTT_PACKED_STRUCT; |
| 157 | |
| 158 | |
| 159 | struct ltt_block_start_header { |
| 160 | struct { |
| 161 | uint64_t cycle_count; |
| 162 | uint64_t freq; |
| 163 | } begin; |
| 164 | struct { |
| 165 | uint64_t cycle_count; |
| 166 | uint64_t freq; |
| 167 | } end; |
| 168 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
| 169 | uint32_t buf_size; /* The size of this sub-buffer */ |
| 170 | struct ltt_trace_header_any trace[0]; |
| 171 | } LTT_PACKED_STRUCT; |
| 172 | |
| 173 | |
| 174 | #if 0 |
| 175 | struct _LttType{ |
| 176 | // LTTV does not care about type names. Everything is a field. |
| 177 | // GQuark type_name; //type name if it is a named type |
| 178 | gchar * fmt; |
| 179 | guint size; |
| 180 | LttTypeEnum type_class; //which type |
| 181 | GHashTable *enum_map; //maps enum labels to numbers. |
| 182 | gint32 highest_value; //For enum |
| 183 | gint32 lowest_value; //For enum |
| 184 | GArray *fields; // Array of LttFields, for array, sequence, union, struct. |
| 185 | GData *fields_by_name; |
| 186 | guint network; // Is the type in network byte order ? |
| 187 | //part added by gaby for fmt: |
| 188 | char *header; |
| 189 | char *separator; |
| 190 | char *footer; |
| 191 | }; |
| 192 | #endif //0 |
| 193 | |
| 194 | #if 0 |
| 195 | struct _LttEventType{ |
| 196 | GQuark name; |
| 197 | gchar * description; |
| 198 | guint index; //id of the event type within the facility |
| 199 | struct marker_info *info; |
| 200 | GArray * fields; //event's fields (LttField) |
| 201 | GData *fields_by_name; |
| 202 | int has_compact_data; //event header contains compact data (first field) |
| 203 | }; |
| 204 | #endif //0 |
| 205 | |
| 206 | enum field_status { FIELD_UNKNOWN, FIELD_VARIABLE, FIELD_FIXED }; |
| 207 | |
| 208 | #if 0 |
| 209 | struct _LttField{ |
| 210 | GQuark name; |
| 211 | gchar *description; |
| 212 | LttType field_type; //field type |
| 213 | |
| 214 | off_t offset_root; //offset from the root |
| 215 | enum field_status fixed_root; //offset fixed according to the root |
| 216 | |
| 217 | guint field_size; // size of the field |
| 218 | // Only if field type size is set to 0 |
| 219 | // (it's variable), then the field_size should be |
| 220 | // dynamically calculated while reading the trace |
| 221 | // and put here. Otherwise, the field_size always |
| 222 | // equals the type size. |
| 223 | off_t array_offset; // offset of the beginning of the array (for array |
| 224 | // and sequences) |
| 225 | GArray * dynamic_offsets; // array of offsets calculated dynamically at |
| 226 | // each event for sequences and arrays that |
| 227 | // contain variable length fields. |
| 228 | }; |
| 229 | #endif //0 |
| 230 | #if 0 |
| 231 | struct _LttFacility{ |
| 232 | LttTrace *trace; |
| 233 | GQuark name; |
| 234 | guint32 checksum; //checksum of the facility |
| 235 | guint32 id; //id of the facility |
| 236 | |
| 237 | guint32 int_size; |
| 238 | guint32 long_size; |
| 239 | guint32 pointer_size; |
| 240 | guint32 size_t_size; |
| 241 | guint32 alignment; |
| 242 | |
| 243 | GArray *events; |
| 244 | GData *events_by_name; |
| 245 | // not necessary in LTTV GData *named_types; |
| 246 | |
| 247 | unsigned char exists; /* 0 does not exist, 1 exists */ |
| 248 | }; |
| 249 | #endif //0 |
| 250 | |
| 251 | typedef struct _LttBuffer { |
| 252 | void * head; |
| 253 | unsigned int index; |
| 254 | |
| 255 | struct { |
| 256 | LttTime timestamp; |
| 257 | uint64_t cycle_count; |
| 258 | uint64_t freq; /* Frequency in khz */ |
| 259 | } begin; |
| 260 | struct { |
| 261 | LttTime timestamp; |
| 262 | uint64_t cycle_count; |
| 263 | uint64_t freq; /* Frequency in khz */ |
| 264 | } end; |
| 265 | uint32_t lost_size; /* Size unused at the end of the buffer */ |
| 266 | |
| 267 | /* Timekeeping */ |
| 268 | uint64_t tsc; /* Current timestamp counter */ |
| 269 | uint64_t freq; /* Frequency in khz */ |
| 270 | //double nsecs_per_cycle; /* Precalculated from freq */ |
| 271 | guint32 cyc2ns_scale; |
| 272 | } LttBuffer; |
| 273 | |
| 274 | struct LttTracefile { |
| 275 | gboolean cpu_online; //is the cpu online ? |
| 276 | GQuark long_name; //tracefile complete filename |
| 277 | GQuark name; //tracefile name |
| 278 | guint cpu_num; //cpu number of the tracefile |
| 279 | guint tid; //Usertrace tid, else 0 |
| 280 | guint pgid; //Usertrace pgid, else 0 |
| 281 | guint64 creation; //Usertrace creation, else 0 |
| 282 | LttTrace * trace; //trace containing the tracefile |
| 283 | int fd; //file descriptor |
| 284 | off_t file_size; //file size |
| 285 | //unsigned block_size; //block_size |
| 286 | guint num_blocks; //number of blocks in the file |
| 287 | gboolean reverse_bo; //must we reverse byte order ? |
| 288 | gboolean float_word_order; //what is the byte order of floats ? |
| 289 | size_t alignment; //alignment of events in the tracefile. |
| 290 | // 0 or the architecture size in bytes. |
| 291 | |
| 292 | guint8 has_heartbeat; |
| 293 | size_t buffer_header_size; |
| 294 | int compact; //compact tracefile ? |
| 295 | uint8_t tsc_lsb_truncate; |
| 296 | uint8_t tscbits; |
| 297 | uint8_t tsc_msb_cutoff; |
| 298 | uint64_t tsc_mask; |
| 299 | uint64_t tsc_mask_next_bit; //next MSB after the mask |
| 300 | |
| 301 | /* Current event */ |
| 302 | LttEvent event; //Event currently accessible in the trace |
| 303 | |
| 304 | /* Current block */ |
| 305 | LttBuffer buffer; //current buffer |
| 306 | guint32 buf_size; /* The size of blocks */ |
| 307 | |
| 308 | /* Time flow */ |
| 309 | //unsigned int count; //the number of overflow of cycle count |
| 310 | //double nsec_per_cycle; //Nsec per cycle |
| 311 | //TimeHeartbeat * last_heartbeat; //last heartbeat |
| 312 | |
| 313 | //LttCycleCount cycles_per_nsec_reciprocal; // Optimisation for speed |
| 314 | //void * last_event_pos; |
| 315 | |
| 316 | //LttTime prev_block_end_time; //the end time of previous block |
| 317 | //LttTime prev_event_time; //the time of the previous event |
| 318 | //LttCycleCount pre_cycle_count; //previous cycle count of the event |
| 319 | }; |
| 320 | |
| 321 | /* The characteristics of the system on which the trace was obtained |
| 322 | is described in a LttSystemDescription structure. */ |
| 323 | |
| 324 | struct LttSystemDescription { |
| 325 | gchar *description; |
| 326 | gchar *node_name; |
| 327 | gchar *domain_name; |
| 328 | unsigned nb_cpu; |
| 329 | LttArchSize size; |
| 330 | LttArchEndian endian; |
| 331 | gchar *kernel_name; |
| 332 | gchar *kernel_release; |
| 333 | gchar *kernel_version; |
| 334 | gchar *machine; |
| 335 | gchar *processor; |
| 336 | gchar *hardware_platform; |
| 337 | gchar *operating_system; |
| 338 | LttTime trace_start; |
| 339 | LttTime trace_end; |
| 340 | }; |
| 341 | |
| 342 | /***************************************************************************** |
| 343 | macro for size of some data types |
| 344 | *****************************************************************************/ |
| 345 | // alignment -> dynamic! |
| 346 | |
| 347 | //#define TIMESTAMP_SIZE sizeof(guint32) |
| 348 | //#define EVENT_ID_SIZE sizeof(guint16) |
| 349 | //#define EVENT_HEADER_SIZE (TIMESTAMP_SIZE + EVENT_ID_SIZE) |
| 350 | |
| 351 | |
| 352 | //off_t get_alignment(LttField *field); |
| 353 | |
| 354 | /* Calculate the offset needed to align the type. |
| 355 | * If alignment is 0, alignment is disactivated. |
| 356 | * else, the function returns the offset needed to |
| 357 | * align align_drift on the alignment value (should be |
| 358 | * the size of the architecture). */ |
| 359 | static inline unsigned int ltt_align(size_t align_drift, |
| 360 | size_t size_of_type, |
| 361 | size_t alignment) |
| 362 | { |
| 363 | size_t align_offset = min(alignment, size_of_type); |
| 364 | |
| 365 | if(!alignment) |
| 366 | return 0; |
| 367 | |
| 368 | g_assert(size_of_type != 0); |
| 369 | return ((align_offset - align_drift) & (align_offset-1)); |
| 370 | } |
| 371 | |
| 372 | |
| 373 | #endif /* LTT_PRIVATE_H */ |