From: Tzvetomir (VMware) Stoyanov <tz.stoyanov@xxxxxxxxx> The existing API kshark_load_entries() loads data in a single stream. It cannot be used in case there are more than one streams in the same file. A new API is implemented: kshark_load_file_entries() which loads and merges entries in all sessions, related to given trace file. Signed-off-by: Tzvetomir (VMware) Stoyanov <tz.stoyanov@xxxxxxxxx> --- src/KsUtils.cpp | 4 ++-- src/libkshark.c | 36 +++++++++++++++++++++++++++++++----- src/libkshark.h | 3 +++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/KsUtils.cpp b/src/KsUtils.cpp index bcb88b5..f3e93ad 100644 --- a/src/KsUtils.cpp +++ b/src/KsUtils.cpp @@ -501,7 +501,7 @@ int KsDataStore::loadDataFile(const QString &file, kshark_handle_dpi(stream, plugin, KSHARK_PLUGIN_INIT); } - n = kshark_load_entries(kshark_ctx, sd, &_rows); + n = kshark_load_file_entries(kshark_ctx, &_rows, file.toStdString().c_str()); if (n < 0) { kshark_close(kshark_ctx, sd); return n; @@ -541,7 +541,7 @@ int KsDataStore::appendDataFile(const QString &file, int64_t offset) *(kshark_ctx->stream[sd]->calib_array) = offset; kshark_ctx->stream[sd]->calib_array_size = 1; - nApnd = kshark_load_entries(kshark_ctx, sd, &apndRows); + nApnd = kshark_load_file_entries(kshark_ctx, &_rows, file.toStdString().c_str()); if (nApnd <= 0) { QErrorMessage *em = new QErrorMessage(); em->showMessage(QString("File %1 contains no data.").arg(file)); diff --git a/src/libkshark.c b/src/libkshark.c index 375874d..a5126fd 100644 --- a/src/libkshark.c +++ b/src/libkshark.c @@ -1331,7 +1331,7 @@ void kshark_set_clock_offset(struct kshark_context *kshark_ctx, } /** - * @brief Load the content of the all opened data file into an array of + * @brief Load the content of data from given file into an array of * kshark_entries. * If one or more filters are set, the "visible" fields of each entry * is updated according to the criteria provided by the filters. The @@ -1346,11 +1346,12 @@ void kshark_set_clock_offset(struct kshark_context *kshark_ctx, * @returns The size of the outputted data in the case of success, or a * negative error code on failure. */ -ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx, - struct kshark_entry ***data_rows) +ssize_t kshark_load_file_entries(struct kshark_context *kshark_ctx, + struct kshark_entry ***data_rows, const char *file) { size_t data_size = 0; int i, *stream_ids, sd; + struct kshark_data_stream *stream; if (!kshark_ctx->n_streams) return data_size; @@ -1359,16 +1360,18 @@ ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx, sd = stream_ids[0]; data_size = kshark_load_entries(kshark_ctx, sd, data_rows); - for (i = 1; i < kshark_ctx->n_streams; ++i) { struct kshark_entry **stream_data_rows = NULL; struct kshark_entry **merged_data_rows; size_t stream_data_size; sd = stream_ids[i]; + stream = kshark_get_data_stream(kshark_ctx, sd); + if (!stream || (file && strcmp(stream->file, file))) + continue; + stream_data_size = kshark_load_entries(kshark_ctx, sd, &stream_data_rows); - merged_data_rows = kshark_data_merge(*data_rows, data_size, stream_data_rows, stream_data_size); @@ -1387,6 +1390,29 @@ ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx, return data_size; } + +/** + * @brief Load the content of the all opened data file into an array of + * kshark_entries. + * If one or more filters are set, the "visible" fields of each entry + * is updated according to the criteria provided by the filters. The + * field "filter_mask" of the session's context is used to control the + * level of visibility/invisibility of the filtered entries. + * + * @param kshark_ctx: Input location for context pointer. + * @param data_rows: Output location for the trace data. The user is + * responsible for freeing the elements of the outputted + * array. + * + * @returns The size of the outputted data in the case of success, or a + * negative error code on failure. + */ +ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx, + struct kshark_entry ***data_rows) +{ + return kshark_load_file_entries(kshark_ctx, data_rows, NULL); +} + static inline void free_ptr(void *ptr) { if (ptr) diff --git a/src/libkshark.h b/src/libkshark.h index 44bec79..a76ec92 100644 --- a/src/libkshark.h +++ b/src/libkshark.h @@ -751,6 +751,9 @@ void kshark_set_clock_offset(struct kshark_context *kshark_ctx, ssize_t kshark_load_all_entries(struct kshark_context *kshark_ctx, struct kshark_entry ***data_rows); +ssize_t kshark_load_file_entries(struct kshark_context *kshark_ctx, + struct kshark_entry ***data_rows, const char *file); + /** * Data collections are used to optimize the search for an entry having an * abstract property, defined by a Matching condition function and an array of -- 2.26.2