event-rule: introduce event-rule kprobe
[lttng-tools.git] / src / common / index / ctf-index.h
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.h>
14 #include <common/macros.h>
15
16 #include <stdint.h>
17 #include <limits.h>
18 #include <stddef.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,
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
72 static inline uint32_t lttng_to_index_major(uint32_t lttng_major,
73 uint32_t lttng_minor __attribute__((unused)))
74 {
75 if (lttng_major == 2) {
76 return 1;
77 }
78 abort();
79 }
80
81 static 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
94 static 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
106 #endif /* LTTNG_INDEX_H */
This page took 0.033309 seconds and 5 git commands to generate.