Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/2] Remove tracefs_get_tracing_dir() API
@ 2020-12-22  5:06 Tzvetomir Stoyanov (VMware)
  2020-12-22  5:06 ` [PATCH 1/2] trace-cmd: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir() Tzvetomir Stoyanov (VMware)
  2020-12-22  5:06 ` [PATCH 2/2] trace-cmd: Use tracefs_tracing_dir() instead of tracefs_find_tracing_dir() Tzvetomir Stoyanov (VMware)
  0 siblings, 2 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-22  5:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The two APIs to get the tracefs mount point
tracefs_get_tracing_dir() and tracefs_find_tracing_dir()
are replaced by single one, tracefs_tracing_dir().

Tzvetomir Stoyanov (VMware) (2):
  trace-cmd: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir()
  trace-cmd: Use tracefs_tracing_dir() instead of
    tracefs_find_tracing_dir()

 include/tracefs/tracefs.h            |  7 ++-----
 kernel-shark/src/KsCaptureDialog.cpp |  4 ++--
 lib/trace-cmd/trace-output.c         |  7 +++++--
 lib/trace-cmd/trace-recorder.c       |  6 +++---
 lib/tracefs/include/tracefs-local.h  |  2 ++
 lib/tracefs/tracefs-events.c         |  6 +++---
 lib/tracefs/tracefs-instance.c       |  2 +-
 lib/tracefs/tracefs-utils.c          | 14 +++++++-------
 tracecmd/trace-check-events.c        |  2 +-
 tracecmd/trace-record.c              | 19 ++++++++++++-------
 utest/tracefs-utest.c                | 23 +++++++----------------
 11 files changed, 45 insertions(+), 47 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] trace-cmd: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir()
  2020-12-22  5:06 [PATCH 0/2] Remove tracefs_get_tracing_dir() API Tzvetomir Stoyanov (VMware)
@ 2020-12-22  5:06 ` Tzvetomir Stoyanov (VMware)
  2020-12-22  5:06 ` [PATCH 2/2] trace-cmd: Use tracefs_tracing_dir() instead of tracefs_find_tracing_dir() Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-22  5:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The libtracefs API fo locating trace file system mount point is renamed,
use the new API in trace-cmd.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs/tracefs.h            |  4 ++--
 kernel-shark/src/KsCaptureDialog.cpp |  4 ++--
 lib/trace-cmd/trace-recorder.c       |  6 +++---
 lib/tracefs/tracefs-events.c         |  6 +++---
 lib/tracefs/tracefs-utils.c          |  6 +++---
 tracecmd/trace-check-events.c        |  2 +-
 utest/tracefs-utest.c                | 14 +++++++-------
 7 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index ce8b09ca..8308e3ac 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -12,8 +12,8 @@
 char *tracefs_get_tracing_file(const char *name);
 void tracefs_put_tracing_file(char *name);
 
-/* tracefs_get_tracing_dir must *not* be freed */
-const char *tracefs_get_tracing_dir(void);
+/* The returned string must *not* be freed */
+const char *tracefs_tracing_dir(void);
 
 /* tracefs_find_tracing_dir must be freed */
 char *tracefs_find_tracing_dir(void);
diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp
index 63fd5d6e..7253ab68 100644
--- a/kernel-shark/src/KsCaptureDialog.cpp
+++ b/kernel-shark/src/KsCaptureDialog.cpp
@@ -26,7 +26,7 @@ extern "C" {
 
 static inline tep_handle *local_events()
 {
-	return tracefs_local_events(tracefs_get_tracing_dir());
+	return tracefs_local_events(tracefs_tracing_dir());
 }
 
 /**
@@ -204,7 +204,7 @@ QStringList KsCaptureControl::_getPlugins()
 	QStringList pluginList;
 	char **all_plugins;
 
-	all_plugins = tracefs_tracers(tracefs_get_tracing_dir());
+	all_plugins = tracefs_tracers(tracefs_tracing_dir());
 
 	if (!all_plugins)
 		return pluginList;
diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c
index 6b647d6c..c811028a 100644
--- a/lib/trace-cmd/trace-recorder.c
+++ b/lib/trace-cmd/trace-recorder.c
@@ -307,7 +307,7 @@ struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned
 {
 	const char *tracing;
 
-	tracing = tracefs_get_tracing_dir();
+	tracing = tracefs_tracing_dir();
 	if (!tracing) {
 		errno = ENODEV;
 		return NULL;
@@ -320,7 +320,7 @@ struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu, un
 {
 	const char *tracing;
 
-	tracing = tracefs_get_tracing_dir();
+	tracing = tracefs_tracing_dir();
 	if (!tracing) {
 		errno = ENODEV;
 		return NULL;
@@ -334,7 +334,7 @@ tracecmd_create_recorder_maxkb(const char *file, int cpu, unsigned flags, int ma
 {
 	const char *tracing;
 
-	tracing = tracefs_get_tracing_dir();
+	tracing = tracefs_tracing_dir();
 	if (!tracing) {
 		errno = ENODEV;
 		return NULL;
diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c
index ba640a9e..826b6fc7 100644
--- a/lib/tracefs/tracefs-events.c
+++ b/lib/tracefs/tracefs-events.c
@@ -267,7 +267,7 @@ char **tracefs_event_systems(const char *tracing_dir)
 	int ret;
 
 	if (!tracing_dir)
-		tracing_dir = tracefs_get_tracing_dir();
+		tracing_dir = tracefs_tracing_dir();
 
 	if (!tracing_dir)
 		return NULL;
@@ -341,7 +341,7 @@ char **tracefs_system_events(const char *tracing_dir, const char *system)
 	int ret;
 
 	if (!tracing_dir)
-		tracing_dir = tracefs_get_tracing_dir();
+		tracing_dir = tracefs_tracing_dir();
 
 	if (!tracing_dir || !system)
 		return NULL;
@@ -540,7 +540,7 @@ static int fill_local_events_system(const char *tracing_dir,
 	int i;
 
 	if (!tracing_dir)
-		tracing_dir = tracefs_get_tracing_dir();
+		tracing_dir = tracefs_tracing_dir();
 	if (!tracing_dir)
 		return -1;
 
diff --git a/lib/tracefs/tracefs-utils.c b/lib/tracefs/tracefs-utils.c
index 326b4559..8483cb61 100644
--- a/lib/tracefs/tracefs-utils.c
+++ b/lib/tracefs/tracefs-utils.c
@@ -131,12 +131,12 @@ char *tracefs_find_tracing_dir(void)
 }
 
 /**
- * tracefs_get_tracing_dir - Get tracing directory
+ * tracefs_tracing_dir - Get tracing directory
  *
  * Returns string containing the full path to the system's tracing directory.
  * The returned string must *not* be freed.
  */
-const char *tracefs_get_tracing_dir(void)
+const char *tracefs_tracing_dir(void)
 {
 	static const char *tracing_dir;
 
@@ -182,7 +182,7 @@ char *tracefs_get_tracing_file(const char *name)
  * tracefs_put_tracing_file - Free tracing file or directory name
  *
  * Frees tracing file or directory, returned by
- * tracefs_get_tracing_file() or tracefs_get_tracing_dir() APIs
+ * tracefs_get_tracing_file() API
  */
 void tracefs_put_tracing_file(char *name)
 {
diff --git a/tracecmd/trace-check-events.c b/tracecmd/trace-check-events.c
index 1dadb046..0fa9082c 100644
--- a/tracecmd/trace-check-events.c
+++ b/tracecmd/trace-check-events.c
@@ -29,7 +29,7 @@ void trace_check_events(int argc, char **argv)
 			break;
 		}
 	}
-	tracing = tracefs_get_tracing_dir();
+	tracing = tracefs_tracing_dir();
 
 	if (!tracing) {
 		printf("Can not find or mount tracing directory!\n"
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index e7d637f5..4a622d59 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -169,7 +169,7 @@ static void test_trace_file(void)
 	CU_TEST(stat(dir, &st) == 0);
 	CU_TEST(S_ISDIR(st.st_mode));
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 	CU_TEST(stat(tdir, &st) == 0);
 	CU_TEST(S_ISDIR(st.st_mode));
@@ -192,7 +192,7 @@ static void test_trace_file(void)
 
 static void test_instance_file_read(struct tracefs_instance *inst, char *fname)
 {
-	const char *tdir  = tracefs_get_tracing_dir();
+	const char *tdir  = tracefs_tracing_dir();
 	char buf[BUFSIZ];
 	char *fpath;
 	char *file;
@@ -244,7 +244,7 @@ static void test_instance_file(void)
 	int size;
 	int ret;
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 	CU_TEST(asprintf(&inst_dir, "%s/instances/%s", tdir, name) > 0);
 	CU_TEST(stat(inst_dir, &st) != 0);
@@ -369,7 +369,7 @@ static void test_system_event(void)
 	char **events;
 	char *sdir = NULL;
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 
 	systems = tracefs_event_systems(tdir);
@@ -402,7 +402,7 @@ static void test_tracers(void)
 	char *tracer;
 	int i;
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 
 	tracers = tracefs_tracers(tdir);
@@ -433,7 +433,7 @@ static void test_check_events(struct tep_handle *tep, char *system, bool exist)
 	DIR *dir;
 	int fd;
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 
 	asprintf(&edir, "%s/events/%s", tdir, system);
@@ -470,7 +470,7 @@ static void test_local_events(void)
 	char *lsystems[3];
 	int i;
 
-	tdir  = tracefs_get_tracing_dir();
+	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 
 	tep = tracefs_local_events(tdir);
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] trace-cmd: Use tracefs_tracing_dir() instead of tracefs_find_tracing_dir()
  2020-12-22  5:06 [PATCH 0/2] Remove tracefs_get_tracing_dir() API Tzvetomir Stoyanov (VMware)
  2020-12-22  5:06 ` [PATCH 1/2] trace-cmd: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir() Tzvetomir Stoyanov (VMware)
@ 2020-12-22  5:06 ` Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-22  5:06 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The tracefs_find_tracing_dir() and tracefs_tracing_dir() are
consolidated. All usage of tracefs_find_tracing_dir() are replaced with
calls to tracefs_tracing_dir().

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs/tracefs.h           |  3 ---
 lib/trace-cmd/trace-output.c        |  7 +++++--
 lib/tracefs/include/tracefs-local.h |  2 ++
 lib/tracefs/tracefs-instance.c      |  2 +-
 lib/tracefs/tracefs-utils.c         |  8 ++++----
 tracecmd/trace-record.c             | 19 ++++++++++++-------
 utest/tracefs-utest.c               |  9 ---------
 7 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h
index 8308e3ac..9a99ad6c 100644
--- a/include/tracefs/tracefs.h
+++ b/include/tracefs/tracefs.h
@@ -15,9 +15,6 @@ void tracefs_put_tracing_file(char *name);
 /* The returned string must *not* be freed */
 const char *tracefs_tracing_dir(void);
 
-/* tracefs_find_tracing_dir must be freed */
-char *tracefs_find_tracing_dir(void);
-
 /* ftarce instances */
 struct tracefs_instance;
 
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index cd7dcec8..de76e3e7 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -240,9 +240,12 @@ static tsize_t copy_file(struct tracecmd_output *handle,
  */
 static const char *find_tracing_dir(struct tracecmd_output *handle)
 {
-	if (!handle->tracing_dir)
-		handle->tracing_dir = tracefs_find_tracing_dir();
+	if (!handle->tracing_dir) {
+		const char *dir = tracefs_tracing_dir();
 
+		if (dir)
+			handle->tracing_dir = strdup(dir);
+	}
 	return handle->tracing_dir;
 }
 
diff --git a/lib/tracefs/include/tracefs-local.h b/lib/tracefs/include/tracefs-local.h
index bdbf89e8..c222fe4f 100644
--- a/lib/tracefs/include/tracefs-local.h
+++ b/lib/tracefs/include/tracefs-local.h
@@ -13,6 +13,8 @@ void warning(const char *fmt, ...);
 int str_read_file(const char *file, char **buffer);
 char *trace_append_file(const char *dir, const char *name);
 
+char *trace_find_tracing_dir(void);
+
 #ifndef ACCESSPERMS
 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
 #endif
diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c
index e9e24ef8..bf3de7cc 100644
--- a/lib/tracefs/tracefs-instance.c
+++ b/lib/tracefs/tracefs-instance.c
@@ -210,7 +210,7 @@ char *tracefs_instance_get_dir(struct tracefs_instance *instance)
 		path = tracefs_get_tracing_file(buf);
 		free(buf);
 	} else
-		path = tracefs_find_tracing_dir();
+		path = trace_find_tracing_dir();
 
 	return path;
 }
diff --git a/lib/tracefs/tracefs-utils.c b/lib/tracefs/tracefs-utils.c
index 8483cb61..acfcacf7 100644
--- a/lib/tracefs/tracefs-utils.c
+++ b/lib/tracefs/tracefs-utils.c
@@ -60,12 +60,12 @@ static int mount_debugfs(void)
 }
 
 /**
- * tracefs_find_tracing_dir - Find tracing directory
+ * trace_find_tracing_dir - Find tracing directory
  *
  * Returns string containing the full path to the system's tracing directory.
  * The string must be freed by free()
  */
-char *tracefs_find_tracing_dir(void)
+char *trace_find_tracing_dir(void)
 {
 	char *debug_str = NULL;
 	char fspath[PATH_MAX+1];
@@ -143,7 +143,7 @@ const char *tracefs_tracing_dir(void)
 	if (tracing_dir)
 		return tracing_dir;
 
-	tracing_dir = tracefs_find_tracing_dir();
+	tracing_dir = trace_find_tracing_dir();
 	return tracing_dir;
 }
 
@@ -166,7 +166,7 @@ char *tracefs_get_tracing_file(const char *name)
 		return NULL;
 
 	if (!tracing) {
-		tracing = tracefs_find_tracing_dir();
+		tracing = trace_find_tracing_dir();
 		if (!tracing)
 			return NULL;
 	}
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index e2d1cedf..ade52421 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -450,13 +450,11 @@ static int __add_all_instances(const char *tracing_dir)
  */
 void add_all_instances(void)
 {
-	char *tracing_dir = tracefs_find_tracing_dir();
+	const char *tracing_dir = tracefs_tracing_dir();
 	if (!tracing_dir)
-		die("malloc");
+		die("can't get the tracing directory");
 
 	__add_all_instances(tracing_dir);
-
-	tracefs_put_tracing_file(tracing_dir);
 }
 
 /**
@@ -3539,10 +3537,17 @@ static int create_recorder(struct buffer_instance *instance, int cpu,
 		}
 		if (fd < 0)
 			die("Failed connecting to client");
-		if (tracefs_instance_get_name(instance->tracefs) && !is_agent(instance))
+		if (tracefs_instance_get_name(instance->tracefs) && !is_agent(instance)) {
 			path = tracefs_instance_get_dir(instance->tracefs);
-		else
-			path = tracefs_find_tracing_dir();
+		} else {
+			const char *dir = tracefs_tracing_dir();
+
+			if (dir)
+				path = strdup(path);
+		}
+		if (!path)
+			die("can't get the tracing directory");
+
 		recorder = tracecmd_create_buffer_recorder_fd(fd, cpu, flags, path);
 		tracefs_put_tracing_file(path);
 	} else {
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 4a622d59..9c9eee06 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -162,21 +162,12 @@ static void test_trace_file(void)
 	const char *tdir;
 	struct stat st;
 	char *file;
-	char *dir;
-
-	dir = tracefs_find_tracing_dir();
-	CU_TEST(dir != NULL);
-	CU_TEST(stat(dir, &st) == 0);
-	CU_TEST(S_ISDIR(st.st_mode));
 
 	tdir  = tracefs_tracing_dir();
 	CU_TEST(tdir != NULL);
 	CU_TEST(stat(tdir, &st) == 0);
 	CU_TEST(S_ISDIR(st.st_mode));
 
-	CU_TEST(strcmp(dir, tdir) == 0);
-	free(dir);
-
 	file = tracefs_get_tracing_file(NULL);
 	CU_TEST(file == NULL);
 	file = tracefs_get_tracing_file(tmp);
-- 
2.28.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22  5:06 [PATCH 0/2] Remove tracefs_get_tracing_dir() API Tzvetomir Stoyanov (VMware)
2020-12-22  5:06 ` [PATCH 1/2] trace-cmd: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir() Tzvetomir Stoyanov (VMware)
2020-12-22  5:06 ` [PATCH 2/2] trace-cmd: Use tracefs_tracing_dir() instead of tracefs_find_tracing_dir() Tzvetomir Stoyanov (VMware)

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