Clean-up: run format-cpp on the tree
[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 15
309167d2 16#include <limits.h>
71b4cdb4 17#include <stddef.h>
28f23191 18#include <stdint.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 {
28f23191
JG
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 */
309167d2
JD
44 uint64_t timestamp_begin;
45 uint64_t timestamp_end;
46 uint64_t events_discarded;
28f23191 47 uint64_t stream_id; /* ID of the channel */
234cd636 48 /* CTF_INDEX 1.0 limit */
28f23191
JG
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:
28f23191
JG
58 return offsetof(struct ctf_packet_index, stream_id) +
59 member_sizeof(struct ctf_packet_index, stream_id);
f8f3885c 60 case 1:
28f23191
JG
61 return offsetof(struct ctf_packet_index, packet_seq_num) +
62 member_sizeof(struct ctf_packet_index, packet_seq_num);
f8f3885c
MD
63 default:
64 abort();
65 }
66 }
67 abort();
68}
69
70static inline uint32_t lttng_to_index_major(uint32_t lttng_major,
28f23191 71 uint32_t lttng_minor __attribute__((unused)))
f8f3885c
MD
72{
73 if (lttng_major == 2) {
74 return 1;
75 }
76 abort();
77}
78
28f23191 79static inline uint32_t lttng_to_index_minor(uint32_t lttng_major, uint32_t lttng_minor)
f8f3885c
MD
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
28f23191
JG
91static 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)
71b4cdb4
JG
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);
28f23191 99 hdr->packet_index_len = htobe32(ctf_packet_index_len(idx_major, idx_minor));
71b4cdb4
JG
100}
101
309167d2 102#endif /* LTTNG_INDEX_H */
This page took 0.075781 seconds and 4 git commands to generate.