Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 5/5] KernelShark: New libkshark API for loading all entries from given file
Date: Mon, 27 Jul 2020 10:18:23 +0300
Message-ID: <20200727071823.169962-6-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200727071823.169962-1-tz.stoyanov@gmail.com>

From: Tzvetomir (VMware)  Stoyanov <tz.stoyanov@gmail.com>

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@gmail.com>
---
 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


      parent reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27  7:18 [PATCH 0/5] Add support for opening trace.dat files with multuiple buffers Tzvetomir Stoyanov (VMware)
2020-07-27  7:18 ` [PATCH 1/5] KernelShark: Add stream name Tzvetomir Stoyanov (VMware)
2020-07-28 13:21   ` Steven Rostedt
2020-07-27  7:18 ` [PATCH 2/5] KernelShark: Fix compilation issues on Fedora 32 Tzvetomir Stoyanov (VMware)
2020-07-28 13:23   ` Steven Rostedt
2020-07-27  7:18 ` [PATCH 3/5] KernelShark: Fix combo plot plugin crash in case of multiple streams Tzvetomir Stoyanov (VMware)
2020-07-28 13:26   ` Steven Rostedt
2020-07-27  7:18 ` [PATCH 4/5] KernelShark: Load trace.dat file with ftrace sub-buffers Tzvetomir Stoyanov (VMware)
2020-07-27  7:18 ` Tzvetomir Stoyanov (VMware) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200727071823.169962-6-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git