Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/2] Consolidate APIs to locate tracefs mount point.
@ 2020-12-21  7:29 Tzvetomir Stoyanov (VMware)
  2020-12-21  7:29 ` [PATCH v2 1/2] libtracefs: Remove tracefs_find_tracing_dir() API Tzvetomir Stoyanov (VMware)
  2020-12-21  7:29 ` [PATCH v2 2/2] libtracefs: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir() Tzvetomir Stoyanov (VMware)
  0 siblings, 2 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-21  7:29 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()

v2 changes:
 - Made the new local trace_find_tracing_dir() function hidden.

Tzvetomir Stoyanov (VMware) (2):
  libtracefs: Remove tracefs_find_tracing_dir() API
  libtracefs: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir()

 include/tracefs-local.h |  2 ++
 include/tracefs.h       |  7 ++-----
 src/tracefs-events.c    |  8 ++++----
 src/tracefs-instance.c  |  2 +-
 src/tracefs-utils.c     | 14 +++++++-------
 test.c                  |  2 +-
 utest/tracefs-utest.c   | 23 +++++++----------------
 7 files changed, 24 insertions(+), 34 deletions(-)

-- 
2.28.0


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

* [PATCH v2 1/2] libtracefs: Remove tracefs_find_tracing_dir() API
  2020-12-21  7:29 [PATCH v2 0/2] Consolidate APIs to locate tracefs mount point Tzvetomir Stoyanov (VMware)
@ 2020-12-21  7:29 ` Tzvetomir Stoyanov (VMware)
  2020-12-21  7:29 ` [PATCH v2 2/2] libtracefs: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir() Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-21  7:29 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

There are two APIs to get the tracefs mount point:
tracefs_get_tracing_dir() and tracefs_find_tracing_dir().
The only difference between them is that the first returns
a static cashed string and the second a newly allocated string.
In order not to confused the users with too many APIs that do
the same, the tracefs_find_tracing_dir() is removed as an API,
renamed to trace_find_tracing_dir() and is used only as library
internal function.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs-local.h | 2 ++
 include/tracefs.h       | 3 ---
 src/tracefs-instance.c  | 2 +-
 src/tracefs-utils.c     | 8 ++++----
 utest/tracefs-utest.c   | 9 ---------
 5 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index bdbf89e..3a7ec32 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -10,8 +10,10 @@
 
 /* Can be overridden */
 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 */
diff --git a/include/tracefs.h b/include/tracefs.h
index 5cbe898..ae4ffa0 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -15,9 +15,6 @@ void tracefs_put_tracing_file(char *name);
 /* tracefs_get_tracing_dir must *not* be freed */
 const char *tracefs_get_tracing_dir(void);
 
-/* tracefs_find_tracing_dir must be freed */
-char *tracefs_find_tracing_dir(void);
-
 /* ftrace instances */
 struct tracefs_instance;
 
diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index e9e24ef..bf3de7c 100644
--- a/src/tracefs-instance.c
+++ b/src/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/src/tracefs-utils.c b/src/tracefs-utils.c
index 326b455..d9850d9 100644
--- a/src/tracefs-utils.c
+++ b/src/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)
+__hidden char *trace_find_tracing_dir(void)
 {
 	char *debug_str = NULL;
 	char fspath[PATH_MAX+1];
@@ -143,7 +143,7 @@ const char *tracefs_get_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/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 941b9cf..965f1ec 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_get_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

* [PATCH v2 2/2] libtracefs: Rename tracefs_get_tracing_dir() to tracefs_tracing_dir()
  2020-12-21  7:29 [PATCH v2 0/2] Consolidate APIs to locate tracefs mount point Tzvetomir Stoyanov (VMware)
  2020-12-21  7:29 ` [PATCH v2 1/2] libtracefs: Remove tracefs_find_tracing_dir() API Tzvetomir Stoyanov (VMware)
@ 2020-12-21  7:29 ` Tzvetomir Stoyanov (VMware)
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-12-21  7:29 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The tracefs_get_tracing_dir() API mounts, locates and returns tracefs
mount point. In order to reflect more closely its logic, it is renamed
to tracefs_tracing_dir().

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/tracefs.h     |  4 ++--
 src/tracefs-events.c  |  8 ++++----
 src/tracefs-utils.c   |  6 +++---
 test.c                |  2 +-
 utest/tracefs-utest.c | 14 +++++++-------
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/tracefs.h b/include/tracefs.h
index ae4ffa0..3d70aca 100644
--- a/include/tracefs.h
+++ b/include/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);
 
 /* ftrace instances */
 struct tracefs_instance;
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 58fa153..825f916 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -268,7 +268,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;
@@ -342,7 +342,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;
@@ -407,7 +407,7 @@ char **tracefs_tracers(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;
@@ -544,7 +544,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/src/tracefs-utils.c b/src/tracefs-utils.c
index d9850d9..0e96f8e 100644
--- a/src/tracefs-utils.c
+++ b/src/tracefs-utils.c
@@ -131,12 +131,12 @@ __hidden char *trace_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/test.c b/test.c
index daf99d6..d38fc92 100644
--- a/test.c
+++ b/test.c
@@ -2,6 +2,6 @@
 
 int main()
 {
-	tracefs_get_tracing_dir();
+	tracefs_tracing_dir();
 	return 0;
 }
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 965f1ec..b45a3c6 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -163,7 +163,7 @@ static void test_trace_file(void)
 	struct stat st;
 	char *file;
 
-	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));
@@ -183,7 +183,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;
@@ -235,7 +235,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);
@@ -360,7 +360,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);
@@ -393,7 +393,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);
@@ -424,7 +424,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);
@@ -461,7 +461,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

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-21  7:29 [PATCH v2 0/2] Consolidate APIs to locate tracefs mount point Tzvetomir Stoyanov (VMware)
2020-12-21  7:29 ` [PATCH v2 1/2] libtracefs: Remove tracefs_find_tracing_dir() API Tzvetomir Stoyanov (VMware)
2020-12-21  7:29 ` [PATCH v2 2/2] libtracefs: Rename tracefs_get_tracing_dir() to tracefs_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