X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=lib%2Fiterator.c;h=4190e65286d914021133ea110e936a27ce51c208;hp=b57be035057923a5bee693c3e3889a4ef1f8d26b;hb=1b8455b701df7ac196e35795b9ab8ef2d402058d;hpb=2af75f65e584f99e299e6d79af9c1796c5a00316 diff --git a/lib/iterator.c b/lib/iterator.c index b57be035..4190e652 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -16,6 +16,14 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include @@ -172,7 +180,7 @@ static int seek_ctf_trace_by_timestamp(struct ctf_trace *tin, ret = seek_file_stream_by_timestamp(cfs, timestamp); if (ret == 0) { /* Add to heap */ - ret = heap_insert(stream_heap, cfs); + ret = bt_heap_insert(stream_heap, cfs); if (ret) { /* Return positive error. */ return -ret; @@ -253,7 +261,7 @@ static int find_max_timestamp_ctf_stream_class( struct ctf_file_stream **cfsp, uint64_t *max_timestamp) { - int ret = EOF, i; + int ret = EOF, i, found = 0; for (i = 0; i < stream_class->streams->len; i++) { struct ctf_stream_definition *stream; @@ -272,9 +280,13 @@ static int find_max_timestamp_ctf_stream_class( if (current_max_ts >= *max_timestamp) { *max_timestamp = current_max_ts; *cfsp = cfs; + found = 1; } } assert(ret >= 0 || ret == EOF); + if (found) { + return 0; + } return ret; } @@ -297,7 +309,7 @@ static int seek_last_ctf_trace_collection(struct trace_collection *tc, /* For each trace in the trace_collection */ for (i = 0; i < tc->array->len; i++) { struct ctf_trace *tin; - struct trace_descriptor *td_read; + struct bt_trace_descriptor *td_read; td_read = g_ptr_array_index(tc->array, i); if (!td_read) @@ -346,8 +358,8 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) if (!iter_pos->u.restore) return -EINVAL; - heap_free(iter->stream_heap); - ret = heap_init(iter->stream_heap, 0, stream_compare); + bt_heap_free(iter->stream_heap); + ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; @@ -381,8 +393,8 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) stream->prev_cycles_timestamp = 0; stream->prev_cycles_timestamp_end = 0; - printf_debug("restored to cur_index = %zd and " - "offset = %zd, timestamp = %" PRIu64 "\n", + printf_debug("restored to cur_index = %" PRId64 " and " + "offset = %" PRId64 ", timestamp = %" PRIu64 "\n", stream_pos->cur_index, stream_pos->offset, stream->real_timestamp); @@ -392,7 +404,7 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) } /* Add to heap */ - ret = heap_insert(iter->stream_heap, + ret = bt_heap_insert(iter->stream_heap, saved_pos->file_stream); if (ret) goto error; @@ -401,15 +413,15 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) case BT_SEEK_TIME: tc = iter->ctx->tc; - heap_free(iter->stream_heap); - ret = heap_init(iter->stream_heap, 0, stream_compare); + bt_heap_free(iter->stream_heap); + ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; /* for each trace in the trace_collection */ for (i = 0; i < tc->array->len; i++) { struct ctf_trace *tin; - struct trace_descriptor *td_read; + struct bt_trace_descriptor *td_read; td_read = g_ptr_array_index(tc->array, i); if (!td_read) @@ -432,14 +444,14 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) return 0; case BT_SEEK_BEGIN: tc = iter->ctx->tc; - heap_free(iter->stream_heap); - ret = heap_init(iter->stream_heap, 0, stream_compare); + bt_heap_free(iter->stream_heap); + ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; for (i = 0; i < tc->array->len; i++) { struct ctf_trace *tin; - struct trace_descriptor *td_read; + struct bt_trace_descriptor *td_read; int stream_id; td_read = g_ptr_array_index(tc->array, i); @@ -471,7 +483,11 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) if (ret != 0 && ret != EOF) { goto error; } - ret = heap_insert(iter->stream_heap, file_stream); + if (ret == EOF) { + /* Do not add EOF streams */ + continue; + } + ret = bt_heap_insert(iter->stream_heap, file_stream); if (ret) goto error; } @@ -487,13 +503,13 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) if (ret != 0 || !cfs) goto error; /* remove all streams from the heap */ - heap_free(iter->stream_heap); + bt_heap_free(iter->stream_heap); /* Create a new empty heap */ - ret = heap_init(iter->stream_heap, 0, stream_compare); + ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error; /* Insert the stream that contains the last event */ - ret = heap_insert(iter->stream_heap, cfs); + ret = bt_heap_insert(iter->stream_heap, cfs); if (ret) goto error; break; @@ -506,10 +522,10 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) return 0; error: - heap_free(iter->stream_heap); + bt_heap_free(iter->stream_heap); error_heap_init: - if (heap_init(iter->stream_heap, 0, stream_compare) < 0) { - heap_free(iter->stream_heap); + if (bt_heap_init(iter->stream_heap, 0, stream_compare) < 0) { + bt_heap_free(iter->stream_heap); g_free(iter->stream_heap); iter->stream_heap = NULL; ret = -ENOMEM; @@ -539,12 +555,12 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter) if (!pos->u.restore->stream_saved_pos) goto error; - ret = heap_copy(&iter_heap_copy, iter->stream_heap); + ret = bt_heap_copy(&iter_heap_copy, iter->stream_heap); if (ret < 0) goto error_heap; /* iterate over each stream in the heap */ - file_stream = heap_maximum(&iter_heap_copy); + file_stream = bt_heap_maximum(&iter_heap_copy); while (file_stream != NULL) { struct stream_saved_pos saved_pos; @@ -568,12 +584,12 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter) saved_pos.current_real_timestamp); /* remove the stream from the heap copy */ - removed = heap_remove(&iter_heap_copy); + removed = bt_heap_remove(&iter_heap_copy); assert(removed == file_stream); - file_stream = heap_maximum(&iter_heap_copy); + file_stream = bt_heap_maximum(&iter_heap_copy); } - heap_free(&iter_heap_copy); + bt_heap_free(&iter_heap_copy); return pos; error_heap: @@ -653,13 +669,13 @@ int bt_iter_init(struct bt_iter *iter, bt_context_get(ctx); iter->ctx = ctx; - ret = heap_init(iter->stream_heap, 0, stream_compare); + ret = bt_heap_init(iter->stream_heap, 0, stream_compare); if (ret < 0) goto error_heap_init; for (i = 0; i < ctx->tc->array->len; i++) { struct ctf_trace *tin; - struct trace_descriptor *td_read; + struct bt_trace_descriptor *td_read; td_read = g_ptr_array_index(ctx->tc->array, i); if (!td_read) @@ -702,7 +718,7 @@ int bt_iter_init(struct bt_iter *iter, goto error; } /* Add to heap */ - ret = heap_insert(iter->stream_heap, file_stream); + ret = bt_heap_insert(iter->stream_heap, file_stream); if (ret) goto error; } @@ -713,7 +729,7 @@ int bt_iter_init(struct bt_iter *iter, return 0; error: - heap_free(iter->stream_heap); + bt_heap_free(iter->stream_heap); error_heap_init: g_free(iter->stream_heap); iter->stream_heap = NULL; @@ -744,7 +760,7 @@ void bt_iter_fini(struct bt_iter *iter) { assert(iter); if (iter->stream_heap) { - heap_free(iter->stream_heap); + bt_heap_free(iter->stream_heap); g_free(iter->stream_heap); } iter->ctx->current_iterator = NULL; @@ -766,7 +782,7 @@ int bt_iter_next(struct bt_iter *iter) if (!iter) return -EINVAL; - file_stream = heap_maximum(iter->stream_heap); + file_stream = bt_heap_maximum(iter->stream_heap); if (!file_stream) { /* end of file for all streams */ ret = 0; @@ -775,7 +791,7 @@ int bt_iter_next(struct bt_iter *iter) ret = stream_read_event(file_stream); if (ret == EOF) { - removed = heap_remove(iter->stream_heap); + removed = bt_heap_remove(iter->stream_heap); assert(removed == file_stream); ret = 0; goto end; @@ -783,7 +799,7 @@ int bt_iter_next(struct bt_iter *iter) goto end; } /* Reinsert the file stream into the heap, and rebalance. */ - removed = heap_replace_max(iter->stream_heap, file_stream); + removed = bt_heap_replace_max(iter->stream_heap, file_stream); assert(removed == file_stream); end: