| 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 <common/compat/endian.h> |
| 29 | #include <common/macros.h> |
| 30 | |
| 31 | #include <stdint.h> |
| 32 | #include <limits.h> |
| 33 | #include <stddef.h> |
| 34 | |
| 35 | #define CTF_INDEX_MAGIC 0xC1F1DCC1 |
| 36 | #define CTF_INDEX_MAJOR 1 |
| 37 | #define CTF_INDEX_MINOR 1 |
| 38 | |
| 39 | /* |
| 40 | * Header at the beginning of each index file. |
| 41 | * All integer fields are stored in big endian. |
| 42 | */ |
| 43 | struct ctf_packet_index_file_hdr { |
| 44 | uint32_t magic; |
| 45 | uint32_t index_major; |
| 46 | uint32_t index_minor; |
| 47 | /* struct packet_index_len, in bytes */ |
| 48 | uint32_t packet_index_len; |
| 49 | } __attribute__((__packed__)); |
| 50 | |
| 51 | /* |
| 52 | * Packet index generated for each trace packet stored in a trace file. |
| 53 | * All integer fields are stored in big endian. |
| 54 | */ |
| 55 | struct ctf_packet_index { |
| 56 | uint64_t offset; /* offset of the packet in the file, in bytes */ |
| 57 | uint64_t packet_size; /* packet size, in bits */ |
| 58 | uint64_t content_size; /* content size, in bits */ |
| 59 | uint64_t timestamp_begin; |
| 60 | uint64_t timestamp_end; |
| 61 | uint64_t events_discarded; |
| 62 | uint64_t stream_id; /* ID of the channel */ |
| 63 | /* CTF_INDEX 1.0 limit */ |
| 64 | uint64_t stream_instance_id; /* ID of the channel instance */ |
| 65 | uint64_t packet_seq_num; /* packet sequence number */ |
| 66 | } __attribute__((__packed__)); |
| 67 | |
| 68 | static inline size_t ctf_packet_index_len(uint32_t major, uint32_t minor) |
| 69 | { |
| 70 | if (major == 1) { |
| 71 | switch (minor) { |
| 72 | case 0: |
| 73 | return offsetof(struct ctf_packet_index, stream_id) |
| 74 | + member_sizeof(struct ctf_packet_index, |
| 75 | stream_id); |
| 76 | case 1: |
| 77 | return offsetof(struct ctf_packet_index, packet_seq_num) |
| 78 | + member_sizeof(struct ctf_packet_index, |
| 79 | packet_seq_num); |
| 80 | default: |
| 81 | abort(); |
| 82 | } |
| 83 | } |
| 84 | abort(); |
| 85 | } |
| 86 | |
| 87 | static inline uint32_t lttng_to_index_major(uint32_t lttng_major, |
| 88 | uint32_t lttng_minor __attribute__((unused))) |
| 89 | { |
| 90 | if (lttng_major == 2) { |
| 91 | return 1; |
| 92 | } |
| 93 | abort(); |
| 94 | } |
| 95 | |
| 96 | static inline uint32_t lttng_to_index_minor(uint32_t lttng_major, |
| 97 | uint32_t lttng_minor) |
| 98 | { |
| 99 | if (lttng_major == 2) { |
| 100 | if (lttng_minor < 8) { |
| 101 | return 0; |
| 102 | } else { |
| 103 | return 1; |
| 104 | } |
| 105 | } |
| 106 | abort(); |
| 107 | } |
| 108 | |
| 109 | static inline void ctf_packet_index_file_hdr_init( |
| 110 | struct ctf_packet_index_file_hdr *hdr, |
| 111 | uint32_t idx_major, uint32_t idx_minor) |
| 112 | { |
| 113 | memset(hdr, 0, sizeof(*hdr)); |
| 114 | hdr->magic = htobe32(CTF_INDEX_MAGIC); |
| 115 | hdr->index_major = htobe32(idx_major); |
| 116 | hdr->index_minor = htobe32(idx_minor); |
| 117 | hdr->packet_index_len = htobe32( |
| 118 | ctf_packet_index_len(idx_major, idx_minor)); |
| 119 | } |
| 120 | |
| 121 | #endif /* LTTNG_INDEX_H */ |