diff options
Diffstat (limited to 'src/H5FDlog.c')
-rw-r--r-- | src/H5FDlog.c | 273 |
1 files changed, 161 insertions, 112 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c index a9f76af..f04b0c6 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -24,15 +24,11 @@ #include "H5MMprivate.h" /* Memory allocation */ #include "H5Pprivate.h" /*property lists */ - #ifdef MAX #undef MAX #define MAX(X,Y) ((X)>(Y)?(X):(Y)) #endif /* MAX */ -/* The size of the buffer to track allocation requests */ -#define TRACK_BUFFER 130*(1024*1024) - /* The driver identification number, initialized at runtime */ static hid_t H5FD_LOG_g = 0; @@ -43,8 +39,9 @@ static hid_t H5FD_LOG_g = 0; /* Driver-specific file access properties */ typedef struct H5FD_log_fapl_t { - char *logfile; /* Allocated log file name */ - int verbosity; /* Verbosity of logging information */ + char *logfile; /* Allocated log file name */ + unsigned flags; /* Flags for logging behavior */ + size_t buf_size; /* Size of buffers for track flavor and number of times each byte is accessed */ } H5FD_log_fapl_t; /* Define strings for the different file memory types */ @@ -277,20 +274,21 @@ H5FD_log_init(void) *------------------------------------------------------------------------- */ herr_t -H5Pset_fapl_log(hid_t fapl_id, char *logfile, int verbosity) +H5Pset_fapl_log(hid_t fapl_id, char *logfile, unsigned flags, size_t buf_size) { H5FD_log_fapl_t fa; /* File access property list information */ H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value=FAIL; FUNC_ENTER(H5Pset_fapl_log, FAIL); - H5TRACE3("e","isIs",fapl_id,logfile,verbosity); + H5TRACE3("e","isIu",fapl_id,logfile,flags); if(TRUE!=H5P_isa_class(fapl_id,H5P_FILE_ACCESS) || NULL == (plist = H5I_object(fapl_id))) HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list"); - fa.logfile = logfile; - fa.verbosity=verbosity; + fa.logfile=logfile; + fa.flags=flags; + fa.buf_size=buf_size; ret_value= H5P_set_driver(plist, H5FD_LOG, &fa); FUNC_LEAVE(ret_value); @@ -479,18 +477,24 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, file->inode = sb.st_ino; #endif - /* Get the verbosity of the logging */ - file->fa.verbosity=fa->verbosity; + /* Get the flags for logging */ + file->fa.flags=fa->flags; /* Check if we are doing any logging at all */ - if(file->fa.verbosity>=0) { - file->iosize=TRACK_BUFFER; /* Default size for now */ - file->nread=H5MM_calloc(file->iosize); - assert(file->nread); - file->nwrite=H5MM_calloc(file->iosize); - assert(file->nwrite); - file->flavor=H5MM_calloc(file->iosize); - assert(file->flavor); + if(file->fa.flags!=0) { + file->iosize=file->fa.buf_size; + if(file->fa.flags&H5FD_LOG_NUM_READ) { + file->nread=H5MM_calloc(file->iosize); + assert(file->nread); + } /* end if */ + if(file->fa.flags&H5FD_LOG_NUM_WRITE) { + file->nwrite=H5MM_calloc(file->iosize); + assert(file->nwrite); + } /* end if */ + if(file->fa.flags&H5FD_LOG_FLAVOR) { + file->flavor=H5MM_calloc(file->iosize); + assert(file->flavor); + } /* end if */ if(fa->logfile) file->logfp=HDfopen(fa->logfile,"w"); else @@ -498,7 +502,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, } /* end if */ FUNC_LEAVE((H5FD_t*)file); -} +} /* end H5FD_log_open() */ /*------------------------------------------------------------------------- @@ -532,80 +536,93 @@ H5FD_log_close(H5FD_t *_file) HRETURN_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to flush file"); #ifdef H5_HAVE_GETTIMEOFDAY - HDgettimeofday(&timeval_start,NULL); + if(file->fa.flags&H5FD_LOG_TIME_CLOSE) + HDgettimeofday(&timeval_start,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ if (close(file->fd)<0) HRETURN_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file"); #ifdef H5_HAVE_GETTIMEOFDAY - HDgettimeofday(&timeval_stop,NULL); + if(file->fa.flags&H5FD_LOG_TIME_CLOSE) + HDgettimeofday(&timeval_stop,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ /* Dump I/O information */ - if(file->fa.verbosity>=0) { + if(file->fa.flags!=0) { haddr_t addr; haddr_t last_addr; unsigned char last_val; #ifdef H5_HAVE_GETTIMEOFDAY - /* Calculate the elapsed gettimeofday time */ - timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; - timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; - if(timeval_diff.tv_usec<0) { - timeval_diff.tv_usec+=1000000; - timeval_diff.tv_sec--; - } /* end if */ - HDfprintf(file->logfp,"Close took: (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + if(file->fa.flags&H5FD_LOG_TIME_CLOSE) { + /* Calculate the elapsed gettimeofday time */ + timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; + timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; + if(timeval_diff.tv_usec<0) { + timeval_diff.tv_usec+=1000000; + timeval_diff.tv_sec--; + } /* end if */ + HDfprintf(file->logfp,"Close took: (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + } /* end if */ #endif /* H5_HAVE_GETTIMEOFDAY */ /* Dump the write I/O information */ - HDfprintf(file->logfp,"Dumping write I/O information:\n"); - last_val=file->nwrite[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->nwrite[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); - last_val=file->nwrite[addr]; - last_addr=addr; - } /* end if */ - addr++; - } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + if(file->fa.flags&H5FD_LOG_FILE_WRITE) { + HDfprintf(file->logfp,"Dumping write I/O information:\n"); + last_val=file->nwrite[0]; + last_addr=0; + addr=1; + while(addr<file->eoa) { + if(file->nwrite[addr]!=last_val) { + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + last_val=file->nwrite[addr]; + last_addr=addr; + } /* end if */ + addr++; + } /* end while */ + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + } /* end if */ /* Dump the read I/O information */ - HDfprintf(file->logfp,"Dumping read I/O information:\n"); - last_val=file->nread[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->nread[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); - last_val=file->nread[addr]; - last_addr=addr; - } /* end if */ - addr++; - } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + if(file->fa.flags&H5FD_LOG_FILE_READ) { + HDfprintf(file->logfp,"Dumping read I/O information:\n"); + last_val=file->nread[0]; + last_addr=0; + addr=1; + while(addr<file->eoa) { + if(file->nread[addr]!=last_val) { + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + last_val=file->nread[addr]; + last_addr=addr; + } /* end if */ + addr++; + } /* end while */ + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val); + } /* end if */ /* Dump the I/O flavor information */ - HDfprintf(file->logfp,"Dumping I/O flavor information:\n"); - last_val=file->flavor[0]; - last_addr=0; - addr=1; - while(addr<file->eoa) { - if(file->flavor[addr]!=last_val) { - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); - last_val=file->flavor[addr]; - last_addr=addr; - } /* end if */ - addr++; - } /* end while */ - HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); + if(file->fa.flags&H5FD_LOG_FLAVOR) { + HDfprintf(file->logfp,"Dumping I/O flavor information:\n"); + last_val=file->flavor[0]; + last_addr=0; + addr=1; + while(addr<file->eoa) { + if(file->flavor[addr]!=last_val) { + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); + last_val=file->flavor[addr]; + last_addr=addr; + } /* end if */ + addr++; + } /* end while */ + HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]); + } /* end if */ /* Free the logging information */ - file->nwrite=H5MM_xfree(file->nwrite); - file->nread=H5MM_xfree(file->nread); - file->flavor=H5MM_xfree(file->flavor); + if(file->fa.flags&H5FD_LOG_FILE_WRITE) + file->nwrite=H5MM_xfree(file->nwrite); + if(file->fa.flags&H5FD_LOG_FILE_READ) + file->nread=H5MM_xfree(file->nread); + if(file->fa.flags&H5FD_LOG_FLAVOR) + file->flavor=H5MM_xfree(file->flavor); if(file->logfp!=stderr) fclose(file->logfp); } /* end if */ @@ -747,13 +764,15 @@ H5FD_log_alloc(H5FD_t *_file, H5FD_mem_t type, hsize_t size) printf("%s: flavor=%s, size=%lu\n",FUNC,flavors[type],(unsigned long)size); #endif /* QAK */ /* Retain the (first) flavor of the information written to the file */ - if(file->fa.verbosity>=0) { - assert(addr<file->iosize); - H5_CHECK_OVERFLOW(size,hsize_t,size_t); - HDmemset(&file->flavor[addr],type,(size_t)size); + if(file->fa.flags!=0) { + if(file->fa.flags&H5FD_LOG_FLAVOR) { + assert(addr<file->iosize); + H5_CHECK_OVERFLOW(size,hsize_t,size_t); + HDmemset(&file->flavor[addr],type,(size_t)size); + } /* end if */ - if(file->fa.verbosity>1) - HDfprintf(file->logfp,"%10a-%10a (%10lu bytes) Allocated, flavor=%s\n",addr,addr+size-1,(unsigned long)size,flavors[file->flavor[addr]]); + if(file->fa.flags&H5FD_LOG_ALLOC) + HDfprintf(file->logfp,"%10a-%10a (%10Hu bytes) Allocated, flavor=%s\n",addr,addr+size-1,size,flavors[type]); } /* end if */ FUNC_LEAVE(addr); @@ -891,30 +910,39 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, haddr HRETURN_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow"); /* Log the I/O information about the read */ - if(file->fa.verbosity>=0) { + if(file->fa.flags!=0) { size_t tmp_size=size; haddr_t tmp_addr=addr; - assert((addr+size)<file->iosize); - while(tmp_size-->0) - file->nread[tmp_addr++]++; + /* Log information about the number of times these locations are read */ + if(file->fa.flags&H5FD_LOG_FILE_READ) { + assert((addr+size)<file->iosize); + while(tmp_size-->0) + file->nread[tmp_addr++]++; + } /* end if */ /* Log information about the seek, if it's going to occur */ - if(file->fa.verbosity>1 && (addr!=file->pos || OP_READ!=file->op)) - HDfprintf(file->logfp,"Seek: From %10a To %10a\n",file->pos,addr); + if(file->fa.flags&H5FD_LOG_LOC_SEEK) { + if(addr!=file->pos || OP_READ!=file->op) + HDfprintf(file->logfp,"Seek: From %10a To %10a\n",file->pos,addr); + } /* end if */ /* Log information about the read */ - if(file->fa.verbosity>0) - HDfprintf(file->logfp,"%10a-%10a (%10lu bytes) Read, flavor=%s\n",addr,addr+size-1,(unsigned long)size,flavors[file->flavor[addr]]); - } + if(file->fa.flags&H5FD_LOG_LOC_READ) { + /* Output the flavor information, if we have it */ + if(file->fa.flags&H5FD_LOG_FLAVOR) + HDfprintf(file->logfp,"%10a-%10a (%10Zu bytes) Read, flavor=%s\n",addr,addr+size-1,size,flavors[file->flavor[addr]]); + else + HDfprintf(file->logfp,"%10a-%10a (%10Zu bytes) Read\n",addr,addr+size-1,size); + } /* end if */ + } /* end if */ /* Seek to the correct location */ if ((addr!=file->pos || OP_READ!=file->op) && file_seek(file->fd, (file_offset_t)addr, SEEK_SET)<0) { file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; - HRETURN_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, - "unable to seek to proper position"); + HRETURN_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position"); } /* @@ -969,7 +997,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, haddr *------------------------------------------------------------------------- */ static herr_t -H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, haddr_t addr, +H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr, size_t size, const void *buf) { H5FD_log_t *file = (H5FD_log_t*)_file; @@ -1000,7 +1028,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd HRETURN_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow"); /* Log the I/O information about the write */ - if(file->fa.verbosity>=0) { + if(file->fa.flags&H5FD_LOG_FILE_WRITE) { size_t tmp_size=size; haddr_t tmp_addr=addr; @@ -1012,31 +1040,36 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd /* Seek to the correct location */ if (addr!=file->pos || OP_WRITE!=file->op) { #ifdef H5_HAVE_GETTIMEOFDAY - HDgettimeofday(&timeval_start,NULL); + if(file->fa.flags&H5FD_LOG_TIME_SEEK) + HDgettimeofday(&timeval_start,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ if(file_seek(file->fd, (file_offset_t)addr, SEEK_SET)<0) { file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; - HRETURN_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, - "unable to seek to proper position"); + HRETURN_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position"); } /* end if */ #ifdef H5_HAVE_GETTIMEOFDAY - HDgettimeofday(&timeval_stop,NULL); + if(file->fa.flags&H5FD_LOG_TIME_SEEK) + HDgettimeofday(&timeval_stop,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ /* Log information about the seek */ - if(file->fa.verbosity>1) { + if(file->fa.flags&H5FD_LOG_LOC_SEEK) { + HDfprintf(file->logfp,"Seek: From %10a To %10a",file->pos,addr); #ifdef H5_HAVE_GETTIMEOFDAY - /* Calculate the elapsed gettimeofday time */ - timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; - timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; - if(timeval_diff.tv_usec<0) { - timeval_diff.tv_usec+=1000000; - timeval_diff.tv_sec--; - } /* end if */ - HDfprintf(file->logfp,"Seek: From %10a To %10a (%f s)\n",file->pos,addr,(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + if(file->fa.flags&H5FD_LOG_TIME_SEEK) { + /* Calculate the elapsed gettimeofday time */ + timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; + timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; + if(timeval_diff.tv_usec<0) { + timeval_diff.tv_usec+=1000000; + timeval_diff.tv_sec--; + } /* end if */ + HDfprintf(file->logfp," (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + } /* end if */ + else #else /* H5_HAVE_GETTIMEOFDAY */ - HDfprintf(file->logfp,"Seek: From %10a To %10a\n",file->pos,addr); + HDfprintf(file->logfp,"\n"); #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ } /* end if */ @@ -1046,6 +1079,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd * results */ #ifdef H5_HAVE_GETTIMEOFDAY + if(file->fa.flags&H5FD_LOG_TIME_WRITE) HDgettimeofday(&timeval_start,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ while (size>0) { @@ -1056,6 +1090,8 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd /* error */ file->pos = HADDR_UNDEF; file->op = OP_UNKNOWN; + if(file->fa.flags&H5FD_LOG_LOC_WRITE) + HDfprintf(file->logfp,"Error! Writing: %10a-%10a (%10Zu bytes)\n",orig_addr,orig_addr+orig_size-1,orig_size); HRETURN_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed"); } assert(nbytes>0); @@ -1065,15 +1101,26 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd buf = (const char*)buf + nbytes; } #ifdef H5_HAVE_GETTIMEOFDAY + if(file->fa.flags&H5FD_LOG_TIME_WRITE) HDgettimeofday(&timeval_stop,NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ /* Log information about the write */ - if(file->fa.verbosity>0) { + if(file->fa.flags&H5FD_LOG_LOC_WRITE) { + /* Output the flavor information, if desired */ + if(file->fa.flags&H5FD_LOG_FLAVOR) + HDfprintf(file->logfp,"%10a-%10a (%10Zu bytes) (%s) Written",orig_addr,orig_addr+orig_size-1,orig_size,flavors[file->flavor[orig_addr]]); + else + HDfprintf(file->logfp,"%10a-%10a (%10Zu bytes) Written",orig_addr,orig_addr+orig_size-1,orig_size); + /* Check if this is the first write into a "default" section, grabbed by the metadata agregation algorithm */ - if(file->flavor[orig_addr]==H5FD_MEM_DEFAULT) - HDmemset(&file->flavor[orig_addr],type,orig_size); + if(file->fa.flags&H5FD_LOG_FLAVOR) { + if(file->flavor[orig_addr]==H5FD_MEM_DEFAULT) + HDmemset(&file->flavor[orig_addr],type,orig_size); + } /* end if */ + #ifdef H5_HAVE_GETTIMEOFDAY + if(file->fa.flags&H5FD_LOG_TIME_WRITE) { /* Calculate the elapsed gettimeofday time */ timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec; timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec; @@ -1081,9 +1128,11 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, hadd timeval_diff.tv_usec+=1000000; timeval_diff.tv_sec--; } /* end if */ - HDfprintf(file->logfp,"%10a-%10a (%10lu bytes) (%s) Written (%f s)\n",orig_addr,orig_addr+orig_size-1,(unsigned long)orig_size,flavors[file->flavor[orig_addr]],(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + HDfprintf(file->logfp," (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0)); + } /* end if */ + else #else /* H5_HAVE_GETTIMEOFDAY */ - HDfprintf(file->logfp,"%10a-%10a (%10lu bytes) (%s) Written\n",orig_addr,orig_addr+orig_size-1,(unsigned long)orig_size,flavors[file->flavor[orig_addr]]); + HDfprintf(file->logfp,"\n"); #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ |