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 v3 1/4] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd
Date: Tue,  3 Sep 2019 16:34:42 +0300
Message-ID: <20190903133445.30486-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20190903133445.30486-1-tz.stoyanov@gmail.com>

A trace-cmd global variable "quiet" is used from libtracecmd and
should be defined there. A new library APIs are implemented to
access it:
 void tracecmd_set_quiet(int quiet);
 int tracecmd_get_quiet(void);

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/trace-cmd/trace-cmd.h           |  3 +++
 lib/trace-cmd/include/trace-cmd-local.h |  2 --
 lib/trace-cmd/trace-output.c            | 28 +++++++++++++++++++++++--
 tracecmd/include/trace-local.h          |  2 --
 tracecmd/trace-cmd.c                    |  2 --
 tracecmd/trace-record.c                 | 15 +++++++++----
 6 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h
index ede510c..f44f7a4 100644
--- a/include/trace-cmd/trace-cmd.h
+++ b/include/trace-cmd/trace-cmd.h
@@ -57,6 +57,9 @@ struct tracecmd_output;
 struct tracecmd_recorder;
 struct hook_list;
 
+void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet);
+bool tracecmd_get_quiet(struct tracecmd_output *handle);
+
 static inline int tracecmd_host_bigendian(void)
 {
 	unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 };
diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h
index bad325f..09574db 100644
--- a/lib/trace-cmd/include/trace-cmd-local.h
+++ b/lib/trace-cmd/include/trace-cmd-local.h
@@ -18,8 +18,6 @@
 #define STR(x)	_STR(x)
 #define FILE_VERSION_STRING STR(FILE_VERSION)
 
-extern int quiet;
-
 static ssize_t __do_write(int fd, const void *data, size_t size)
 {
 	ssize_t tot = 0;
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 1f94346..41932ee 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -53,6 +53,7 @@ struct tracecmd_output {
 	char			*tracing_dir;
 	int			options_written;
 	int			nr_options;
+	bool			quiet;
 	struct list_head 	options;
 	struct tracecmd_msg_handle *msg_handle;
 };
@@ -103,6 +104,29 @@ static unsigned long long convert_endian_8(struct tracecmd_output *handle,
 	return tep_read_number(handle->pevent, &val, 8);
 }
 
+/**
+ * tracecmd_set_quiet - Set if to print output to the screen
+ * @quiet: If non zero, print no output to the screen
+ *
+ */
+void tracecmd_set_quiet(struct tracecmd_output *handle, bool set_quiet)
+{
+	if (handle)
+		handle->quiet = set_quiet;
+}
+
+/**
+ * tracecmd_get_quiet - Get if to print output to the screen
+ * Returns non zero, if no output to the screen should be printed
+ *
+ */
+bool tracecmd_get_quiet(struct tracecmd_output *handle)
+{
+	if (handle)
+		return handle->quiet;
+	return false;
+}
+
 void tracecmd_output_free(struct tracecmd_output *handle)
 {
 	struct tracecmd_option *option;
@@ -1157,7 +1181,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 		goto out_free;
 
 	for (i = 0; i < cpus; i++) {
-		if (!quiet)
+		if (!tracecmd_get_quiet(handle))
 			fprintf(stderr, "CPU%d data recorded at offset=0x%llx\n",
 				i, (unsigned long long) offsets[i]);
 		offset = lseek64(handle->fd, offsets[i], SEEK_SET);
@@ -1172,7 +1196,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 			    check_size, sizes[i]);
 			goto out_free;
 		}
-		if (!quiet)
+		if (!tracecmd_get_quiet(handle))
 			fprintf(stderr, "    %llu bytes in size\n",
 				(unsigned long long)check_size);
 	}
diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 7de5dd6..05760d8 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -12,8 +12,6 @@
 #include "trace-cmd.h"
 #include "event-utils.h"
 
-extern int quiet;
-
 /* fix stupid glib guint64 typecasts and printf formats */
 typedef unsigned long long u64;
 
diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c
index 4add2e2..30691b6 100644
--- a/tracecmd/trace-cmd.c
+++ b/tracecmd/trace-cmd.c
@@ -16,8 +16,6 @@
 int silence_warnings;
 int show_status;
 
-int quiet;
-
 void warning(const char *fmt, ...)
 {
 	va_list ap;
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 7467b47..61457c8 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -80,6 +80,8 @@ static char *host;
 static unsigned int *client_ports;
 static int sfd;
 
+static bool quiet;
+
 /* Max size to let a per cpu file get */
 static int max_kb;
 
@@ -3162,13 +3164,16 @@ setup_connection(struct buffer_instance *instance, struct common_record_context
 	/* Now create the handle through this socket */
 	if (msg_handle->version == V3_PROTOCOL) {
 		network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events);
+		tracecmd_set_quiet(network_handle, quiet);
 		add_options(network_handle, ctx);
 		tracecmd_write_cpus(network_handle, instance->cpu_count);
 		tracecmd_write_options(network_handle);
 		tracecmd_msg_finish_sending_data(msg_handle);
-	} else
+	} else {
 		network_handle = tracecmd_create_init_fd_glob(msg_handle->fd,
 							      listed_events);
+		tracecmd_set_quiet(network_handle, quiet);
+	}
 
 	instance->network_handle = network_handle;
 
@@ -3444,9 +3449,10 @@ static void record_data(struct common_record_context *ctx)
 	if (!local)
 		return;
 
-	if (latency)
+	if (latency) {
 		handle = tracecmd_create_file_latency(output_file, local_cpu_count);
-	else {
+		tracecmd_set_quiet(handle, quiet);
+	} else {
 		if (!local_cpu_count)
 			return;
 
@@ -3478,6 +3484,7 @@ static void record_data(struct common_record_context *ctx)
 		handle = tracecmd_create_init_file_glob(output_file, listed_events);
 		if (!handle)
 			die("Error creating output file");
+		tracecmd_set_quiet(handle, quiet);
 
 		add_options(handle, ctx);
 
@@ -5155,7 +5162,7 @@ static void parse_record_options(int argc,
 			break;
 		case OPT_quiet:
 		case 'q':
-			quiet = 1;
+			quiet = true;
 			break;
 		default:
 			usage(argv);
-- 
2.21.0


  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 13:34 [PATCH v3 0/4] Separate trace-cmd and libtracecmd code Tzvetomir Stoyanov (VMware)
2019-09-03 13:34 ` Tzvetomir Stoyanov (VMware) [this message]
2019-09-03 13:34 ` [PATCH v3 2/4] trace-cmd: Move plog() function to libtracecmd Tzvetomir Stoyanov (VMware)
2019-09-03 13:34 ` [PATCH v3 3/4] trace-cmd: Move tracecmd_stack_tracer_status() " Tzvetomir Stoyanov (VMware)
2019-09-03 13:34 ` [PATCH v3 4/4] trace-cmd: Update descriptions of "debug" libtracecmd APIs Tzvetomir Stoyanov (VMware)

Reply instructions:

You may reply publically 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=20190903133445.30486-2-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 linux-trace-devel@archiver.kernel.org
	public-inbox-index linux-trace-devel


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