Skip to content

Commit

Permalink
avio: Collect and print statistics of bytes read & seeks
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed Jun 15, 2012
1 parent f77a695 commit 11153a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libavformat/avio.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ typedef struct {
* call the underlying seek function directly.
*/
int direct;

/**
* Bytes read statistic
* This field is internal to libavformat and access from outside is not allowed.
*/
int64_t bytes_read;

/**
* seek statistic
* This field is internal to libavformat and access from outside is not allowed.
*/
int seek_count;
} AVIOContext;

/* unbuffered I/O */
Expand Down
4 changes: 4 additions & 0 deletions libavformat/aviobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
return AVERROR(EPIPE);
if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
return res;
s->seek_count ++;
if (!s->write_flag)
s->buf_end = s->buffer;
s->buf_ptr = s->buffer;
Expand Down Expand Up @@ -423,6 +424,7 @@ static void fill_buffer(AVIOContext *s)
s->pos += len;
s->buf_ptr = dst;
s->buf_end = dst + len;
s->bytes_read += len;
}
}

Expand Down Expand Up @@ -792,6 +794,8 @@ int avio_close(AVIOContext *s)

h = s->opaque;
av_free(s->buffer);
if (!s->write_flag)
av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
av_free(s);
return ffurl_close(h);
}
Expand Down

0 comments on commit 11153a9

Please sign in to comment.