| 1 | /* |
| 2 | * iterator.c |
| 3 | * |
| 4 | * Babeltrace Library |
| 5 | * |
| 6 | * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation |
| 7 | * |
| 8 | * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | * of this software and associated documentation files (the "Software"), to deal |
| 12 | * in the Software without restriction, including without limitation the rights |
| 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | * copies of the Software, and to permit persons to whom the Software is |
| 15 | * furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included in |
| 18 | * all copies or substantial portions of the Software. |
| 19 | */ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <babeltrace/babeltrace.h> |
| 23 | #include <babeltrace/context.h> |
| 24 | #include <babeltrace/context-internal.h> |
| 25 | #include <babeltrace/iterator-internal.h> |
| 26 | #include <babeltrace/iterator.h> |
| 27 | #include <babeltrace/prio_heap.h> |
| 28 | #include <babeltrace/ctf/metadata.h> |
| 29 | #include <babeltrace/ctf/events.h> |
| 30 | #include <inttypes.h> |
| 31 | |
| 32 | static int babeltrace_filestream_seek(struct ctf_file_stream *file_stream, |
| 33 | const struct bt_iter_pos *begin_pos, |
| 34 | unsigned long stream_id); |
| 35 | |
| 36 | struct stream_saved_pos { |
| 37 | /* |
| 38 | * Use file_stream pointer to check if the trace collection we |
| 39 | * restore to match the one we saved from, for each stream. |
| 40 | */ |
| 41 | struct ctf_file_stream *file_stream; |
| 42 | size_t cur_index; /* current index in packet index */ |
| 43 | ssize_t offset; /* offset from base, in bits. EOF for end of file. */ |
| 44 | uint64_t current_timestamp; |
| 45 | }; |
| 46 | |
| 47 | struct bt_saved_pos { |
| 48 | struct trace_collection *tc; |
| 49 | GArray *stream_saved_pos; /* Contains struct stream_saved_pos */ |
| 50 | }; |
| 51 | |
| 52 | static int stream_read_event(struct ctf_file_stream *sin) |
| 53 | { |
| 54 | int ret; |
| 55 | |
| 56 | ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->parent); |
| 57 | if (ret == EOF) |
| 58 | return EOF; |
| 59 | else if (ret) { |
| 60 | fprintf(stderr, "[error] Reading event failed.\n"); |
| 61 | return ret; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * returns true if a < b, false otherwise. |
| 68 | */ |
| 69 | int stream_compare(void *a, void *b) |
| 70 | { |
| 71 | struct ctf_file_stream *s_a = a, *s_b = b; |
| 72 | |
| 73 | if (s_a->parent.timestamp < s_b->parent.timestamp) |
| 74 | return 1; |
| 75 | else |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | void bt_iter_free_pos(struct bt_iter_pos *iter_pos) |
| 80 | { |
| 81 | if (!iter_pos) |
| 82 | return; |
| 83 | |
| 84 | if (iter_pos->u.restore) { |
| 85 | if (iter_pos->u.restore->stream_saved_pos) { |
| 86 | g_array_free( |
| 87 | iter_pos->u.restore->stream_saved_pos, |
| 88 | TRUE); |
| 89 | } |
| 90 | g_free(iter_pos->u.restore); |
| 91 | } |
| 92 | g_free(iter_pos); |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * seek_file_stream_by_timestamp |
| 97 | * |
| 98 | * Browse a filestream by index, if an index contains the timestamp passed in |
| 99 | * argument, seek inside the corresponding packet it until we find the event we |
| 100 | * are looking for (either the exact timestamp or the event just after the |
| 101 | * timestamp). |
| 102 | * |
| 103 | * Return 0 if the seek succeded and EOF if we didn't find any packet |
| 104 | * containing the timestamp. |
| 105 | */ |
| 106 | static int seek_file_stream_by_timestamp(struct ctf_file_stream *cfs, |
| 107 | uint64_t timestamp) |
| 108 | { |
| 109 | struct ctf_stream_pos *stream_pos; |
| 110 | struct packet_index *index; |
| 111 | int i, ret; |
| 112 | |
| 113 | stream_pos = &cfs->pos; |
| 114 | for (i = 0; i < stream_pos->packet_index->len; i++) { |
| 115 | index = &g_array_index(stream_pos->packet_index, |
| 116 | struct packet_index, i); |
| 117 | if (index->timestamp_end <= timestamp) |
| 118 | continue; |
| 119 | |
| 120 | stream_pos->packet_seek(&stream_pos->parent, i, SEEK_SET); |
| 121 | while (cfs->parent.timestamp < timestamp) { |
| 122 | ret = stream_read_event(cfs); |
| 123 | if (ret < 0) |
| 124 | break; |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | return EOF; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * seek_ctf_trace_by_timestamp : for each file stream, seek to the event with |
| 133 | * the corresponding timestamp |
| 134 | * |
| 135 | * Return 0 on success. |
| 136 | * If the timestamp is not part of any file stream, return EOF to inform the |
| 137 | * user the timestamp is out of the scope |
| 138 | */ |
| 139 | static int seek_ctf_trace_by_timestamp(struct ctf_trace *tin, |
| 140 | uint64_t timestamp, struct ptr_heap *stream_heap) |
| 141 | { |
| 142 | int i, j, ret; |
| 143 | int found = EOF; |
| 144 | |
| 145 | /* for each stream_class */ |
| 146 | for (i = 0; i < tin->streams->len; i++) { |
| 147 | struct ctf_stream_class *stream_class; |
| 148 | |
| 149 | stream_class = g_ptr_array_index(tin->streams, i); |
| 150 | /* for each file_stream */ |
| 151 | for (j = 0; j < stream_class->streams->len; j++) { |
| 152 | struct ctf_stream *stream; |
| 153 | struct ctf_file_stream *cfs; |
| 154 | |
| 155 | stream = g_ptr_array_index(stream_class->streams, j); |
| 156 | cfs = container_of(stream, struct ctf_file_stream, |
| 157 | parent); |
| 158 | ret = seek_file_stream_by_timestamp(cfs, timestamp); |
| 159 | if (ret == 0) { |
| 160 | /* Add to heap */ |
| 161 | ret = heap_insert(stream_heap, cfs); |
| 162 | if (ret) |
| 163 | goto error; |
| 164 | found = 0; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return found; |
| 170 | |
| 171 | error: |
| 172 | return -2; |
| 173 | } |
| 174 | |
| 175 | int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) |
| 176 | { |
| 177 | struct trace_collection *tc; |
| 178 | int i, ret; |
| 179 | |
| 180 | switch (iter_pos->type) { |
| 181 | case BT_SEEK_RESTORE: |
| 182 | if (!iter_pos->u.restore) |
| 183 | return -EINVAL; |
| 184 | |
| 185 | heap_free(iter->stream_heap); |
| 186 | ret = heap_init(iter->stream_heap, 0, stream_compare); |
| 187 | if (ret < 0) |
| 188 | goto error; |
| 189 | |
| 190 | for (i = 0; i < iter_pos->u.restore->stream_saved_pos->len; |
| 191 | i++) { |
| 192 | struct stream_saved_pos *saved_pos; |
| 193 | struct ctf_stream_pos *stream_pos; |
| 194 | struct ctf_stream *stream; |
| 195 | |
| 196 | saved_pos = &g_array_index( |
| 197 | iter_pos->u.restore->stream_saved_pos, |
| 198 | struct stream_saved_pos, i); |
| 199 | stream = &saved_pos->file_stream->parent; |
| 200 | stream_pos = &saved_pos->file_stream->pos; |
| 201 | |
| 202 | stream_pos->packet_seek(&stream_pos->parent, |
| 203 | saved_pos->cur_index, SEEK_SET); |
| 204 | |
| 205 | /* |
| 206 | * the timestamp needs to be restored after |
| 207 | * packet_seek, because this function resets |
| 208 | * the timestamp to the beginning of the packet |
| 209 | */ |
| 210 | stream->timestamp = saved_pos->current_timestamp; |
| 211 | stream_pos->offset = saved_pos->offset; |
| 212 | stream_pos->last_offset = saved_pos->offset; |
| 213 | |
| 214 | stream->prev_timestamp = 0; |
| 215 | stream->prev_timestamp_end = 0; |
| 216 | stream->consumed = 0; |
| 217 | |
| 218 | printf_debug("restored to cur_index = %zd and " |
| 219 | "offset = %zd, timestamp = %" PRIu64 "\n", |
| 220 | stream_pos->cur_index, |
| 221 | stream_pos->offset, stream->timestamp); |
| 222 | |
| 223 | stream_read_event(saved_pos->file_stream); |
| 224 | |
| 225 | /* Add to heap */ |
| 226 | ret = heap_insert(iter->stream_heap, |
| 227 | saved_pos->file_stream); |
| 228 | if (ret) |
| 229 | goto error; |
| 230 | } |
| 231 | case BT_SEEK_TIME: |
| 232 | tc = iter->ctx->tc; |
| 233 | |
| 234 | heap_free(iter->stream_heap); |
| 235 | ret = heap_init(iter->stream_heap, 0, stream_compare); |
| 236 | if (ret < 0) |
| 237 | goto error; |
| 238 | |
| 239 | /* for each trace in the trace_collection */ |
| 240 | for (i = 0; i < tc->array->len; i++) { |
| 241 | struct ctf_trace *tin; |
| 242 | struct trace_descriptor *td_read; |
| 243 | |
| 244 | td_read = g_ptr_array_index(tc->array, i); |
| 245 | tin = container_of(td_read, struct ctf_trace, parent); |
| 246 | |
| 247 | ret = seek_ctf_trace_by_timestamp(tin, |
| 248 | iter_pos->u.seek_time, |
| 249 | iter->stream_heap); |
| 250 | if (ret < 0) |
| 251 | goto error; |
| 252 | } |
| 253 | return 0; |
| 254 | case BT_SEEK_BEGIN: |
| 255 | tc = iter->ctx->tc; |
| 256 | for (i = 0; i < tc->array->len; i++) { |
| 257 | struct ctf_trace *tin; |
| 258 | struct trace_descriptor *td_read; |
| 259 | int stream_id; |
| 260 | |
| 261 | td_read = g_ptr_array_index(tc->array, i); |
| 262 | tin = container_of(td_read, struct ctf_trace, parent); |
| 263 | |
| 264 | /* Populate heap with each stream */ |
| 265 | for (stream_id = 0; stream_id < tin->streams->len; |
| 266 | stream_id++) { |
| 267 | struct ctf_stream_class *stream; |
| 268 | int filenr; |
| 269 | |
| 270 | stream = g_ptr_array_index(tin->streams, |
| 271 | stream_id); |
| 272 | if (!stream) |
| 273 | continue; |
| 274 | for (filenr = 0; filenr < stream->streams->len; |
| 275 | filenr++) { |
| 276 | struct ctf_file_stream *file_stream; |
| 277 | file_stream = g_ptr_array_index( |
| 278 | stream->streams, |
| 279 | filenr); |
| 280 | ret = babeltrace_filestream_seek( |
| 281 | file_stream, iter_pos, |
| 282 | stream_id); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | break; |
| 287 | default: |
| 288 | /* not implemented */ |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | |
| 294 | error: |
| 295 | heap_free(iter->stream_heap); |
| 296 | if (heap_init(iter->stream_heap, 0, stream_compare) < 0) { |
| 297 | heap_free(iter->stream_heap); |
| 298 | g_free(iter->stream_heap); |
| 299 | iter->stream_heap = NULL; |
| 300 | ret = -ENOMEM; |
| 301 | } |
| 302 | return ret; |
| 303 | } |
| 304 | |
| 305 | struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter) |
| 306 | { |
| 307 | struct bt_iter_pos *pos; |
| 308 | struct trace_collection *tc = iter->ctx->tc; |
| 309 | int i, stream_class_id, stream_id; |
| 310 | |
| 311 | pos = g_new0(struct bt_iter_pos, 1); |
| 312 | pos->u.restore = g_new0(struct bt_saved_pos, 1); |
| 313 | pos->u.restore->tc = tc; |
| 314 | pos->u.restore->stream_saved_pos = g_array_new(FALSE, TRUE, |
| 315 | sizeof(struct stream_saved_pos)); |
| 316 | if (!pos->u.restore->stream_saved_pos) |
| 317 | goto error; |
| 318 | |
| 319 | for (i = 0; i < tc->array->len; i++) { |
| 320 | struct ctf_trace *tin; |
| 321 | struct trace_descriptor *td_read; |
| 322 | |
| 323 | td_read = g_ptr_array_index(tc->array, i); |
| 324 | tin = container_of(td_read, struct ctf_trace, parent); |
| 325 | |
| 326 | for (stream_class_id = 0; stream_class_id < tin->streams->len; |
| 327 | stream_class_id++) { |
| 328 | struct ctf_stream_class *stream_class; |
| 329 | |
| 330 | stream_class = g_ptr_array_index(tin->streams, |
| 331 | stream_class_id); |
| 332 | for (stream_id = 0; |
| 333 | stream_id < stream_class->streams->len; |
| 334 | stream_id++) { |
| 335 | struct ctf_stream *stream; |
| 336 | struct ctf_file_stream *cfs; |
| 337 | struct stream_saved_pos saved_pos; |
| 338 | |
| 339 | stream = g_ptr_array_index( |
| 340 | stream_class->streams, |
| 341 | stream_id); |
| 342 | cfs = container_of(stream, |
| 343 | struct ctf_file_stream, |
| 344 | parent); |
| 345 | |
| 346 | saved_pos.file_stream = cfs; |
| 347 | saved_pos.cur_index = cfs->pos.cur_index; |
| 348 | |
| 349 | /* |
| 350 | * It is possible that an event was read during |
| 351 | * the last restore, never consumed and its |
| 352 | * position saved again. For this case, we |
| 353 | * need to check if the event really was |
| 354 | * consumed by the caller otherwise it is lost. |
| 355 | */ |
| 356 | if (stream->consumed) |
| 357 | saved_pos.offset = cfs->pos.offset; |
| 358 | else |
| 359 | saved_pos.offset = cfs->pos.last_offset; |
| 360 | |
| 361 | saved_pos.current_timestamp = stream->timestamp; |
| 362 | |
| 363 | g_array_append_val( |
| 364 | pos->u.restore->stream_saved_pos, |
| 365 | saved_pos); |
| 366 | |
| 367 | printf_debug("stream : %" PRIu64 ", cur_index : %zd, " |
| 368 | "offset : %zd, " |
| 369 | "timestamp = %" PRIu64 "\n", |
| 370 | stream->stream_id, saved_pos.cur_index, |
| 371 | saved_pos.offset, |
| 372 | saved_pos.current_timestamp); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return pos; |
| 378 | |
| 379 | error: |
| 380 | return NULL; |
| 381 | } |
| 382 | |
| 383 | struct bt_iter_pos *bt_iter_create_time_pos(struct bt_iter *iter, |
| 384 | uint64_t timestamp) |
| 385 | { |
| 386 | struct bt_iter_pos *pos; |
| 387 | |
| 388 | pos = g_new0(struct bt_iter_pos, 1); |
| 389 | pos->type = BT_SEEK_TIME; |
| 390 | pos->u.seek_time = timestamp; |
| 391 | return pos; |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * babeltrace_filestream_seek: seek a filestream to given position. |
| 396 | * |
| 397 | * The stream_id parameter is only useful for BT_SEEK_RESTORE. |
| 398 | */ |
| 399 | static int babeltrace_filestream_seek(struct ctf_file_stream *file_stream, |
| 400 | const struct bt_iter_pos *begin_pos, |
| 401 | unsigned long stream_id) |
| 402 | { |
| 403 | int ret = 0; |
| 404 | |
| 405 | switch (begin_pos->type) { |
| 406 | case BT_SEEK_CUR: |
| 407 | /* |
| 408 | * just insert into the heap we should already know |
| 409 | * the timestamps |
| 410 | */ |
| 411 | break; |
| 412 | case BT_SEEK_BEGIN: |
| 413 | file_stream->pos.packet_seek(&file_stream->pos.parent, |
| 414 | 0, SEEK_SET); |
| 415 | ret = stream_read_event(file_stream); |
| 416 | break; |
| 417 | case BT_SEEK_TIME: |
| 418 | case BT_SEEK_RESTORE: |
| 419 | case BT_SEEK_END: |
| 420 | default: |
| 421 | assert(0); /* Not yet defined */ |
| 422 | } |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * bt_iter_seek: seek iterator to given position. |
| 429 | */ |
| 430 | int bt_iter_seek(struct bt_iter *iter, |
| 431 | const struct bt_iter_pos *begin_pos) |
| 432 | { |
| 433 | int i, stream_id; |
| 434 | int ret = 0; |
| 435 | struct trace_collection *tc = iter->ctx->tc; |
| 436 | |
| 437 | for (i = 0; i < tc->array->len; i++) { |
| 438 | struct ctf_trace *tin; |
| 439 | struct trace_descriptor *td_read; |
| 440 | |
| 441 | td_read = g_ptr_array_index(tc->array, i); |
| 442 | tin = container_of(td_read, struct ctf_trace, parent); |
| 443 | |
| 444 | /* Populate heap with each stream */ |
| 445 | for (stream_id = 0; stream_id < tin->streams->len; |
| 446 | stream_id++) { |
| 447 | struct ctf_stream_class *stream; |
| 448 | int filenr; |
| 449 | |
| 450 | stream = g_ptr_array_index(tin->streams, stream_id); |
| 451 | for (filenr = 0; filenr < stream->streams->len; |
| 452 | filenr++) { |
| 453 | struct ctf_file_stream *file_stream; |
| 454 | |
| 455 | file_stream = g_ptr_array_index(stream->streams, |
| 456 | filenr); |
| 457 | ret = babeltrace_filestream_seek(file_stream, begin_pos, |
| 458 | stream_id); |
| 459 | if (ret < 0) |
| 460 | goto end; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | end: |
| 465 | return ret; |
| 466 | } |
| 467 | |
| 468 | int bt_iter_init(struct bt_iter *iter, |
| 469 | struct bt_context *ctx, |
| 470 | const struct bt_iter_pos *begin_pos, |
| 471 | const struct bt_iter_pos *end_pos) |
| 472 | { |
| 473 | int i, stream_id; |
| 474 | int ret = 0; |
| 475 | |
| 476 | if (ctx->current_iterator) { |
| 477 | ret = -1; |
| 478 | goto error_ctx; |
| 479 | } |
| 480 | |
| 481 | iter->stream_heap = g_new(struct ptr_heap, 1); |
| 482 | iter->end_pos = end_pos; |
| 483 | bt_context_get(ctx); |
| 484 | iter->ctx = ctx; |
| 485 | |
| 486 | ret = heap_init(iter->stream_heap, 0, stream_compare); |
| 487 | if (ret < 0) |
| 488 | goto error_heap_init; |
| 489 | |
| 490 | for (i = 0; i < ctx->tc->array->len; i++) { |
| 491 | struct ctf_trace *tin; |
| 492 | struct trace_descriptor *td_read; |
| 493 | |
| 494 | td_read = g_ptr_array_index(ctx->tc->array, i); |
| 495 | tin = container_of(td_read, struct ctf_trace, parent); |
| 496 | |
| 497 | /* Populate heap with each stream */ |
| 498 | for (stream_id = 0; stream_id < tin->streams->len; |
| 499 | stream_id++) { |
| 500 | struct ctf_stream_class *stream; |
| 501 | int filenr; |
| 502 | |
| 503 | stream = g_ptr_array_index(tin->streams, stream_id); |
| 504 | if (!stream) |
| 505 | continue; |
| 506 | for (filenr = 0; filenr < stream->streams->len; |
| 507 | filenr++) { |
| 508 | struct ctf_file_stream *file_stream; |
| 509 | |
| 510 | file_stream = g_ptr_array_index(stream->streams, |
| 511 | filenr); |
| 512 | |
| 513 | if (begin_pos) { |
| 514 | ret = babeltrace_filestream_seek( |
| 515 | file_stream, |
| 516 | begin_pos, |
| 517 | stream_id); |
| 518 | } else { |
| 519 | struct bt_iter_pos pos; |
| 520 | pos.type = BT_SEEK_BEGIN; |
| 521 | ret = babeltrace_filestream_seek( |
| 522 | file_stream, &pos, |
| 523 | stream_id); |
| 524 | } |
| 525 | if (ret == EOF) { |
| 526 | ret = 0; |
| 527 | continue; |
| 528 | } else if (ret) { |
| 529 | goto error; |
| 530 | } |
| 531 | /* Add to heap */ |
| 532 | ret = heap_insert(iter->stream_heap, file_stream); |
| 533 | if (ret) |
| 534 | goto error; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | ctx->current_iterator = iter; |
| 540 | return 0; |
| 541 | |
| 542 | error: |
| 543 | heap_free(iter->stream_heap); |
| 544 | error_heap_init: |
| 545 | g_free(iter->stream_heap); |
| 546 | error_ctx: |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | struct bt_iter *bt_iter_create(struct bt_context *ctx, |
| 551 | const struct bt_iter_pos *begin_pos, |
| 552 | const struct bt_iter_pos *end_pos) |
| 553 | { |
| 554 | struct bt_iter *iter; |
| 555 | int ret; |
| 556 | |
| 557 | iter = g_new0(struct bt_iter, 1); |
| 558 | ret = bt_iter_init(iter, ctx, begin_pos, end_pos); |
| 559 | if (ret) { |
| 560 | g_free(iter); |
| 561 | return NULL; |
| 562 | } |
| 563 | return iter; |
| 564 | } |
| 565 | |
| 566 | void bt_iter_fini(struct bt_iter *iter) |
| 567 | { |
| 568 | if (iter->stream_heap) { |
| 569 | heap_free(iter->stream_heap); |
| 570 | g_free(iter->stream_heap); |
| 571 | } |
| 572 | iter->ctx->current_iterator = NULL; |
| 573 | bt_context_put(iter->ctx); |
| 574 | } |
| 575 | |
| 576 | void bt_iter_destroy(struct bt_iter *iter) |
| 577 | { |
| 578 | bt_iter_fini(iter); |
| 579 | g_free(iter); |
| 580 | } |
| 581 | |
| 582 | int bt_iter_next(struct bt_iter *iter) |
| 583 | { |
| 584 | struct ctf_file_stream *file_stream, *removed; |
| 585 | int ret; |
| 586 | |
| 587 | file_stream = heap_maximum(iter->stream_heap); |
| 588 | if (!file_stream) { |
| 589 | /* end of file for all streams */ |
| 590 | ret = 0; |
| 591 | goto end; |
| 592 | } |
| 593 | |
| 594 | ret = stream_read_event(file_stream); |
| 595 | if (ret == EOF) { |
| 596 | removed = heap_remove(iter->stream_heap); |
| 597 | assert(removed == file_stream); |
| 598 | ret = 0; |
| 599 | goto end; |
| 600 | } else if (ret) { |
| 601 | goto end; |
| 602 | } |
| 603 | /* Reinsert the file stream into the heap, and rebalance. */ |
| 604 | removed = heap_replace_max(iter->stream_heap, file_stream); |
| 605 | assert(removed == file_stream); |
| 606 | |
| 607 | end: |
| 608 | return ret; |
| 609 | } |