diff mbox series

[v2,1/2] rt-utils: Add option to avoid stopping tracing in tracemark()

Message ID 20210714110718.68292-1-nsaenzju@redhat.com
State New
Headers show
Series [v2,1/2] rt-utils: Add option to avoid stopping tracing in tracemark() | expand

Commit Message

Nicolas Saenz Julienne July 14, 2021, 11:07 a.m. UTC
Not all users of tracemark() might want to stop tracing after printing a
mark. For example, if leaving a mark during a test. So add an extra
argument to tracemark() which avoid the stop.

Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
---

Changes since v1:
 - Add stdbool.h include in rt-utils.h

 src/cyclictest/cyclictest.c | 3 ++-
 src/include/rt-utils.h      | 3 ++-
 src/lib/rt-utils.c          | 6 ++++--
 src/oslat/oslat.c           | 2 +-
 4 files changed, 9 insertions(+), 5 deletions(-)

Comments

John Kacur July 30, 2021, 8:28 p.m. UTC | #1
On Wed, 14 Jul 2021, Nicolas Saenz Julienne wrote:

> Not all users of tracemark() might want to stop tracing after printing a

> mark. For example, if leaving a mark during a test. So add an extra

> argument to tracemark() which avoid the stop.

> 

> Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>

> ---

> 

> Changes since v1:

>  - Add stdbool.h include in rt-utils.h

> 

>  src/cyclictest/cyclictest.c | 3 ++-

>  src/include/rt-utils.h      | 3 ++-

>  src/lib/rt-utils.c          | 6 ++++--

>  src/oslat/oslat.c           | 2 +-

>  4 files changed, 9 insertions(+), 5 deletions(-)

> 

> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c

> index a08c91d..1f3c5a2 100644

> --- a/src/cyclictest/cyclictest.c

> +++ b/src/cyclictest/cyclictest.c

> @@ -12,6 +12,7 @@

>  #include <stdlib.h>

>  #include <stdint.h>

>  #include <stdarg.h>

> +#include <stdbool.h>

>  #include <unistd.h>

>  #include <fcntl.h>

>  #include <getopt.h>

> @@ -722,7 +723,7 @@ static void *timerthread(void *param)

>  			pthread_mutex_lock(&break_thread_id_lock);

>  			if (break_thread_id == 0) {

>  				break_thread_id = stat->tid;

> -				tracemark("hit latency threshold (%llu > %d)",

> +				tracemark(true, "hit latency threshold (%llu > %d)",

>  					  (unsigned long long) diff, tracelimit);

>  				break_thread_value = diff;

>  			}

> diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h

> index f6b3fed..5b3d34d 100644

> --- a/src/include/rt-utils.h

> +++ b/src/include/rt-utils.h

> @@ -3,6 +3,7 @@

>  #define __RT_UTILS_H

>  

>  #include <stdint.h>

> +#include <stdbool.h>

>  

>  #define _STR(x) #x

>  #define STR(x) _STR(x)

> @@ -31,7 +32,7 @@ int parse_time_string(char *val);

>  int parse_mem_string(char *str, uint64_t *val);

>  

>  void enable_trace_mark(void);

> -void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));

> +void tracemark(bool stop, char *fmt, ...) __attribute__((format(printf, 2, 3)));

>  void disable_trace_mark(void);

>  

>  #define MSEC_PER_SEC		1000

> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c

> index 6c0235d..d8d1325 100644

> --- a/src/lib/rt-utils.c

> +++ b/src/lib/rt-utils.c

> @@ -23,6 +23,7 @@

>  #include <sys/utsname.h>

>  #include <time.h>

>  #include <sys/time.h>

> +#include <stdbool.h>

>  

>  #include "rt-utils.h"

>  #include "rt-sched.h"

> @@ -458,7 +459,7 @@ static void debugfs_prepare(void)

>  		     "debug fs not mounted");

>  }

>  

> -void tracemark(char *fmt, ...)

> +void tracemark(bool stop, char *fmt, ...)

