mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
add error counting with STREAMFILE_PROFILE
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@280 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
4084ee9da5
commit
f944267644
@ -14,6 +14,7 @@ typedef struct {
|
||||
char name[260];
|
||||
#ifdef PROFILE_STREAMFILE
|
||||
size_t bytes_read;
|
||||
int error_count;
|
||||
#endif
|
||||
} STDIOSTREAMFILE;
|
||||
|
||||
@ -59,6 +60,11 @@ static size_t read_the_rest(uint8_t * dest, off_t offset, size_t length, STDIOST
|
||||
streamfile->validsize=length_read;
|
||||
|
||||
#ifdef PROFILE_STREAMFILE
|
||||
if (ferror(streamfile->infile)) {
|
||||
clearerr(streamfile->infile);
|
||||
streamfile->error_count++;
|
||||
}
|
||||
|
||||
streamfile->bytes_read += length_read;
|
||||
#endif
|
||||
|
||||
@ -117,6 +123,9 @@ static void get_name_stdio(STDIOSTREAMFILE *streamfile,char *buffer,size_t lengt
|
||||
static size_t get_bytes_read_stdio(STDIOSTREAMFILE *streamFile) {
|
||||
return streamFile->bytes_read;
|
||||
}
|
||||
static size_t get_error_count_stdio(STDIOSTREAMFILE *streamFile) {
|
||||
return streamFile->error_count;
|
||||
}
|
||||
#endif
|
||||
|
||||
static STREAMFILE *open_stdio(STDIOSTREAMFILE *streamFile,const char * const filename,size_t buffersize) {
|
||||
@ -166,6 +175,7 @@ static STREAMFILE * open_stdio_streamfile_buffer_by_FILE(FILE *infile,const char
|
||||
streamfile->sf.close = (void*)close_stdio;
|
||||
#ifdef PROFILE_STREAMFILE
|
||||
streamfile->sf.get_bytes_read = (void*)get_bytes_read_stdio;
|
||||
streamfile->sf.get_error_count = (void*)get_error_count_stdio;
|
||||
#endif
|
||||
|
||||
streamfile->infile = infile;
|
||||
|
@ -41,6 +41,8 @@ typedef struct _STREAMFILE {
|
||||
void (*close)(struct _STREAMFILE *);
|
||||
#ifdef PROFILE_STREAMFILE
|
||||
size_t (*get_bytes_read)(struct _STREAMFILE *);
|
||||
int (*get_error_count)(struct _STREAMFILE *);
|
||||
|
||||
#endif
|
||||
} STREAMFILE;
|
||||
|
||||
@ -65,7 +67,18 @@ static inline size_t get_streamfile_size(STREAMFILE * 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);
|
||||
if (streamfile->get_bytes_read)
|
||||
return streamfile->get_bytes_read(streamfile);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return how many times we encountered a read error */
|
||||
static inline int get_streamfile_error_count(STREAMFILE * streamfile) {
|
||||
if (streamfile->get_error_count)
|
||||
return streamfile->get_error_count(streamfile);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -256,6 +256,7 @@ int main(int argc, char ** argv) {
|
||||
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);
|
||||
int error_count = get_streamfile_error_count(s->ch[i].streamfile);
|
||||
int already_reported = 0;
|
||||
|
||||
/* see if we've reported this STREAMFILE already */
|
||||
@ -268,8 +269,8 @@ int main(int argc, char ** argv) {
|
||||
if (already_reported) continue;
|
||||
|
||||
total_bytes_read += bytes_read;
|
||||
fprintf(stderr,"ch%d: %lf%% (%d bytes read, file is %d bytes)\n",i,
|
||||
bytes_read*100.0/file_size,bytes_read,file_size);
|
||||
fprintf(stderr,"ch%d: %lf%% (%d bytes read, file is %d bytes) %d errors\n",i,
|
||||
bytes_read*100.0/file_size,bytes_read,file_size,error_count);
|
||||
}
|
||||
fprintf(stderr,"total bytes read: %d\n",total_bytes_read);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user