diff mbox series

[6/7] trace-cmd: Refactored make_instances() and tracecmd_remove_instances()

Message ID 20190116191838.32127-7-tstoyanov@vmware.com (mailing list archive)
State Superseded
Headers show
Series trace-cmd [POC]: Timestamps sync using PTP-like algorithm, relying on vsock events. | expand

Commit Message

Tzvetomir Stoyanov Jan. 16, 2019, 7:18 p.m. UTC
In order to reuse the code which creates / deletes tracing instances,
these two functions are refactotred. A new ones are implemented:
make_one_instances() and tracecmd_remove_one_instance().

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 tracecmd/trace-record.c | 54 +++++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

Comments

Steven Rostedt Jan. 21, 2019, 9:13 a.m. UTC | #1
On Wed, 16 Jan 2019 21:18:37 +0200
Tzvetomir Stoyanov <tstoyanov@vmware.com> wrote:


> --- a/tracecmd/trace-record.c
> +++ b/tracecmd/trace-record.c
> @@ -4260,49 +4260,57 @@ static void clear_func_filters(void)
>  	}
>  }
>  
> -static void make_instances(void)
> +static void make_one_instances(struct buffer_instance *instance)

> +static void tracecmd_remove_one_instance(struct buffer_instance *instance)


I would just make the names non plural, and call them:

make_one_instance()
tracecmd_remove_instance()

-- Steve
diff mbox series

Patch

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 900d0d4..4c3df3d 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4260,49 +4260,57 @@  static void clear_func_filters(void)
 	}
 }
 
-static void make_instances(void)
+static void make_one_instances(struct buffer_instance *instance)
 {
-	struct buffer_instance *instance;
 	struct stat st;
 	char *path;
 	int ret;
 
+	path = get_instance_dir(instance);
+	ret = stat(path, &st);
+	if (ret < 0) {
+		ret = mkdir(path, 0777);
+		if (ret < 0)
+			die("mkdir %s", path);
+	} else
+		/* Don't delete instances that already exist */
+		instance->flags |= BUFFER_FL_KEEP;
+	tracecmd_put_tracing_file(path);
+
+}
+
+static void make_instances(void)
+{
+	struct buffer_instance *instance;
+
 	for_each_instance(instance) {
 		if (instance->flags & BUFFER_FL_GUEST)
 			continue;
+		make_one_instances(instance);
+	}
+}
 
-		path = get_instance_dir(instance);
-		ret = stat(path, &st);
-		if (ret < 0) {
-			ret = mkdir(path, 0777);
-			if (ret < 0)
-				die("mkdir %s", path);
-		} else
-			/* Don't delete instances that already exist */
-			instance->flags |= BUFFER_FL_KEEP;
-		tracecmd_put_tracing_file(path);
+static void tracecmd_remove_one_instance(struct buffer_instance *instance)
+{
+	char *path;
+
+	if (instance->tracing_on_fd > 0) {
+		close(instance->tracing_on_fd);
+		instance->tracing_on_fd = 0;
 	}
+	path = get_instance_dir(instance);
+	tracecmd_put_tracing_file(path);
 }
 
 void tracecmd_remove_instances(void)
 {
 	struct buffer_instance *instance;
-	char *path;
-	int ret;
 
 	for_each_instance(instance) {
 		/* Only delete what we created */
 		if (instance->flags & (BUFFER_FL_KEEP | BUFFER_FL_GUEST))
 			continue;
-		if (instance->tracing_on_fd > 0) {
-			close(instance->tracing_on_fd);
-			instance->tracing_on_fd = 0;
-		}
-		path = get_instance_dir(instance);
-		ret = rmdir(path);
-		if (ret < 0)
-			die("rmdir %s", path);
-		tracecmd_put_tracing_file(path);
+		tracecmd_remove_one_instance(instance);
 	}
 }