This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] staprun: use rotatingly-named log file


Currently we can use '-s' option to specify the maximum of output
file and he maximum number of output files i.e.,
 $ stap -F -o test.output -S 128,10 test.stp

The issue here is the output file names will be from test.output.0
to test.output.INT_MAX, that's not friendly if we continuesly run
sysemtap.

We'd better use rotatingly-named log file, as a result the output
file name will be from output_filename.0 to output_filename.(N-1)
and then rotate begin with output_filename.0.

- Why not keep the old file and just tuncate it?
Because we always use the file creation event to judge that we stop
writing the current file and begin to write to the next file.
So we'd better remove the old file and create a new one.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 staprun/relay.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/staprun/relay.c b/staprun/relay.c
index c87bef4..3cda0eb 100644
--- a/staprun/relay.c
+++ b/staprun/relay.c
@@ -84,8 +84,8 @@ static int open_outfile(int fnum, int cpu, int remove_file)
 	if (fnum_max) {
 		if (remove_file) {
 			 /* remove oldest file */
-			if (make_outfile_name(buf, PATH_MAX, fnum - fnum_max,
-				 cpu, read_backlog(cpu, fnum - fnum_max),
+			if (make_outfile_name(buf, PATH_MAX, fnum,
+				 cpu, read_backlog(cpu, fnum),
 				 bulkmode) < 0)
 				return -1;
 			remove(buf); /* don't care */
@@ -105,17 +105,23 @@ static int open_outfile(int fnum, int cpu, int remove_file)
 
 static int switch_outfile(int cpu, int *fnum)
 {
-	int remove_file = 0;
+	static int remove_file = 0;
 
 	dbug(3, "thread %d switching file\n", cpu);
 	close(out_fd[cpu]);
+
 	*fnum += 1;
-	if (fnum_max && *fnum >= fnum_max)
-		remove_file = 1;
+	if (fnum_max && *fnum >= fnum_max) {
+		*fnum = 0;
+		if (!remove_file)
+			remove_file = 1;
+	}
+
 	if (open_outfile(*fnum, cpu, remove_file) < 0) {
 		perr("Couldn't open file for cpu %d, exiting.", cpu);
 		return -1;
 	}
+
 	return 0;
 }
 
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]