linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH v7 12/32] kernel-shark: Housekeeping before implementing stream interface
Date: Fri, 11 Dec 2020 17:07:36 +0200	[thread overview]
Message-ID: <20201211150756.577366-13-y.karadz@gmail.com> (raw)
In-Reply-To: <20201211150756.577366-1-y.karadz@gmail.com>

kshark_load data_matrix() is a method that is used only in trace-cruncher
prototype. The version of this function that is currently part of the API
is anyway not compatible with the latest version of trace-cruncher because
of the mismatch of the argument types, so we can directly remove the
existing implementation. An equivalent functionality will be provided as
part of the implantation of the Data stream interface in the following
patch. Here we just make kshark_data_matrix_alloc() and
unset_event_filter_flag() public, because the methods will be used in the
stream interface implementation.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/libkshark.c | 121 ++++++++----------------------------------------
 src/libkshark.h |  28 ++++++++---
 2 files changed, 40 insertions(+), 109 deletions(-)

diff --git a/src/libkshark.c b/src/libkshark.c
index bf465b5..ff0fe12 100644
--- a/src/libkshark.c
+++ b/src/libkshark.c
@@ -1190,21 +1190,6 @@ bool kshark_filter_is_set(struct kshark_context *kshark_ctx)
 -              kshark_this_filter_is_set(kshark_ctx->hide_event_filter);
 }
 
-static inline void unset_event_filter_flag(struct kshark_context *kshark_ctx,
-					   struct kshark_entry *e)
-{
-	/*
-	 * All entries, filtered-out by the event filters, will be treated
-	 * differently, when visualized. Because of this, ignore the value
-	 * of the GRAPH_VIEW flag provided by the user via
-	 * kshark_ctx->filter_mask. The value of the EVENT_VIEW flag in
-	 * kshark_ctx->filter_mask will be used instead.
-	 */
-	int event_mask = kshark_ctx->filter_mask & ~KS_GRAPH_VIEW_FILTER_MASK;
-
-	e->visible &= ~event_mask;
-}
-
 static void set_all_visible(uint16_t *v) {
 	/*  Keep the original value of the PLUGIN_UNTOUCHED bit flag. */
 	*v |= 0xFF & ~KS_PLUGIN_UNTOUCHED_MASK;
@@ -1680,11 +1665,25 @@ static inline void free_ptr(void *ptr)
 		free(*(void **)ptr);
 }
 
