diff mbox series

[BlueZ,v3,5/5] monitor/analyze: Inline data to gnuplot

Message ID 20230801233135.537864-5-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 80107630396d3d3a3984c599e0cb9b015be0499c
Headers show
Series [BlueZ,v3,1/5] monitor: Add TX frame number and speed estimation | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz Aug. 1, 2023, 11:31 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Instead of creating a separate file just to write the x:y axis inline
the data via gnuplot $data variable then use it to plot.
---
 monitor/analyze.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/monitor/analyze.c b/monitor/analyze.c
index d0ad70d5dc74..9f882a6c8b71 100644
--- a/monitor/analyze.c
+++ b/monitor/analyze.c
@@ -112,35 +112,28 @@  static void tmp_write(void *data, void *user_data)
 
 static void plot_draw(struct queue *queue)
 {
-	const char *filename = "analyze.tmp";
-	FILE *gplot = popen("gnuplot", "w");
-	FILE *tmp;
+	FILE *gplot;
 
+	if (queue_length(queue) < 2)
+		return;
+
+	gplot = popen("gnuplot", "w");
 	if (!gplot)
 		return;
 
-	if (queue_isempty(queue))
-		goto done;
-
-	tmp = fopen(filename, "w");
-	if (!tmp)
-		goto done;
-
-	queue_foreach(queue, tmp_write, tmp);
+	fprintf(gplot, "$data << EOD\n");
+	queue_foreach(queue, tmp_write, gplot);
+	fprintf(gplot, "EOD\n");
 
 	fprintf(gplot, "set terminal dumb enhanced ansi\n");
 	fprintf(gplot, "set xlabel 'Latency (ms)'\n");
 	fprintf(gplot, "set tics out nomirror\n");
 	fprintf(gplot, "set log y\n");
 	fprintf(gplot, "set yrange [0.5:*]\n");
-	fprintf(gplot, "plot './%s' using 1:2 t 'Packets' w impulses\n",
-								filename);
+	fprintf(gplot, "plot $data using 1:2 t 'Packets' w impulses\n");
 	fflush(gplot);
 
-	fclose(tmp);
-done:
 	pclose(gplot);
-	unlink(filename);
 }
 
 static void chan_destroy(void *data)
@@ -166,8 +159,7 @@  static void chan_destroy(void *data)
 		print_field("~%lld Kb/s TX transfer speed",
 				chan->tx_bytes * 8 / TV_MSEC(chan->tx_l.total));
 
-	if (chan->num > 1)
-		plot_draw(chan->plot);
+	plot_draw(chan->plot);
 
 	free(chan);
 }