Add type-checked versions of allocation and deallocations functions
[lttng-tools.git] / src / common / index / ctf-index.hpp
CommitLineData
309167d2 1/*
ab5be9fa
MJ
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>
309167d2 5 *
ab5be9fa 6 * SPDX-License-Identifier: MIT
309167d2 7 *
309167d2
JD
8 */
9
10#ifndef LTTNG_INDEX_H
11#define LTTNG_INDEX_H
12
c9e313bc
SM
13#include <common/compat/endian.hpp>
14#include <common/macros.hpp>
71b4cdb4
JG
15
16#include <stdint.h>
309167d2 17#include <limits.h>
71b4cdb4 18#include <stddef.h>
309167d2 19
50adc264
JD
20#define CTF_INDEX_MAGIC 0xC1F1DCC1
21#define CTF_INDEX_MAJOR 1
234cd636 22#define CTF_INDEX_MINOR 1
309167d2
JD
23
24/*
25 * Header at the beginning of each index file.
26 * All integer fields are stored in big endian.
27 */
50adc264
JD
28struct ctf_packet_index_file_hdr {
29 uint32_t magic;
309167d2
JD
30 uint32_t index_major;
31 uint32_t index_minor;
50adc264
JD
32 /* struct packet_index_len, in bytes */
33 uint32_t packet_index_len;
309167d2
JD
34} __attribute__((__packed__));
35
36/*
7591bab1 37 * Packet index generated for each trace packet stored in a trace file.
309167d2
JD
38 * All integer fields are stored in big endian.
39 */
50adc264 40struct ctf_packet_index {
309167d2
JD
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;
234cd636
JD
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 */
309167d2
JD
51} __attribute__((__packed__));
52
f8f3885c
MD
53static 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,
60 stream_id);
61 case 1:
62 return offsetof(struct ctf_packet_index, packet_seq_num)
63 + member_sizeof(struct ctf_packet_index,
64 packet_seq_num);
65 default:
66 abort();
67 }
68 }
69 abort();
70}
71
72static inline uint32_t lttng_to_index_major(uint32_t lttng_major,
5e943e75 73 uint32_t lttng_minor __attribute__((unused)))
f8f3885c
MD
74{
75 if (lttng_major == 2) {
76 return 1;
77 }
78 abort();
79}
80
81static inline uint32_t lttng_to_index_minor(uint32_t lttng_major,
82 uint32_t lttng_minor)
83{
84 if (lttng_major == 2) {
85 if (lttng_minor < 8) {
86 return 0;
87 } else {
88 return 1;
89 }
90 }
91 abort();
92}
93
71b4cdb4
JG
94static inline void ctf_packet_index_file_hdr_init(
95 struct ctf_packet_index_file_hdr *hdr,
96 uint32_t idx_major, uint32_t idx_minor)
97{
98 memset(hdr, 0, sizeof(*hdr));
99 hdr->magic = htobe32(CTF_INDEX_MAGIC);
100 hdr->index_major = htobe32(idx_major);
101 hdr->index_minor = htobe32(idx_minor);
102 hdr->packet_index_len = htobe32(
103 ctf_packet_index_len(idx_major, idx_minor));
104}
105
309167d2 106#endif /* LTTNG_INDEX_H */
This page took 0.080147 seconds and 4 git commands to generate.