-static bool data_matrix_alloc(size_t n_rows, uint64_t **offset_array,
-					     uint16_t **cpu_array,
-					     uint64_t **ts_array,
-					     uint16_t **pid_array,
-					     int **event_array)
+/**
+ * @brief Allocate data arrays (matrix columns) to be used to load the tracing
+ *	  data into a data matrix form.
+ *
+ * @param n_rows: Number matrix rows to be allocated. Must be equal to the
+ *	 	  number of trace records.
+ * @param cpu_array: Output location for the CPU Id column.
+ * @param pid_array: Output location for the PID column.
+ * @param event_array: Output location for the Event Id column.
+ * @param offset_array: Output location for the record offset column.
+ * @param ts_array: Output location for the timestamp column.
+ *
+ * @returns True on success. Else false.
+ */
+bool kshark_data_matrix_alloc(size_t n_rows, int16_t **event_array,
+					     int16_t **cpu_array,
+					     int32_t **pid_array,
+					     int64_t **offset_array,
+					     int64_t **ts_array)
 {
 	if (offset_array) {
 		*offset_array = calloc(n_rows, sizeof(**offset_array));
@@ -1731,88 +1730,6 @@ static bool data_matrix_alloc(size_t n_rows, uint64_t **offset_array,
 	return false;
 }
 
-/**
- * @brief Load the content of the trace data file into a table / matrix made
- *	  of columns / arrays of data. The user is responsible for freeing the
- *	  elements of the outputted array
- *
- * @param kshark_ctx: Input location for the session context pointer.
- * @param offset_array: Output location for the array of record offsets.
- * @param cpu_array: Output location for the array of CPU Ids.
- * @param ts_array: Output location for the array of timestamps.
- * @param pid_array: Output location for the array of Process Ids.
- * @param event_array: Output location for the array of Event Ids.
- *
- * @returns The size of the outputted arrays in the case of success, or a
- *	    negative error code on failure.
- */
-size_t kshark_load_data_matrix(struct kshark_context *kshark_ctx,
-			       uint64_t **offset_array,
-			       uint16_t **cpu_array,
-			       uint64_t **ts_array,
-			       uint16_t **pid_array,
-			       int **event_array)
-{
-	enum rec_type type = REC_ENTRY;
-	struct rec_list **rec_list;
-	ssize_t count, total = 0;
-	bool status;
-	int n_cpus;
-
-	total = get_records(kshark_ctx, &rec_list, type);
-	if (total < 0)
-		goto fail;
-
-	n_cpus = tep_get_cpus(kshark_ctx->pevent);
-
-	status = data_matrix_alloc(total, offset_array,
-					  cpu_array,
-					  ts_array,
-					  pid_array,
-					  event_array);
-	if (!status)
-		goto fail_free;
-
-	for (count = 0; count < total; count++) {
-		int next_cpu;
-
-		next_cpu = pick_next_cpu(rec_list, n_cpus, type);
-		if (next_cpu >= 0) {
-			struct rec_list *rec = rec_list[next_cpu];
-			struct kshark_entry *e = &rec->entry;
-
-			if (offset_array)
-				(*offset_array)[count] = e->offset;
-
-			if (cpu_array)
-				(*cpu_array)[count] = e->cpu;
-
-			if (ts_array)
-				(*ts_array)[count] = e->ts;
-
-			if (pid_array)
-				(*pid_array)[count] = e->pid;
-
-			if (event_array)
-				(*event_array)[count] = e->event_id;
-
-			rec_list[next_cpu] = rec_list[next_cpu]->next;
-			free(rec);
-		}
-	}
-
-	/* There should be no entries left in rec_list. */
-	free_rec_list(rec_list, n_cpus, type);
-	return total;
-
- fail_free:
-	free_rec_list(rec_list, n_cpus, type);
-
- fail:
-	fprintf(stderr, "Failed to allocate memory during data loading.\n");
-	return -ENOMEM;
-}
-
 static const char *get_latency(struct tep_handle *pe,
 			       struct tep_record *record)
 {
diff --git a/src/libkshark.h b/src/libkshark.h
index 77fa4c5..36d6000 100644
--- a/src/libkshark.h
+++ b/src/libkshark.h
@@ -456,13 +456,6 @@ ssize_t kshark_load_data_entries(struct kshark_context *kshark_ctx,
 ssize_t kshark_load_data_records(struct kshark_context *kshark_ctx,
 				 struct tep_record ***data_rows);
 
-size_t kshark_load_data_matrix(struct kshark_context *kshark_ctx,
-			       uint64_t **offset_array,
-			       uint16_t **cpu_array,
-			       uint64_t **ts_array,
-			       uint16_t **pid_array,
-			       int **event_array);
-
 ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids);
 
 void kshark_close(struct kshark_context *kshark_ctx);
@@ -617,6 +610,21 @@ bool kshark_this_filter_is_set(struct tracecmd_filter_id *filter);
 
 bool kshark_filter_is_set(struct kshark_context *kshark_ctx);
 
+static inline void unset_event_filter_flag(struct kshark_context *kshark_ctx,
+					   struct kshark_entry *e)
+{
+	/*
+	 * All entries, filtered-out by the event filters, will be treated
+	 * differently, when visualized. Because of this, ignore the value
+	 * of the GRAPH_VIEW flag provided by the user via
+	 * stream->filter_mask. The value of the EVENT_VIEW flag in
+	 * stream->filter_mask will be used instead.
+	 */
+	int event_mask = kshark_ctx->filter_mask & ~KS_GRAPH_VIEW_FILTER_MASK;
+
+	e->visible &= ~event_mask;
+}
+
 void kshark_filter_entries(struct kshark_context *kshark_ctx,
 			   struct kshark_entry **data,
 			   size_t n_entries);
@@ -995,6 +1003,12 @@ struct kshark_config_doc *kshark_open_config_file(const char *file_name,
 
 struct kshark_config_doc *kshark_json_to_conf(struct json_object *jobj);
 
+bool kshark_data_matrix_alloc(size_t n_rows, int16_t **event_array,
+					     int16_t **cpu_array,
+					     int32_t **pid_array,
+					     int64_t **offset_array,
+					     int64_t **ts_array);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.25.1


  parent reply	other threads:[~2020-12-11 16:16 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 15:07 [PATCH v7 00/32] Start KernelShark v2 transformation Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 01/32] kernel-shark: Add license information Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 02/32] kernel-shark: Change the CMake minimum version required Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 03/32] kernel-shark: Use libtraceevent and libtracefs Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 04/32] kernel-shark: Update README Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 05/32] kernel-shark: Define build target for JSONC Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 06/32] kernel-shark: Use only signed types in kshark_entry Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 07/32] kernel-shark: Add stream_id to kshark_entry Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 08/32] kernel-shark: Introduce libkshark-hash Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 09/32] kernel-shark: Introduce Data streams Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 10/32] kernel-shark: Rename static methods in libkshark Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 11/32] kernel-shark: Add basic methods for Data streams Yordan Karadzhov (VMware)
2020-12-11 15:07 ` Yordan Karadzhov (VMware) [this message]
2020-12-11 15:07 ` [PATCH v7 13/32] kernel-shark: Add stream interface for trace-cmd data Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 14/32] kernel-shark: Start introducing KernelShark 2.0 Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 15/32] kernel-shark: Start using data streams Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 16/32] kernel-shark: Remove dead code Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 17/32] kernel-shark: Redesign the plugin interface Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 18/32] kernel-shark: Complete the stream integration Yordan Karadzhov (VMware)
2020-12-11 21:51   ` Steven Rostedt
2020-12-11 21:56     ` Steven Rostedt
2020-12-11 15:07 ` [PATCH v7 19/32] kernel-shark: Provide merging of multiple data streams Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 20/32] kernel-shark: Integrate the stream definitions with data model Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 21/32] kernel-shark: Use only signed types for model defs Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 22/32] kernel-shark: Add ksmodel_get_bin() Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 23/32] kernel-shark: Protect ksmodel_set_in_range_bining() Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 24/32] kernel-shark: Add methods for time calibration Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 25/32] kernel-shark: Integrate streams with libkshark-configio Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 26/32] kernel-shark: Add support for drawing text Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 27/32] kernel-shark: Make GLUT optional dependency Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 28/32] kernel-shark: Add ksplot_draw_polyline() Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 29/32] kernel-shark: Optimize ksplot_draw_polygon() Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 30/32] kernel-shark: Do not use the ARRAY_SIZE macro Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 31/32] kernel-shark: Add basic infrastructure for testing Yordan Karadzhov (VMware)
2020-12-11 15:07 ` [PATCH v7 32/32] kernel-shark: Add "github Actions" workflow Yordan Karadzhov (VMware)

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=20201211150756.577366-13-y.karadz@gmail.com \
    --to=y.karadz@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).