fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / src / common / index / ctf-index.hpp
1 /*
2 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
5 *
6 * SPDX-License-Identifier: MIT
7 *
8 */
9
10 #ifndef LTTNG_INDEX_H
11 #define LTTNG_INDEX_H
12
13 #include <common/compat/endian.hpp>
14 #include <common/macros.hpp>
15
16 #include <limits.h>
17 #include <stddef.h>
18 #include <stdint.h>
19
20 #define CTF_INDEX_MAGIC 0xC1F1DCC1
21 #define CTF_INDEX_MAJOR 1
22 #define CTF_INDEX_MINOR 1
23
24 /*
25 * Header at the beginning of each index file.
26 * All integer fields are stored in big endian.
27 */
28 struct ctf_packet_index_file_hdr {
29 uint32_t magic;
30 uint32_t index_major;
31 uint32_t index_minor;
32 /* struct packet_index_len, in bytes */
33 uint32_t packet_index_len;
34 } __attribute__((__packed__));
35
36 /*
37 * Packet index generated for each trace packet stored in a trace file.
38 * All integer fields are stored in big endian.
39 */
40 struct ctf_packet_index {
41 uint64_t offset; /* offset of the packet in the file, in bytes */
42 uint64_t packet_size; /* packet size, in bits */
43 uint64_t content_size; /* content size, in bits */
44 uint64_t timestamp_begin;
45 uint64_t timestamp_end;
46 uint64_t events_discarded;
47 uint64_t stream_id; /* ID of the channel */
48 /* CTF_INDEX 1.0 limit */
49 uint64_t stream_instance_id; /* ID of the channel instance */
50 uint64_t packet_seq_num; /* packet sequence number */
51 } __attribute__((__packed__));
52
53 static inline size_t ctf_packet_index_len(uint32_t major, uint32_t minor)
54 {
55 if (major == 1) {
56 switch (minor) {
57 case 0:
58 return offsetof(struct ctf_packet_index, stream_id) +
59 member_sizeof(struct ctf_packet_index, stream_id);
60 case 1:
61 return offsetof(struct ctf_packet_index, packet_seq_num) +
62 member_sizeof(struct ctf_packet_index, packet_seq_num);
63 default:
64 abort();
65 }
66 }
67 abort();
68 }
69
70 static inline uint32_t lttng_to_index_major(uint32_t lttng_major,
71 uint32_t lttng_minor __attribute__((unused)))
72 {
73 if (lttng_major == 2) {
74 return 1;
75 }
76 abort();
77 }
78
79 static inline uint32_t lttng_to_index_minor(uint32_t lttng_major, uint32_t lttng_minor)
80 {
81 if (lttng_major == 2) {
82 if (lttng_minor < 8) {
83 return 0;
84 } else {
85 return 1;
86 }
87 }
88 abort();
89 }
90
91 static inline void ctf_packet_index_file_hdr_init(struct ctf_packet_index_file_hdr *hdr,
92 uint32_t idx_major,
93 uint32_t idx_minor)
94 {
95 memset(hdr, 0, sizeof(*hdr));
96 hdr->magic = htobe32(CTF_INDEX_MAGIC);
97 hdr->index_major = htobe32(idx_major);
98 hdr->index_minor = htobe32(idx_minor);
99 hdr->packet_index_len = htobe32(ctf_packet_index_len(idx_major, idx_minor));
100 }
101
102 #endif /* LTTNG_INDEX_H */
This page took 0.030725 seconds and 4 git commands to generate.