From 57e227e4c1127caedb60ef31f6cf56f1fb16cfb3 Mon Sep 17 00:00:00 2001 From: halleyscometsw Date: Tue, 20 May 2008 18:56:44 +0000 Subject: [PATCH] "profiling" for STREAMFILE, to see how much is actually being read git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@186 51a99a44-fe44-0410-b1ba-c3e57ba2b86b --- src/streamfile.c | 16 ++++++++++++++++ src/streamfile.h | 10 ++++++++++ test/test.c | 12 ++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/streamfile.c b/src/streamfile.c index 0a9edf80..26580267 100644 --- a/src/streamfile.c +++ b/src/streamfile.c @@ -10,6 +10,9 @@ typedef struct { uint8_t * buffer; size_t buffersize; char name[260]; +#ifdef PROFILE_STREAMFILE + size_t bytes_read; +#endif } STDIOSTREAMFILE; static STREAMFILE * open_stdio_streamfile_buffer_by_FILE(FILE *infile,const char * const filename, size_t buffersize); @@ -53,6 +56,10 @@ static size_t read_the_rest(uint8_t * dest, off_t offset, size_t length, STDIOST length_read = fread(streamfile->buffer,1,streamfile->buffersize,streamfile->infile); streamfile->validsize=length_read; +#ifdef PROFILE_STREAMFILE + streamfile->bytes_read += length_read; +#endif + /* if we can't get enough to satisfy the request we give up */ if (length_read < length_to_read) { memcpy(dest,streamfile->buffer,length_read); @@ -104,6 +111,12 @@ static void get_name_stdio(STDIOSTREAMFILE *streamfile,char *buffer,size_t lengt strcpy(buffer,streamfile->name); } +#ifdef PROFILE_STREAMFILE +static size_t get_bytes_read_stdio(STDIOSTREAMFILE *streamFile) { + return streamFile->bytes_read; +} +#endif + static STREAMFILE *open_stdio(STDIOSTREAMFILE *streamFile,const char * const filename,size_t buffersize) { int newfd; FILE *newfile; @@ -149,6 +162,9 @@ static STREAMFILE * open_stdio_streamfile_buffer_by_FILE(FILE *infile,const char streamfile->sf.get_name = (void*)get_name_stdio; streamfile->sf.open = (void*)open_stdio; streamfile->sf.close = (void*)close_stdio; +#ifdef PROFILE_STREAMFILE + streamfile->sf.get_bytes_read = (void*)get_bytes_read_stdio; +#endif streamfile->infile = infile; streamfile->buffersize = buffersize; diff --git a/src/streamfile.h b/src/streamfile.h index 2e21a1a0..0f351f88 100644 --- a/src/streamfile.h +++ b/src/streamfile.h @@ -39,6 +39,9 @@ typedef struct _STREAMFILE { struct _STREAMFILE * (*open)(struct _STREAMFILE *,const char * const filename,size_t buffersize); void (*close)(struct _STREAMFILE *); +#ifdef PROFILE_STREAMFILE + size_t (*get_bytes_read)(struct _STREAMFILE *); +#endif } STREAMFILE; /* close a file, destroy the STREAMFILE object */ @@ -59,6 +62,13 @@ static inline size_t get_streamfile_size(STREAMFILE * streamfile) { return streamfile->get_size(streamfile); } +#ifdef PROFILE_STREAMFILE +/* return how many bytes we read into buffers */ +static inline size_t get_streamfile_bytes_read(STREAMFILE * streamfile) { + return streamfile->get_bytes_read(streamfile); +} +#endif + /* Sometimes you just need an int, and we're doing the buffering. * Note, however, that if these fail to read they'll return -1, * so that should not be a valid value or there should be some backup. */ diff --git a/test/test.c b/test/test.c index eb3381c3..92e11f9c 100644 --- a/test/test.c +++ b/test/test.c @@ -237,6 +237,18 @@ int main(int argc, char ** argv) { fclose(outfile); outfile = NULL; +#ifdef PROFILE_STREAMFILE + { + int i; + for (i=0;ichannels;i++) { + size_t bytes_read = get_streamfile_bytes_read(s->ch[i].streamfile); + size_t file_size = get_streamfile_size(s->ch[i].streamfile); + fprintf(stderr,"ch%d: %lf%% (%d bytes read, file is %d bytes)\n",i, + bytes_read*100.0/file_size,bytes_read,file_size); + } + } +#endif + if (reset_outfilename) { outfile = fopen(reset_outfilename,"wb"); if (!outfile) {