linux-btrace.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Removed empty data files
@ 2009-02-17 14:04 Alan D. Brunelle
  2009-02-19  9:21 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Alan D. Brunelle @ 2009-02-17 14:04 UTC (permalink / raw)
  To: linux-btrace

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Does anybody rely upon _all_ of the blktrace.X files being generated
(even if they are 0-lengthed)?


[-- Attachment #2: 0001-Removed-empty-data-files.patch --]
[-- Type: text/x-diff, Size: 1380 bytes --]

From 1da4effb9b61928b6475ac0cba05a1f32468185e Mon Sep 17 00:00:00 2001
From: Alan D. Brunelle <alan.brunelle@hp.com>
Date: Tue, 17 Feb 2009 09:01:04 -0500
Subject: [PATCH] Removed empty data files

It's not unusual to have lots of empty blktrace files, this unlinks
files at the end of the run that are empty.

Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com>
---
 blktrace.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/blktrace.c b/blktrace.c
index 26b3afd..2695a33 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -1509,6 +1509,17 @@ static int set_vbuf(struct io_info *iop, int mode, size_t size)
 	return 0;
 }
 
+static void iop_close(struct io_info *iop)
+{
+	if (iop) {
+		struct stat buf;
+
+		fclose(iop->ofp);
+		if (!stat(iop->ofn, &buf) && (buf.st_size == 0))
+			unlink(iop->ofn);
+	}
+}
+
 static int iop_open(struct io_info *iop, int cpu)
 {
 	iop->ofd = -1;
@@ -1525,7 +1536,7 @@ static int iop_open(struct io_info *iop, int cpu)
 	if (set_vbuf(iop, _IOLBF, FILE_VBUF_SIZE)) {
 		fprintf(stderr, "set_vbuf for file %s failed: %d/%s\n",
 			iop->ofn, errno, strerror(errno));
-		fclose(iop->ofp);
+		iop_close(iop);
 		return 1;
 	}
 
@@ -1548,8 +1559,7 @@ static void close_iop(struct io_info *iop)
 		}
 	}
 
-	if (iop->ofp)
-		fclose(iop->ofp);
+	iop_close(iop);
 	if (iop->obuf)
 		free(iop->obuf);
 }
-- 
1.5.6.3


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

* Re: [PATCH] Removed empty data files
  2009-02-17 14:04 [PATCH] Removed empty data files Alan D. Brunelle
@ 2009-02-19  9:21 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2009-02-19  9:21 UTC (permalink / raw)
  To: linux-btrace

On Tue, Feb 17 2009, Alan D. Brunelle wrote:
> Does anybody rely upon _all_ of the blktrace.X files being generated
> (even if they are 0-lengthed)?

If blkparse handles it, I think it's good enough...

> 

> From 1da4effb9b61928b6475ac0cba05a1f32468185e Mon Sep 17 00:00:00 2001
> From: Alan D. Brunelle <alan.brunelle@hp.com>
> Date: Tue, 17 Feb 2009 09:01:04 -0500
> Subject: [PATCH] Removed empty data files
> 
> It's not unusual to have lots of empty blktrace files, this unlinks
> files at the end of the run that are empty.
> 
> Signed-off-by: Alan D. Brunelle <alan.brunelle@hp.com>
> ---
>  blktrace.c |   16 +++++++++++++---
>  1 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/blktrace.c b/blktrace.c
> index 26b3afd..2695a33 100644
> --- a/blktrace.c
> +++ b/blktrace.c
> @@ -1509,6 +1509,17 @@ static int set_vbuf(struct io_info *iop, int mode, size_t size)
>  	return 0;
>  }
>  
> +static void iop_close(struct io_info *iop)
> +{
> +	if (iop) {
> +		struct stat buf;
> +
> +		fclose(iop->ofp);
> +		if (!stat(iop->ofn, &buf) && (buf.st_size = 0))
> +			unlink(iop->ofn);
> +	}
> +}
> +
>  static int iop_open(struct io_info *iop, int cpu)
>  {
>  	iop->ofd = -1;
> @@ -1525,7 +1536,7 @@ static int iop_open(struct io_info *iop, int cpu)
>  	if (set_vbuf(iop, _IOLBF, FILE_VBUF_SIZE)) {
>  		fprintf(stderr, "set_vbuf for file %s failed: %d/%s\n",
>  			iop->ofn, errno, strerror(errno));
> -		fclose(iop->ofp);
> +		iop_close(iop);
>  		return 1;
>  	}
>  
> @@ -1548,8 +1559,7 @@ static void close_iop(struct io_info *iop)
>  		}
>  	}
>  
> -	if (iop->ofp)
> -		fclose(iop->ofp);
> +	iop_close(iop);
>  	if (iop->obuf)
>  		free(iop->obuf);
>  }
> -- 
> 1.5.6.3
> 


-- 
Jens Axboe


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

end of thread, other threads:[~2009-02-19  9:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-17 14:04 [PATCH] Removed empty data files Alan D. Brunelle
2009-02-19  9:21 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).