2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef LTTNG_CONSUMER_STREAM_H
9 #define LTTNG_CONSUMER_STREAM_H
11 #include "consumer.hpp"
13 enum consumer_stream_open_packet_status {
14 CONSUMER_STREAM_OPEN_PACKET_STATUS_OPENED,
15 CONSUMER_STREAM_OPEN_PACKET_STATUS_NO_SPACE,
16 CONSUMER_STREAM_OPEN_PACKET_STATUS_ERROR,
20 * Create a consumer stream.
22 * The channel lock MUST be acquired.
24 struct lttng_consumer_stream *consumer_stream_create(
25 struct lttng_consumer_channel *channel,
28 const char *channel_name,
31 struct lttng_trace_chunk *trace_chunk,
34 enum consumer_channel_type type,
35 unsigned int monitor);
38 * Close stream's file descriptors and, if needed, close stream also on the
41 * The stream lock MUST be acquired.
42 * The consumer data lock MUST be acquired.
44 void consumer_stream_close(struct lttng_consumer_stream *stream);
47 * Close stream on the relayd side. This call can destroy a relayd if the
50 * A RCU read side lock MUST be acquired if the relayd object was looked up in
51 * a hash table before calling this.
53 void consumer_stream_relayd_close(struct lttng_consumer_stream *stream,
54 struct consumer_relayd_sock_pair *relayd);
57 * Delete the stream from all possible hash tables.
59 * The consumer data lock MUST be acquired.
61 void consumer_stream_delete(struct lttng_consumer_stream *stream,
65 * Free the given stream within a RCU call.
67 void consumer_stream_free(struct lttng_consumer_stream *stream);
70 * Destroy a stream completely. This will delete, close and free the stream.
71 * Once return, the stream is NO longer usable. Its channel may get destroyed
72 * if conditions are met.
74 * This MUST be called WITHOUT the consumer data and stream lock acquired.
76 void consumer_stream_destroy(struct lttng_consumer_stream *stream,
80 * Destroy the stream's buffers on the tracer side. This is also called in a
83 void consumer_stream_destroy_buffers(struct lttng_consumer_stream *stream);
86 * Write index of a specific stream either on the relayd or local disk.
88 int consumer_stream_write_index(struct lttng_consumer_stream *stream,
89 struct ctf_packet_index *index);
91 int consumer_stream_sync_metadata(struct lttng_consumer_local_data *ctx,
95 * Create the output files of a local stream.
97 * This must be called with the channel's and the stream's lock held.
99 int consumer_stream_create_output_files(struct lttng_consumer_stream *stream,
103 * Rotate the output files of a local stream. This will change the
104 * active output files of both the binary and index in accordance
105 * with the stream's configuration (stream file count).
107 * This must be called with the channel's and the stream's lock held.
109 int consumer_stream_rotate_output_files(struct lttng_consumer_stream *stream);
112 * Indicates whether or not a stream is logically deleted. A deleted stream
113 * should no longer be used; its existence is only garanteed by the RCU lock
114 * held by the caller.
116 * This function must be called with the RCU read side lock held.
118 bool consumer_stream_is_deleted(struct lttng_consumer_stream *stream);
121 * Enable metadata bucketization. This must only be enabled if the tracer
122 * provides a reliable metadata `coherent` flag.
124 * This must be called on initialization before any subbuffer is consumed.
126 int consumer_stream_enable_metadata_bucketization(
127 struct lttng_consumer_stream *stream);
130 * Set the version of a metadata stream (i.e. following a metadata
133 * Changing the version of a metadata stream will cause any bucketized metadata
134 * to be discarded and will mark the metadata stream for future `reset`.
136 void consumer_stream_metadata_set_version(
137 struct lttng_consumer_stream *stream, uint64_t new_version);
140 * Attempt to open a packet in a stream.
142 * This function must be called with the stream and channel locks held.
144 enum consumer_stream_open_packet_status consumer_stream_open_packet(
145 struct lttng_consumer_stream *stream);
148 * Flush a stream's buffer.
150 * producer_active: if true, causes a flush to occur only if there is
151 * content present in the current sub-buffer. If false, forces a flush to take
152 * place (otherwise known as "flush_empty").
154 * This function must be called with the stream and channel locks held.
156 int consumer_stream_flush_buffer(struct lttng_consumer_stream *stream,
157 bool producer_active);
159 #endif /* LTTNG_CONSUMER_STREAM_H */