>  {

>  	va_list ap;

>  	int len;

> @@ -476,7 +477,8 @@ void tracemark(char *fmt, ...)

>  	write(tracemark_fd, tracebuf, len);

>  

>  	/* now stop any trace */

> -	write(trace_fd, "0\n", 2);

> +	if (stop)

> +		write(trace_fd, "0\n", 2);

>  }

>  

>  void enable_trace_mark(void)

> diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c

> index 6ff5ba8..d35be57 100644

> --- a/src/oslat/oslat.c

> +++ b/src/oslat/oslat.c

> @@ -304,7 +304,7 @@ static void insert_bucket(struct thread *t, stamp_t value)

>  	if (!g.preheat && g.trace_threshold && us >= g.trace_threshold) {

>  		char *line = "%s: Trace threshold (%d us) triggered with %u us!\n"

>  		    "Stopping the test.\n";

> -		tracemark(line, g.app_name, g.trace_threshold, us);

> +		tracemark(true, line, g.app_name, g.trace_threshold, us);

>  		err_quit(line, g.app_name, g.trace_threshold, us);

>  	}

>  

> -- 

> 2.31.1

> 

> 


I'm curious as to how you are running this?
What I would do is, something like this
trace-cmd record -p function ./oslat -T100
I have no end to the amount of data it generates.

John
diff mbox series

Patch

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index a08c91d..1f3c5a2 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -12,6 +12,7 @@ 
 #include <stdlib.h>
 #include <stdint.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -722,7 +723,7 @@  static void *timerthread(void *param)
 			pthread_mutex_lock(&break_thread_id_lock);
 			if (break_thread_id == 0) {
 				break_thread_id = stat->tid;
-				tracemark("hit latency threshold (%llu > %d)",
+				tracemark(true, "hit latency threshold (%llu > %d)",
 					  (unsigned long long) diff, tracelimit);
 				break_thread_value = diff;
 			}
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index f6b3fed..5b3d34d 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -3,6 +3,7 @@ 
 #define __RT_UTILS_H
 
 #include <stdint.h>
+#include <stdbool.h>
 
 #define _STR(x) #x
 #define STR(x) _STR(x)
@@ -31,7 +32,7 @@  int parse_time_string(char *val);
 int parse_mem_string(char *str, uint64_t *val);
 
 void enable_trace_mark(void);
-void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void tracemark(bool stop, char *fmt, ...) __attribute__((format(printf, 2, 3)));
 void disable_trace_mark(void);
 
 #define MSEC_PER_SEC		1000
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 6c0235d..d8d1325 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -23,6 +23,7 @@ 
 #include <sys/utsname.h>
 #include <time.h>
 #include <sys/time.h>
+#include <stdbool.h>
 
 #include "rt-utils.h"
 #include "rt-sched.h"
@@ -458,7 +459,7 @@  static void debugfs_prepare(void)
 		     "debug fs not mounted");
 }
 
-void tracemark(char *fmt, ...)
+void tracemark(bool stop, char *fmt, ...)
 {
 	va_list ap;
 	int len;
@@ -476,7 +477,8 @@  void tracemark(char *fmt, ...)
 	write(tracemark_fd, tracebuf, len);
 
 	/* now stop any trace */
-	write(trace_fd, "0\n", 2);
+	if (stop)
+		write(trace_fd, "0\n", 2);
 }
 
 void enable_trace_mark(void)
diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index 6ff5ba8..d35be57 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -304,7 +304,7 @@  static void insert_bucket(struct thread *t, stamp_t value)
 	if (!g.preheat && g.trace_threshold && us >= g.trace_threshold) {
 		char *line = "%s: Trace threshold (%d us) triggered with %u us!\n"
 		    "Stopping the test.\n";
-		tracemark(line, g.app_name, g.trace_threshold, us);
+		tracemark(true, line, g.app_name, g.trace_threshold, us);
 		err_quit(line, g.app_name, g.trace_threshold, us);
 	}