[Patch 1/13] iostats

2007-07-24 Thread Girish Shilamkar
This patch instruments the libext2fs unix I/O manager and adds bytes 
read/written and data rate to e2fsck -tt pass/overall timing output.

Signed-off-by: Jim Garlick <[EMAIL PROTECTED]>

Index: e2fsprogs-1.40.1/lib/ext2fs/unix_io.c
===
--- e2fsprogs-1.40.1.orig/lib/ext2fs/unix_io.c
+++ e2fsprogs-1.40.1/lib/ext2fs/unix_io.c
@@ -70,6 +70,7 @@ struct unix_private_data {
int access_time;
ext2_loff_t offset;
struct unix_cache cache[CACHE_SIZE];
+   struct struct_io_stats io_stats;
 };
 
 static errcode_t unix_open(const char *name, int flags, io_channel *channel);
@@ -84,6 +85,8 @@ static errcode_t unix_write_byte(io_chan
int size, const void *data);
 static errcode_t unix_set_option(io_channel channel, const char *option, 
 const char *arg);
+static errcode_t unix_get_stats(io_channel channel,
+   struct struct_io_stats *stats);
 
 static void reuse_cache(io_channel channel, struct unix_private_data *data,
 struct unix_cache *cache, unsigned long block);
@@ -110,11 +113,29 @@ static struct struct_io_manager struct_u
 #else
unix_write_byte,
 #endif
-   unix_set_option
+   unix_set_option,
+   unix_get_stats,
 };
 
 io_manager unix_io_manager = &struct_unix_manager;
 
+static errcode_t unix_get_stats(io_channel channel,
+   struct struct_io_stats *stats)
+{
+   errcode_t   retval = 0;
+
+   struct unix_private_data *data;
+
+   EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+   data = (struct unix_private_data *) channel->private_data;
+   EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+
+   if (stats)
+   *stats = data->io_stats;
+
+   return retval;
+}
+
 /*
  * Here are the raw I/O functions
  */
@@ -130,6 +151,7 @@ static errcode_t raw_read_blk(io_channel
int actual = 0;
 
size = (count < 0) ? -count : count * channel->block_size;
+   data->io_stats.reads += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
@@ -168,6 +190,7 @@ static errcode_t raw_read_blk(io_channel
charsector[BLOCKALIGN];
 
size = (count < 0) ? -count : count * channel->block_size;
+   data->io_stats.reads += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
 #ifdef DEBUG
printf("count=%d, size=%d, block=%lu, blk_size=%d, location=%llx\n",
@@ -224,6 +247,7 @@ static errcode_t raw_write_blk(io_channe
else
size = count * channel->block_size;
}
+   data->io_stats.writes += size;
 
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
Index: e2fsprogs-1.40.1/lib/ext2fs/ext2_io.h
===
--- e2fsprogs-1.40.1.orig/lib/ext2fs/ext2_io.h
+++ e2fsprogs-1.40.1/lib/ext2fs/ext2_io.h
@@ -55,6 +55,11 @@ struct struct_io_channel {
void*app_data;
 };
 
+struct struct_io_stats {
+   unsigned long long reads;
+   unsigned long long writes;
+};
+
 struct struct_io_manager {
errcode_t magic;
const char *name;
@@ -70,6 +75,8 @@ struct struct_io_manager {
int count, const void *data);
errcode_t (*set_option)(io_channel channel, const char *option, 
const char *arg);
+   errcode_t (*get_stats)(io_channel channel,
+  struct struct_io_stats *io_stats);
int reserved[14];
 };
 
Index: e2fsprogs-1.40.1/e2fsck/e2fsck.h
===
--- e2fsprogs-1.40.1.orig/e2fsck/e2fsck.h
+++ e2fsprogs-1.40.1/e2fsck/e2fsck.h
@@ -135,6 +135,7 @@ struct resource_track {
struct timeval user_start;
struct timeval system_start;
void*brk_start;
+   struct struct_io_stats io_start;
 };
 #endif
 
@@ -469,8 +470,10 @@ extern void preenhalt(e2fsck_t ctx);
 extern char *string_copy(e2fsck_t ctx, const char *str, int len);
 #ifdef RESOURCE_TRACK
 extern void print_resource_track(const char *desc,
-struct resource_track *track);
-extern void init_resource_track(struct resource_track *track);
+struct resource_track *track,
+io_channel channel);
+extern void init_resource_track(struct resource_track *track,
+   io_channel channel);
 #endif
 extern int inode_has_valid_blocks(struct ext2_inode *inode);
 extern void e2fsck_read_inode(e2fsck_t ctx, 

Re: [Patch 1/13] iostats

2007-07-24 Thread Theodore Tso
On Tue, Jul 24, 2007 at 04:34:36PM +0530, Girish Shilamkar wrote:
>  
> +struct struct_io_stats {
> + unsigned long long reads;
> + unsigned long long writes;
> +};

I'd suggest doing something like this instead:

struct struct_io_stats {
int num_fields;
int reserved;
unsigned long long bytes_read;
unsigned long long bytes_written;
};

There are other statistics that you might want to gather.  For
example, "read_requests" and "write_requests".  Or perhaps some
statistics based on discontiguous read/writes (i.e., i/o operations
that cause seeks).  Also, in the future we might want to add some kind
of readahead functionality, and that would probably require more
statistics as well.

> + memset(&track->io_start, 0, sizeof(struct struct_io_stats));
> + if (channel && channel->manager && channel->manager->get_stats)
> + channel->manager->get_stats(channel, &track->io_start);
>  }

If you're going to use a caller allocates paradigm, then the caller
would be responsible for doing this:

  track->io_start.num_fields = 2;

... so the library routine knows how much of the structure it is safe
for it to fill in.  Alternatively, it might be easier to simply have
the io_manager pass back a pointer to its own stats structure, and
then the caller would use the num_fields_size to figure out how much
of the structure it can trust.

- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Patch 1/13] iostats

2007-08-03 Thread Theodore Tso
On Tue, Jul 24, 2007 at 04:34:36PM +0530, Girish Shilamkar wrote:
> This patch instruments the libext2fs unix I/O manager and adds bytes 
> read/written and data rate to e2fsck -tt pass/overall timing output.
> 
> Signed-off-by: Jim Garlick <[EMAIL PROTECTED]>

Applied with a number of changes/fixups.

- Ted
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html