| 1 | /* |
| 2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> |
| 3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * David Goulet <dgoulet@efficios.com> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #ifndef LTTNG_INDEX_H |
| 26 | #define LTTNG_INDEX_H |
| 27 | |
| 28 | #include <limits.h> |
| 29 | |
| 30 | #define CTF_INDEX_MAGIC 0xC1F1DCC1 |
| 31 | #define CTF_INDEX_MAJOR 1 |
| 32 | #define CTF_INDEX_MINOR 1 |
| 33 | |
| 34 | /* |
| 35 | * Header at the beginning of each index file. |
| 36 | * All integer fields are stored in big endian. |
| 37 | */ |
| 38 | struct ctf_packet_index_file_hdr { |
| 39 | uint32_t magic; |
| 40 | uint32_t index_major; |
| 41 | uint32_t index_minor; |
| 42 | /* struct packet_index_len, in bytes */ |
| 43 | uint32_t packet_index_len; |
| 44 | } __attribute__((__packed__)); |
| 45 | |
| 46 | /* |
| 47 | * Packet index generated for each trace packet stored in a trace file. |
| 48 | * All integer fields are stored in big endian. |
| 49 | */ |
| 50 | struct ctf_packet_index { |
| 51 | uint64_t offset; /* offset of the packet in the file, in bytes */ |
| 52 | uint64_t packet_size; /* packet size, in bits */ |
| 53 | uint64_t content_size; /* content size, in bits */ |
| 54 | uint64_t timestamp_begin; |
| 55 | uint64_t timestamp_end; |
| 56 | uint64_t events_discarded; |
| 57 | uint64_t stream_id; /* ID of the channel */ |
| 58 | /* CTF_INDEX 1.0 limit */ |
| 59 | uint64_t stream_instance_id; /* ID of the channel instance */ |
| 60 | uint64_t packet_seq_num; /* packet sequence number */ |
| 61 | } __attribute__((__packed__)); |
| 62 | |
| 63 | static inline size_t ctf_packet_index_len(uint32_t major, uint32_t minor) |
| 64 | { |
| 65 | if (major == 1) { |
| 66 | switch (minor) { |
| 67 | case 0: |
| 68 | return offsetof(struct ctf_packet_index, stream_id) |
| 69 | + member_sizeof(struct ctf_packet_index, |
| 70 | stream_id); |
| 71 | case 1: |
| 72 | return offsetof(struct ctf_packet_index, packet_seq_num) |
| 73 | + member_sizeof(struct ctf_packet_index, |
| 74 | packet_seq_num); |
| 75 | default: |
| 76 | abort(); |
| 77 | } |
| 78 | } |
| 79 | abort(); |
| 80 | } |
| 81 | |
| 82 | static inline uint32_t lttng_to_index_major(uint32_t lttng_major, |
| 83 | uint32_t lttng_minor __attribute__((unused))) |
| 84 | { |
| 85 | if (lttng_major == 2) { |
| 86 | return 1; |
| 87 | } |
| 88 | abort(); |
| 89 | } |
| 90 | |
| 91 | static inline uint32_t lttng_to_index_minor(uint32_t lttng_major, |
| 92 | uint32_t lttng_minor) |
| 93 | { |
| 94 | if (lttng_major == 2) { |
| 95 | if (lttng_minor < 8) { |
| 96 | return 0; |
| 97 | } else { |
| 98 | return 1; |
| 99 | } |
| 100 | } |
| 101 | abort(); |
| 102 | } |
| 103 | |
| 104 | #endif /* LTTNG_INDEX_H */ |