mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 23:10:10 +01:00
"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
This commit is contained in:
parent
7171043682
commit
57e227e4c1
@ -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;
|
||||
|
@ -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. */
|
||||
|
12
test/test.c
12
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;i<s->channels;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) {
|
||||
|
Loading…
Reference in New Issue
Block a user