[PATCH 11/11] libtraceeval task-evals: Free the libtraceevals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

Add code to free the allocated traceveals including the ones that are
daisy chained in the teval_tasks.

Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
 samples/task-eval.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/samples/task-eval.c b/samples/task-eval.c
index 25032293c9a3..382e30514ec3 100644
--- a/samples/task-eval.c
+++ b/samples/task-eval.c
@@ -225,6 +225,20 @@ static void assign_task_keys(struct traceeval_data keys[2],
 	TRACEEVAL_SET_NUMBER(keys[1], state);
 }
 
+static void release_data(const struct traceeval_type *type,
+			  struct traceeval_data *data);
+
+static int copy_data(const struct traceeval_type *type,
+		     struct traceeval_data *dst,
+		     const struct traceeval_data *src)
+{
+	if (dst->pointer && dst->pointer != src->pointer)
+		die("Pointers do not match!");
+	/* This prevents releases of data */
+	*dst = *src;
+	return 0;
+}
+
 /*
  * For each state the process is in, record the time delta for
  * that state. Also, only for the RUNNING state, this will
@@ -237,6 +251,8 @@ static struct traceeval_type task_vals[] = {
 	{
 		.type = TRACEEVAL_TYPE_POINTER,
 		.name = "data",
+		.release = release_data,
+		.copy = copy_data,
 	},
 	{
 		.type = TRACEEVAL_TYPE_DELTA,
@@ -326,6 +342,21 @@ enum command {
 	STOP
 };
 
+static void release_data(const struct traceeval_type *type,
+			  struct traceeval_data *data)
+{
+	struct process_data *pdata;
+
+	if (!data || !data->pointer)
+		return;
+
+	pdata = data->pointer;
+	traceeval_release(pdata->teval_cpus);
+	traceeval_release(pdata->teval_threads);
+	free(pdata);
+	data->pointer = NULL;
+}
+
 static void init_process_data(struct process_data *pdata)
 {
 	pdata->teval_cpus = traceeval_init(cpu_keys, cpu_vals);
@@ -1043,6 +1074,11 @@ static void display(struct task_data *tdata)
 
 static void free_tdata(struct task_data *tdata)
 {
+	if (!tdata)
+		return;
+
+	traceeval_release(tdata->teval_cpus);
+	traceeval_release(tdata->teval_tasks);
 }
 
 /*
-- 
2.42.0





[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux