- /* A trace is not allowed to have a NULL packet header */
- assert(trace->packet_header_type);
- stream->packet_header = bt_ctf_field_create(trace->packet_header_type);
- if (!stream->packet_header) {
- goto error;
- }
- /*
- * Attempt to populate the default trace packet header fields
- * (magic, uuid and stream_id). This will _not_ fail shall the
- * fields not be found or be of an incompatible type; they will
- * simply not be populated automatically. The user will have to
- * make sure to set the trace packet header fields himself before
- * flushing.
- */
- ret = set_packet_header(stream);
- if (ret) {
- goto error;
+ /* Initialize events_discarded */
+ ret = set_structure_field_integer(stream->packet_context,
+ "events_discarded", 0);
+ if (ret) {
+ goto error;
+ }
+
+ stream->events = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) release_event);
+ if (!stream->events) {
+ goto error;
+ }
+
+ /* A trace is not allowed to have a NULL packet header */
+ assert(trace->packet_header_type);
+ stream->packet_header =
+ bt_ctf_field_create(trace->packet_header_type);
+ if (!stream->packet_header) {
+ goto error;
+ }
+
+ /*
+ * Attempt to populate the default trace packet header fields
+ * (magic, uuid and stream_id). This will _not_ fail shall the
+ * fields not be found or be of an incompatible type; they will
+ * simply not be populated automatically. The user will have to
+ * make sure to set the trace packet header fields himself
+ * before flushing.
+ */
+ ret = set_packet_header(stream);
+ if (ret) {
+ goto error;
+ }
+
+ /* Create file associated with this stream */
+ fd = create_stream_file(writer, stream);
+ if (fd < 0) {
+ goto error;
+ }
+
+ ret = set_stream_fd(stream, fd);
+ if (ret) {
+ goto error;
+ }
+
+ /* Freeze the writer */
+ bt_ctf_writer_freeze(writer);
+ } else {
+ /* Non-writer stream indicated by a negative FD */
+ ret = set_stream_fd(stream, -1);
+ if (ret) {
+ goto error;
+ }