diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2012-03-21 15:10:17 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2012-03-21 15:10:17 (GMT) |
commit | eb89d7b53ab95623ab454186a602e1cafc7391f0 (patch) | |
tree | ceafe458b3011e38853e765352d3c7e59bbecce1 /tools/h5stat | |
parent | 3e468e6ff65d540a439e99ea568a6bff7add7cea (diff) | |
download | hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.zip hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.tar.gz hdf5-eb89d7b53ab95623ab454186a602e1cafc7391f0.tar.bz2 |
[svn-r22105] Description:
Bring r20557:22085 from trunk to this branch, also fixing some other
issues/failures in the branch simultaneously. The h5repack tests are still
failing, but Neil will be checking into those, so the branch can be fully
functional again.
Tested on:
Mac OSX/64 10.7.3 (amazon) w/debug
Diffstat (limited to 'tools/h5stat')
-rw-r--r-- | tools/h5stat/CMakeLists.txt | 41 | ||||
-rw-r--r-- | tools/h5stat/Makefile.in | 3 | ||||
-rw-r--r-- | tools/h5stat/h5stat.c | 922 | ||||
-rw-r--r-- | tools/h5stat/h5stat_gentest.c | 4 | ||||
-rw-r--r-- | tools/h5stat/testh5stat.sh.in | 85 |
5 files changed, 616 insertions, 439 deletions
diff --git a/tools/h5stat/CMakeLists.txt b/tools/h5stat/CMakeLists.txt index 86ad3ad..8c621c9 100644 --- a/tools/h5stat/CMakeLists.txt +++ b/tools/h5stat/CMakeLists.txt @@ -1,11 +1,10 @@ -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 2.8.6) PROJECT (HDF5_TOOLS_H5STAT) #----------------------------------------------------------------------------- # Setup include Directories #----------------------------------------------------------------------------- INCLUDE_DIRECTORIES (${HDF5_TOOLS_SRC_DIR}/lib) -INCLUDE_DIRECTORIES (${HDF5_PROJECT_DIR}/test) # -------------------------------------------------------------------- # Add the h5stat executables @@ -13,6 +12,7 @@ INCLUDE_DIRECTORIES (${HDF5_PROJECT_DIR}/test) ADD_EXECUTABLE (h5stat ${HDF5_TOOLS_H5STAT_SOURCE_DIR}/h5stat.c) TARGET_NAMING (h5stat ${LIB_TYPE}) TARGET_LINK_LIBRARIES (h5stat ${HDF5_TOOLS_LIB_TARGET} ${HDF5_LIB_TARGET}) +SET_TARGET_PROPERTIES (h5stat PROPERTIES FOLDER tools) SET (H5_DEP_EXECUTABLES h5stat) @@ -29,7 +29,8 @@ IF (BUILD_TESTING) IF (HDF5_BUILD_GENERATORS AND NOT BUILD_SHARED_LIBS) ADD_EXECUTABLE (h5stat_gentest ${HDF5_TOOLS_H5STAT_SOURCE_DIR}/h5stat_gentest.c) TARGET_NAMING (h5stat_gentest ${LIB_TYPE}) - TARGET_LINK_LIBRARIES (h5stat_gentest ${HDF5_LIB_TARGET} ${HDF5_TOOLS_LIB_TARGET}) + TARGET_LINK_LIBRARIES (h5stat_gentest ${HDF5_LIB_TARGET}) + SET_TARGET_PROPERTIES (h5stat_gentest PROPERTIES FOLDER generator/tools) #ADD_TEST (NAME h5stat_gentest COMMAND $<TARGET_FILE:h5stat_gentest>) ENDIF (HDF5_BUILD_GENERATORS AND NOT BUILD_SHARED_LIBS) @@ -91,8 +92,17 @@ IF (BUILD_TESTING) # If using memchecker add tests without using scripts IF (HDF5_ENABLE_USING_MEMCHECKER) ADD_TEST (NAME H5STAT-${resultfile} COMMAND $<TARGET_FILE:h5stat> ${ARGN}) + IF (NOT "${last_test}" STREQUAL "") + SET_TESTS_PROPERTIES (H5STAT-${resultfile} PROPERTIES DEPENDS ${last_test}) + ENDIF (NOT "${last_test}" STREQUAL "") + SET (last_test "H5STAT-${resultfile}") ELSE (HDF5_ENABLE_USING_MEMCHECKER) ADD_TEST ( + NAME H5STAT-clear-${resultfile}-objects + COMMAND ${CMAKE_COMMAND} + -E remove ${resultfile}.out ${resultfile}.out.err + ) + ADD_TEST ( NAME H5STAT-${resultfile} COMMAND "${CMAKE_COMMAND}" -D "TEST_PROGRAM=$<TARGET_FILE:h5stat>" @@ -103,11 +113,8 @@ IF (BUILD_TESTING) -D "TEST_REFERENCE=${resultfile}.ddl" -P "${HDF5_RESOURCES_DIR}/runTest.cmake" ) + SET_TESTS_PROPERTIES (H5STAT-${resultfile} PROPERTIES DEPENDS "H5STAT-clear-${resultfile}-objects") ENDIF (HDF5_ENABLE_USING_MEMCHECKER) - IF (NOT "${last_test}" STREQUAL "") - SET_TESTS_PROPERTIES (H5STAT-${resultfile} PROPERTIES DEPENDS ${last_test}) - ENDIF (NOT "${last_test}" STREQUAL "") - SET (last_test "H5STAT-${resultfile}") ENDMACRO (ADD_H5_TEST file) ############################################################################## @@ -116,8 +123,9 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## - # Remove any output file left over from previous test run - ADD_TEST ( + IF (HDF5_ENABLE_USING_MEMCHECKER) + # Remove any output file left over from previous test run + ADD_TEST ( NAME H5STAT-clearall-objects COMMAND ${CMAKE_COMMAND} -E remove @@ -149,16 +157,11 @@ IF (BUILD_TESTING) h5stat_newgrat-UG.out.err h5stat_newgrat-UA.out h5stat_newgrat-UA.out.err - ) - IF (NOT "${last_test}" STREQUAL "") - SET_TESTS_PROPERTIES (H5STAT-clearall-objects PROPERTIES DEPENDS ${last_test}) - ENDIF (NOT "${last_test}" STREQUAL "") - SET (last_test "H5STAT-clearall-objects") - - # If using memchecker add tests without using scripts - IF (HDF5_ENABLE_USING_MEMCHECKER) - ADD_TEST (NAME H5STAT-help COMMAND h5stat -h) - ADD_TEST (NAME H5STAT-filters COMMAND h5stat h5stat_filters.h5) + ) + IF (NOT "${last_test}" STREQUAL "") + SET_TESTS_PROPERTIES (H5STAT-clearall-objects PROPERTIES DEPENDS ${last_test}) + ENDIF (NOT "${last_test}" STREQUAL "") + SET (last_test "H5STAT-clearall-objects") ENDIF (HDF5_ENABLE_USING_MEMCHECKER) # Test for help flag diff --git a/tools/h5stat/Makefile.in b/tools/h5stat/Makefile.in index 4e37025..403446c 100644 --- a/tools/h5stat/Makefile.in +++ b/tools/h5stat/Makefile.in @@ -204,6 +204,7 @@ F9XMODEXT = @F9XMODEXT@ F9XMODFLAG = @F9XMODFLAG@ F9XSUFFIXFLAG = @F9XSUFFIXFLAG@ FC = @FC@ +FC2003 = @FC2003@ FCFLAGS = @FCFLAGS@ FCFLAGS_f90 = @FCFLAGS_f90@ FCLIBS = @FCLIBS@ @@ -224,10 +225,12 @@ H5_LONE_COLON = @H5_LONE_COLON@ H5_VERSION = @H5_VERSION@ HADDR_T = @HADDR_T@ HAVE_DMALLOC = @HAVE_DMALLOC@ +HAVE_FORTRAN_2003 = @HAVE_FORTRAN_2003@ HDF5_HL = @HDF5_HL@ HDF5_INTERFACES = @HDF5_INTERFACES@ HDF_CXX = @HDF_CXX@ HDF_FORTRAN = @HDF_FORTRAN@ +HDF_FORTRAN2003 = @HDF_FORTRAN2003@ HID_T = @HID_T@ HL = @HL@ HL_FOR = @HL_FOR@ diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c index fd21266..e206f4f 100644 --- a/tools/h5stat/h5stat.c +++ b/tools/h5stat/h5stat.c @@ -15,7 +15,7 @@ #include <stdlib.h> #include <string.h> -#include "H5private.h" /* Generic Functions */ +#include "H5private.h" /* Generic Functions */ #include "h5tools.h" #include "h5tools_utils.h" #include "h5tools_ref.h" @@ -27,7 +27,7 @@ /* Parameters to control statistics gathered */ #define SIZE_SMALL_GROUPS 10 -#define SIZE_SMALL_ATTRS 10 +#define SIZE_SMALL_ATTRS 10 #define SIZE_SMALL_DSETS 10 #define SIZE_SMALL_SECTS 10 @@ -60,7 +60,7 @@ typedef struct ohdr_info_t { /* Info to pass to the iteration functions */ typedef struct iter_t { hid_t fid; /* File ID */ - hsize_t filesize; /* Size of the file */ + hsize_t filesize; /* Size of the file */ unsigned long uniq_groups; /* Number of unique groups */ unsigned long uniq_dsets; /* Number of unique datasets */ unsigned long uniq_dtypes; /* Number of unique named datatypes */ @@ -74,7 +74,7 @@ typedef struct iter_t { unsigned long *group_bins; /* Pointer to array of bins for group counts */ ohdr_info_t group_ohdr_info; /* Object header information for groups */ - hsize_t max_attrs; /* Maximum attributes from a group */ + hsize_t max_attrs; /* Maximum attributes from a group */ unsigned long num_small_attrs[SIZE_SMALL_ATTRS]; /* Size of small attributes tracked */ unsigned attr_nbins; /* Number of bins for attribute counts */ unsigned long *attr_bins; /* Pointer to array of bins for attribute counts */ @@ -99,14 +99,14 @@ typedef struct iter_t { hsize_t attrs_heap_storage_size; /* fractal heap size for attributes (1.8) */ hsize_t SM_hdr_storage_size; /* header size for SOHM table (1.8) */ hsize_t SM_index_storage_size; /* index (btree & list) size for SOHM table (1.8) */ - hsize_t SM_heap_storage_size; /* fractal heap size for SOHM table (1.8) */ - hsize_t super_size; /* superblock size */ - hsize_t super_ext_size; /* superblock extension size */ - hsize_t ublk_size; /* user block size (if exists) */ - H5F_file_space_type_t fs_strategy; /* File space management strategy */ - hsize_t fs_threshold; /* Free-space section threshold */ - hsize_t free_space; /* amount of freespace in the file */ - hsize_t free_hdr; /* size of free space manager metadata in the file */ + hsize_t SM_heap_storage_size; /* fractal heap size for SOHM table (1.8) */ + hsize_t super_size; /* superblock size */ + hsize_t super_ext_size; /* superblock extension size */ + hsize_t ublk_size; /* user block size (if exists) */ + H5F_file_space_type_t fs_strategy; /* File space management strategy */ + hsize_t fs_threshold; /* Free-space section threshold */ + hsize_t free_space; /* amount of freespace in the file */ + hsize_t free_hdr; /* size of free space manager metadata in the file */ unsigned long num_small_sects[SIZE_SMALL_SECTS]; /* Size of small free-space sections */ unsigned sect_nbins; /* Number of bins for free-space section sizes */ unsigned long *sect_bins; /* Pointer to array of bins for free-space section sizes */ @@ -120,19 +120,19 @@ typedef struct iter_t { static int display_all = TRUE; /* Enable the printing of selected statistics */ -static int display_file = FALSE; /* display file information */ -static int display_group = FALSE; /* display groups information */ -static int display_dset = FALSE; /* display datasets information */ +static int display_file = FALSE; /* display file information */ +static int display_group = FALSE; /* display groups information */ +static int display_dset = FALSE; /* display datasets information */ static int display_dset_dtype_meta = FALSE; /* display datasets' datatype information */ -static int display_attr = FALSE; /* display attributes information */ +static int display_attr = FALSE; /* display attributes information */ static int display_free_sections = FALSE; /* display free space information */ -static int display_summary = FALSE; /* display summary of file space information */ +static int display_summary = FALSE; /* display summary of file space information */ static int display_file_metadata = FALSE; /* display file space info for file's metadata */ static int display_group_metadata = FALSE; /* display file space info for groups' metadata */ static int display_dset_metadata = FALSE; /* display file space info for datasets' metadata */ -static int display_object = FALSE; /* not implemented yet */ +static int display_object = FALSE; /* not implemented yet */ /* a structure for handling the order command-line parameters come in */ struct handler_t { @@ -232,28 +232,28 @@ static void leave(int ret) { h5tools_close(); - exit(ret); + HDexit(ret); } static void usage(const char *prog) { - fflush(stdout); - fprintf(stdout, "Usage: %s [OPTIONS] file\n", prog); - fprintf(stdout, "\n"); - fprintf(stdout, " OPTIONS\n"); - fprintf(stdout, " -h, --help Print a usage message and exit\n"); - fprintf(stdout, " -V, --version Print version number and exit\n"); - fprintf(stdout, " -f, --file Print file information\n"); - fprintf(stdout, " -F, --filemetadata Print file space information for file's metadata\n"); - fprintf(stdout, " -g, --group Print group information\n"); - fprintf(stdout, " -G, --groupmetadata Print file space information for groups' metadata\n"); - fprintf(stdout, " -d, --dset Print dataset information\n"); - fprintf(stdout, " -D, --dsetmetadata Print file space information for datasets' metadata\n"); - fprintf(stdout, " -T, --dtypemetadata Print datasets' datatype information\n"); - fprintf(stdout, " -A, --attribute Print attribute information\n"); - fprintf(stdout, " -s, --freespace Print free space information\n"); - fprintf(stdout, " -S, --summary Print summary of file space information\n"); + HDfflush(stdout); + HDfprintf(stdout, "Usage: %s [OPTIONS] file\n", prog); + HDfprintf(stdout, "\n"); + HDfprintf(stdout, " OPTIONS\n"); + HDfprintf(stdout, " -h, --help Print a usage message and exit\n"); + HDfprintf(stdout, " -V, --version Print version number and exit\n"); + HDfprintf(stdout, " -f, --file Print file information\n"); + HDfprintf(stdout, " -F, --filemetadata Print file space information for file's metadata\n"); + HDfprintf(stdout, " -g, --group Print group information\n"); + HDfprintf(stdout, " -G, --groupmetadata Print file space information for groups' metadata\n"); + HDfprintf(stdout, " -d, --dset Print dataset information\n"); + HDfprintf(stdout, " -D, --dsetmetadata Print file space information for datasets' metadata\n"); + HDfprintf(stdout, " -T, --dtypemetadata Print datasets' datatype information\n"); + HDfprintf(stdout, " -A, --attribute Print attribute information\n"); + HDfprintf(stdout, " -s, --freespace Print free space information\n"); + HDfprintf(stdout, " -S, --summary Print summary of file space information\n"); } @@ -303,7 +303,7 @@ ceil_log10(unsigned long x) static herr_t attribute_stats(iter_t *iter, const H5O_info_t *oi) { - unsigned bin; /* "bin" the number of objects falls in */ + unsigned bin; /* "bin" the number of objects falls in */ /* Update dataset & attribute metadata info */ iter->attrs_btree_storage_size += oi->meta_size.attr.index_size; @@ -318,12 +318,12 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi) /* Add attribute count to proper bin */ bin = ceil_log10((unsigned long)oi->num_attrs); if((bin + 1) > iter->attr_nbins) { - iter->attr_bins = (unsigned long *)realloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long)); - assert(iter->attr_bins); + iter->attr_bins = (unsigned long *)HDrealloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long)); + HDassert(iter->attr_bins); - /* Initialize counts for intermediate bins */ + /* Initialize counts for intermediate bins */ while(iter->attr_nbins < bin) - iter->attr_bins[iter->attr_nbins++] = 0; + iter->attr_bins[iter->attr_nbins++] = 0; iter->attr_nbins++; /* Initialize count for new bin */ @@ -351,23 +351,23 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi) * Modifications: Refactored code from the walk_function * EIP, Wednesday, August 16, 2006 * - * Vailin Choi 12 July 2007 - * 1. Gathered storage info for btree and heap - * (groups and attributes) - * 2. Gathered info for attributes + * Vailin Choi 12 July 2007 + * 1. Gathered storage info for btree and heap + * (groups and attributes) + * 2. Gathered info for attributes * - * Vailin Choi 14 July 2007 - * Cast "num_objs" and "num_attrs" to size_t - * Due to the -Mbounds problem for the pgi-32 bit compiler on indexing + * Vailin Choi 14 July 2007 + * Cast "num_objs" and "num_attrs" to size_t + * Due to the -Mbounds problem for the pgi-32 bit compiler on indexing * *------------------------------------------------------------------------- */ static herr_t group_stats(iter_t *iter, const char *name, const H5O_info_t *oi) { - H5G_info_t ginfo; /* Group information */ - unsigned bin; /* "bin" the number of objects falls in */ - herr_t ret; + H5G_info_t ginfo; /* Group information */ + unsigned bin; /* "bin" the number of objects falls in */ + herr_t ret; /* Gather statistics about this type of object */ iter->uniq_groups++; @@ -378,7 +378,7 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi) /* Get group information */ ret = H5Gget_info_by_name(iter->fid, name, &ginfo, H5P_DEFAULT); - assert(ret >= 0); + HDassert(ret >= 0); /* Update link stats */ if(ginfo.nlinks < SIZE_SMALL_GROUPS) @@ -390,10 +390,10 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi) bin = ceil_log10((unsigned long)ginfo.nlinks); if((bin + 1) > iter->group_nbins) { /* Allocate more storage for info about dataset's datatype */ - iter->group_bins = (unsigned long *)realloc(iter->group_bins, (bin + 1) * sizeof(unsigned long)); - assert(iter->group_bins); + iter->group_bins = (unsigned long *)HDrealloc(iter->group_bins, (bin + 1) * sizeof(unsigned long)); + HDassert(iter->group_bins); - /* Initialize counts for intermediate bins */ + /* Initialize counts for intermediate bins */ while(iter->group_nbins < bin) iter->group_bins[iter->group_nbins++] = 0; iter->group_nbins++; @@ -410,7 +410,7 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi) /* Update attribute metadata info */ ret = attribute_stats(iter, oi); - assert(ret >= 0); + HDassert(ret >= 0); return 0; } /* end group_stats() */ @@ -433,22 +433,22 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi) static herr_t dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) { - unsigned bin; /* "bin" the number of objects falls in */ - hid_t did; /* Dataset ID */ - hid_t sid; /* Dataspace ID */ - hid_t tid; /* Datatype ID */ - hid_t dcpl; /* Dataset creation property list ID */ - hsize_t dims[H5S_MAX_RANK];/* Dimensions of dataset */ - H5D_layout_t lout; /* Layout of dataset */ - unsigned type_found; /* Whether the dataset's datatype was */ - /* already found */ - int ndims; /* Number of dimensions of dataset */ - hsize_t storage; /* Size of dataset storage */ - unsigned u; /* Local index variable */ - int num_ext; /* Number of external files for a dataset */ - int nfltr; /* Number of filters for a dataset */ - H5Z_filter_t fltr; /* Filter identifier */ - herr_t ret; + unsigned bin; /* "bin" the number of objects falls in */ + hid_t did; /* Dataset ID */ + hid_t sid; /* Dataspace ID */ + hid_t tid; /* Datatype ID */ + hid_t dcpl; /* Dataset creation property list ID */ + hsize_t dims[H5S_MAX_RANK];/* Dimensions of dataset */ + H5D_layout_t lout; /* Layout of dataset */ + unsigned type_found; /* Whether the dataset's datatype was */ + /* already found */ + int ndims; /* Number of dimensions of dataset */ + hsize_t storage; /* Size of dataset storage */ + unsigned u; /* Local index variable */ + int num_ext; /* Number of external files for a dataset */ + int nfltr; /* Number of filters for a dataset */ + H5Z_filter_t fltr; /* Filter identifier */ + herr_t ret; /* Gather statistics about this type of object */ iter->uniq_dsets++; @@ -458,7 +458,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) iter->dset_ohdr_info.free_size += oi->hdr.space.free; did = H5Dopen2(iter->fid, name, H5P_DEFAULT); - assert(did > 0); + HDassert(did > 0); /* Update dataset metadata info */ iter->datasets_index_storage_size += oi->meta_size.obj.index_size; @@ -466,22 +466,22 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) /* Update attribute metadata info */ ret = attribute_stats(iter, oi); - assert(ret >= 0); + HDassert(ret >= 0); /* Get storage info */ storage = H5Dget_storage_size(did); /* Gather layout statistics */ dcpl = H5Dget_create_plist(did); - assert(dcpl > 0); + HDassert(dcpl > 0); lout = H5Pget_layout(dcpl); - assert(lout >= 0); + HDassert(lout >= 0); /* Object header's total size for H5D_COMPACT layout includes raw data size */ /* "storage" also includes H5D_COMPACT raw data size */ if(lout == H5D_COMPACT) - iter->dset_ohdr_info.total_size -= storage; + iter->dset_ohdr_info.total_size -= storage; /* Track the layout type for dataset */ (iter->dset_layouts[lout])++; @@ -495,14 +495,14 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) iter->nexternal += (unsigned long)num_ext; iter->dset_external_storage_size += (unsigned long)storage; } else - iter->dset_storage_size += storage; + iter->dset_storage_size += storage; /* Gather dataspace statistics */ sid = H5Dget_space(did); - assert(sid > 0); + HDassert(sid > 0); ndims = H5Sget_simple_extent_dims(sid, dims, NULL); - assert(ndims >= 0); + HDassert(ndims >= 0); /* Check for larger rank of dataset */ if((unsigned)ndims > iter->max_dset_rank) @@ -521,8 +521,8 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) bin = ceil_log10((unsigned long)dims[0]); if((bin + 1) > iter->dset_dim_nbins) { /* Allocate more storage for info about dataset's datatype */ - iter->dset_dim_bins = (unsigned long *)realloc(iter->dset_dim_bins, (bin + 1) * sizeof(unsigned long)); - assert(iter->dset_dim_bins); + iter->dset_dim_bins = (unsigned long *)HDrealloc(iter->dset_dim_bins, (bin + 1) * sizeof(unsigned long)); + HDassert(iter->dset_dim_bins); /* Initialize counts for intermediate bins */ while(iter->dset_dim_nbins < bin) @@ -537,11 +537,11 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) } /* end if */ ret = H5Sclose(sid); - assert(ret >= 0); + HDassert(ret >= 0); /* Gather datatype statistics */ tid = H5Dget_type(did); - assert(tid > 0); + HDassert(tid > 0); type_found = FALSE; for(u = 0; u < iter->dset_ntypes; u++) @@ -558,12 +558,12 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) iter->dset_ntypes++; /* Allocate more storage for info about dataset's datatype */ - iter->dset_type_info = (dtype_info_t *)realloc(iter->dset_type_info, iter->dset_ntypes * sizeof(dtype_info_t)); - assert(iter->dset_type_info); + iter->dset_type_info = (dtype_info_t *)HDrealloc(iter->dset_type_info, iter->dset_ntypes * sizeof(dtype_info_t)); + HDassert(iter->dset_type_info); /* Initialize information about datatype */ iter->dset_type_info[curr_ntype].tid = H5Tcopy(tid); - assert(iter->dset_type_info[curr_ntype].tid > 0); + HDassert(iter->dset_type_info[curr_ntype].tid > 0); iter->dset_type_info[curr_ntype].count = 1; iter->dset_type_info[curr_ntype].named = 0; @@ -576,7 +576,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) (iter->dset_type_info[u].named)++; ret = H5Tclose(tid); - assert(ret >= 0); + HDassert(ret >= 0); /* Track different filters */ if((nfltr = H5Pget_nfilters(dcpl)) >= 0) { @@ -594,10 +594,10 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) } /* endif nfltr */ ret = H5Pclose(dcpl); - assert(ret >= 0); + HDassert(ret >= 0); ret = H5Dclose(did); - assert(ret >= 0); + HDassert(ret >= 0); return 0; } /* end dataset_stats() */ @@ -628,7 +628,7 @@ datatype_stats(iter_t *iter, const H5O_info_t *oi) /* Update attribute metadata info */ ret = attribute_stats(iter, oi); - assert(ret >= 0); + HDassert(ret >= 0); return 0; } /* end datatype_stats() */ @@ -640,7 +640,7 @@ datatype_stats(iter_t *iter, const H5O_info_t *oi) * Purpose: Gather statistics about an object * * Return: Success: 0 - * Failure: -1 + * Failure: -1 * * Programmer: Quincey Koziol * Tuesday, November 6, 2007 @@ -669,7 +669,7 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited, break; case H5O_TYPE_NAMED_DATATYPE: - datatype_stats(iter, oi); + datatype_stats(iter, oi); break; default: @@ -724,7 +724,7 @@ lnk_stats(const char UNUSED *path, const H5L_info_t *li, void *_iter) * Purpose: Gather statistics for free space sections in the file * * Return: Success: 0 - * Failure: -1 + * Failure: -1 * * Programmer: Vailin Choi; July 7th, 2009 * @@ -734,31 +734,31 @@ static herr_t freespace_stats(hid_t fid, iter_t *iter) { H5F_sect_info_t *sect_info = NULL; /* Free space sections */ - ssize_t nsects; /* Number of free space sections */ - size_t u; /* Local index variable */ + ssize_t nsects; /* Number of free space sections */ + size_t u; /* Local index variable */ /* Query section information */ if((nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, 0, NULL)) < 0) - return(FAIL); + return(FAIL); else if(nsects) { - if(NULL == (sect_info = (H5F_sect_info_t *)calloc((size_t)nsects, sizeof(H5F_sect_info_t)))) - return(FAIL); - nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info); - assert(nsects); + if(NULL == (sect_info = (H5F_sect_info_t *)HDcalloc((size_t)nsects, sizeof(H5F_sect_info_t)))) + return(FAIL); + nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info); + HDassert(nsects); } /* end else-if */ for(u = 0; u < (size_t)nsects; u++) { - unsigned bin; /* "bin" the number of objects falls in */ + unsigned bin; /* "bin" the number of objects falls in */ - if(sect_info[u].size < SIZE_SMALL_SECTS) - (iter->num_small_sects[(size_t)sect_info[u].size])++; + if(sect_info[u].size < SIZE_SMALL_SECTS) + (iter->num_small_sects[(size_t)sect_info[u].size])++; /* Add section size to proper bin */ bin = ceil_log10((unsigned long)sect_info[u].size); if(bin >= iter->sect_nbins) { /* Allocate more storage for section info */ - iter->sect_bins = (unsigned long *)realloc(iter->sect_bins, (bin + 1) * sizeof(unsigned long)); - assert(iter->sect_bins); + iter->sect_bins = (unsigned long *)HDrealloc(iter->sect_bins, (bin + 1) * sizeof(unsigned long)); + HDassert(iter->sect_bins); /* Initialize counts for intermediate bins */ while(iter->sect_nbins < bin) @@ -792,9 +792,9 @@ freespace_stats(hid_t fid, iter_t *iter) * Saturday, August 12, 2006 * * Modifications: - * Vailin Choi; October 2009 - * Turn on display_group_metadata, display_dset_metadata - * Add 'S' & 's' for printing free space info (previous checkin) + * Vailin Choi; October 2009 + * Turn on display_group_metadata, display_dset_metadata + * Add 'S' & 's' for printing free space info (previous checkin) * *------------------------------------------------------------------------- */ @@ -802,86 +802,113 @@ static struct handler_t * parse_command_line(int argc, const char *argv[]) { int opt, i; - struct handler_t *hand; + struct handler_t *hand = NULL; /* Allocate space to hold the command line info */ - hand = (struct handler_t *)calloc((size_t)argc, sizeof(struct handler_t)); + if((hand = (struct handler_t *)HDcalloc((size_t)argc, sizeof(struct handler_t)))==NULL) { + error_msg("unable to parse command line arguments \n"); + goto error; + } /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { - switch ((char)opt) { - case 'h': - usage(h5tools_getprogname()); - leave(EXIT_SUCCESS); - - case 'V': - print_version(h5tools_getprogname()); - leave(EXIT_SUCCESS); - break; + switch ((char) opt) { + case 'h': + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_SUCCESS); + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + goto done; + break; - case 'F': - display_all = FALSE; - display_file_metadata = TRUE; - break; + case 'V': + print_version(h5tools_getprogname()); + h5tools_setstatus(EXIT_SUCCESS); + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + goto done; + break; - case 'f': - display_all = FALSE; - display_file = TRUE; - break; + case 'F': + display_all = FALSE; + display_file_metadata = TRUE; + break; - case 'G': - display_all = FALSE; - display_group_metadata = TRUE; - break; + case 'f': + display_all = FALSE; + display_file = TRUE; + break; - case 'g': - display_all = FALSE; - display_group = TRUE; - break; + case 'G': + display_all = FALSE; + display_group_metadata = TRUE; + break; - case 'D': - display_all = FALSE; - display_dset_metadata = TRUE; - break; + case 'g': + display_all = FALSE; + display_group = TRUE; + break; - case 'd': - display_all = FALSE; - display_dset = TRUE; - break; + case 'D': + display_all = FALSE; + display_dset_metadata = TRUE; + break; - case 'T': - display_all = FALSE; - display_dset_dtype_meta = TRUE; - break; + case 'd': + display_all = FALSE; + display_dset = TRUE; + break; - case 'A': - display_all = FALSE; - display_attr = TRUE; - break; + case 'T': + display_all = FALSE; + display_dset_dtype_meta = TRUE; + break; - case 's': - display_all = FALSE; - display_free_sections = TRUE; - break; + case 'A': + display_all = FALSE; + display_attr = TRUE; + break; - case 'S': - display_all = FALSE; - display_summary = TRUE; - break; + case 's': + display_all = FALSE; + display_free_sections = TRUE; + break; - case 'O': - display_all = FALSE; - display_object = TRUE; - for(i = 0; i < argc; i++) - if(!hand[i].obj) { - hand[i].obj = HDstrdup(opt_arg); - break; - } /* end if */ - break; + case 'S': + display_all = FALSE; + display_summary = TRUE; + break; - default: - usage(h5tools_getprogname()); - leave(EXIT_FAILURE); + case 'O': + display_all = FALSE; + display_object = TRUE; + for (i = 0; i < argc; i++) + if (!hand[i].obj) { + hand[i].obj = HDstrdup(opt_arg); + break; + } /* end if */ + break; + + default: + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + goto error; } /* end switch */ } /* end while */ @@ -889,9 +916,26 @@ parse_command_line(int argc, const char *argv[]) if (argc <= opt_ind) { error_msg("missing file name\n"); usage(h5tools_getprogname()); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto error; } /* end if */ +done: + return hand; + +error: + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + h5tools_setstatus(EXIT_FAILURE); + return hand; } @@ -924,6 +968,45 @@ iter_init(iter_t *iter, hid_t fid) /*------------------------------------------------------------------------- + * Function: free_iter + * + * Purpose: Freee iter structure + * + * Return: Success: 0 + * + * Failure: Never fails + * + *------------------------------------------------------------------------- + */ +static herr_t +iter_free(iter_t *iter) +{ + /* Clear array of bins for group counts */ + if(iter->group_bins) + free(iter->group_bins); + iter->group_bins = NULL; + /* Clear array of bins for attribute counts */ + if(iter->attr_bins) + free(iter->attr_bins); + iter->attr_bins = NULL; + /* Clear dataset datatype information found */ + if(iter->dset_type_info) + free(iter->dset_type_info); + iter->dset_type_info = NULL; + /* Clear array of bins for dataset dimensions */ + if(iter->dset_dim_bins) + free(iter->dset_dim_bins); + iter->dset_dim_bins = NULL; + /* Clear array of bins for free-space section sizes */ + if(iter->sect_bins) + free(iter->sect_bins); + iter->sect_bins = NULL; + + return 0; +} + + +/*------------------------------------------------------------------------- * Function: print_file_info * * Purpose: Prints information about file @@ -956,6 +1039,66 @@ print_file_info(const iter_t *iter) /*------------------------------------------------------------------------- + * Function: print_file_metadata + * + * Purpose: Prints file space information for file's metadata + * + * Return: Success: 0 + * + * Failure: Never fails + * + * Programmer: Elena Pourmal + * Saturday, August 12, 2006 + * + *------------------------------------------------------------------------- + */ +static herr_t +print_file_metadata(const iter_t *iter) +{ + HDfprintf(stdout, "File space information for file metadata (in bytes):\n"); + HDfprintf(stdout, "\tSuperblock: %Hu\n", iter->super_size); + HDfprintf(stdout, "\tSuperblock extension: %Hu\n", iter->super_ext_size); + HDfprintf(stdout, "\tUser block: %Hu\n", iter->ublk_size); + + HDfprintf(stdout, "\tObject headers: (total/unused)\n"); + HDfprintf(stdout, "\t\tGroups: %Hu/%Hu\n", + iter->group_ohdr_info.total_size, + iter->group_ohdr_info.free_size); + HDfprintf(stdout, "\t\tDatasets(exclude compact data): %Hu/%Hu\n", + iter->dset_ohdr_info.total_size, + iter->dset_ohdr_info.free_size); + HDfprintf(stdout, "\t\tDatatypes: %Hu/%Hu\n", + iter->dtype_ohdr_info.total_size, + iter->dtype_ohdr_info.free_size); + + HDfprintf(stdout, "\tGroups:\n"); + HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->groups_btree_storage_size); + HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->groups_heap_storage_size); + + HDfprintf(stdout, "\tAttributes:\n"); + HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->attrs_btree_storage_size); + HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->attrs_heap_storage_size); + + HDfprintf(stdout, "\tChunked datasets:\n"); + HDfprintf(stdout, "\t\tIndex: %Hu\n", iter->datasets_index_storage_size); + + HDfprintf(stdout, "\tDatasets:\n"); + HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->datasets_heap_storage_size); + + HDfprintf(stdout, "\tShared Messages:\n"); + HDfprintf(stdout, "\t\tHeader: %Hu\n", iter->SM_hdr_storage_size); + HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->SM_index_storage_size); + HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->SM_heap_storage_size); + + HDfprintf(stdout, "\tFree-space managers:\n"); + HDfprintf(stdout, "\t\tHeader: %Hu\n", iter->free_hdr); + HDfprintf(stdout, "\t\tAmount of free space: %Hu\n", iter->free_space); + + return 0; +} /* print_file_metadata() */ + + +/*------------------------------------------------------------------------- * Function: print_group_info * * Purpose: Prints information about groups in the file @@ -968,9 +1111,9 @@ print_file_info(const iter_t *iter) * Saturday, August 12, 2006 * * Modifications: - * bug #1253; Oct 6th 2008; Vailin Choi - * Fixed segmentation fault: print iter->group_bins[0] when - * there is iter->group_nbins + * bug #1253; Oct 6th 2008; Vailin Choi + * Fixed segmentation fault: print iter->group_bins[0] when + * there is iter->group_nbins * *------------------------------------------------------------------------- */ @@ -1013,54 +1156,31 @@ print_group_info(const iter_t *iter) /*------------------------------------------------------------------------- - * Function: print_attr_info + * Function: print_group_metadata * - * Purpose: Prints information about attributes in the file + * Purpose: Prints file space information for groups' metadata * * Return: Success: 0 * * Failure: Never fails * - * Programmer: Vailin Choi - * July 12, 2007 - * - * Modifications: + * Programmer: Vailin Choi; October 2009 * *------------------------------------------------------------------------- */ static herr_t -print_attr_info(const iter_t *iter) +print_group_metadata(const iter_t *iter) { - unsigned long power; /* Temporary "power" for bins */ - unsigned long total; /* Total count for various statistics */ - unsigned u; /* Local index variable */ + printf("File space information for groups' metadata (in bytes):\n"); - printf("Small # of attributes:\n"); - total = 0; - for(u = 1; u < SIZE_SMALL_ATTRS; u++) { - if(iter->num_small_attrs[u] > 0) { - printf("\t# of objects with %u attributes: %lu\n", u, iter->num_small_attrs[u]); - total += iter->num_small_attrs[u]; - } /* end if */ - } /* end for */ - printf("\tTotal # of objects with small # of attributes: %lu\n", total); + HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", + iter->group_ohdr_info.total_size, iter->group_ohdr_info.free_size); - printf("Attribute bins:\n"); - total = 0; - power = 1; - for(u = 1; u < iter->attr_nbins; u++) { - if(iter->attr_bins[u] > 0) { - printf("\t# of objects with %lu - %lu attributes: %lu\n", power, (power * 10) - 1, - iter->attr_bins[u]); - total += iter->attr_bins[u]; - } /* end if */ - power *= 10; - } /* end for */ - printf("\tTotal # of objects with attributes: %lu\n", total); - printf("\tMax. # of attributes to objects: %lu\n", (unsigned long)iter->max_attrs); + HDfprintf(stdout, "\tB-tree/List: %Hu\n", iter->groups_btree_storage_size); + HDfprintf(stdout, "\tHeap: %Hu\n", iter->groups_heap_storage_size); return 0; -} /* print_attr_info() */ +} /* print_group_metadata() */ /*------------------------------------------------------------------------- @@ -1154,6 +1274,35 @@ print_dataset_info(const iter_t *iter) /*------------------------------------------------------------------------- + * Function: print_dataset_metadata + * + * Purpose: Prints file space information for datasets' metadata + * + * Return: Success: 0 + * + * Failure: Never fails + * + * Programmer: Vailin Choi; October 2009 + * + *------------------------------------------------------------------------- + */ +static herr_t +print_dset_metadata(const iter_t *iter) +{ + printf("File space information for datasets' metadata (in bytes):\n"); + + HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", + iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size); + + HDfprintf(stdout, "\tIndex for Chunked datasets: %Hu\n", + iter->datasets_index_storage_size); + HDfprintf(stdout, "\tHeap: %Hu\n", iter->datasets_heap_storage_size); + + return 0; +} /* print_dset_metadata() */ + + +/*------------------------------------------------------------------------- * Function: print_dset_dtype_meta * * Purpose: Prints datasets' datatype information @@ -1165,8 +1314,8 @@ print_dataset_info(const iter_t *iter) * Programmer: * * Modifications: - * Vailin Choi; October 2009 - * Moved from print_dataset_info() + * Vailin Choi; October 2009 + * Moved from print_dataset_info() * *------------------------------------------------------------------------- */ @@ -1178,20 +1327,20 @@ print_dset_dtype_meta(const iter_t *iter) unsigned u; /* Local index variable */ if(iter->dset_ntypes) { - printf("Dataset datatype information:\n"); - printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes); - total = 0; - for(u = 0; u < iter->dset_ntypes; u++) { - H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size); - printf("\tDataset datatype #%u:\n", u); - printf("\t\tCount (total/named) = (%lu/%lu)\n", - iter->dset_type_info[u].count, iter->dset_type_info[u].named); - printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size, - (unsigned long)H5Tget_size(iter->dset_type_info[u].tid)); - H5Tclose(iter->dset_type_info[u].tid); - total += iter->dset_type_info[u].count; - } /* end for */ - printf("\tTotal dataset datatype count: %lu\n", total); + printf("Dataset datatype information:\n"); + printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes); + total = 0; + for(u = 0; u < iter->dset_ntypes; u++) { + H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size); + printf("\tDataset datatype #%u:\n", u); + printf("\t\tCount (total/named) = (%lu/%lu)\n", + iter->dset_type_info[u].count, iter->dset_type_info[u].named); + printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size, + (unsigned long)H5Tget_size(iter->dset_type_info[u].tid)); + H5Tclose(iter->dset_type_info[u].tid); + total += iter->dset_type_info[u].count; + } /* end for */ + printf("\tTotal dataset datatype count: %lu\n", total); } return 0; @@ -1199,6 +1348,57 @@ print_dset_dtype_meta(const iter_t *iter) /*------------------------------------------------------------------------- + * Function: print_attr_info + * + * Purpose: Prints information about attributes in the file + * + * Return: Success: 0 + * + * Failure: Never fails + * + * Programmer: Vailin Choi + * July 12, 2007 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +print_attr_info(const iter_t *iter) +{ + unsigned long power; /* Temporary "power" for bins */ + unsigned long total; /* Total count for various statistics */ + unsigned u; /* Local index variable */ + + printf("Small # of attributes:\n"); + total = 0; + for(u = 1; u < SIZE_SMALL_ATTRS; u++) { + if(iter->num_small_attrs[u] > 0) { + printf("\t# of objects with %u attributes: %lu\n", u, iter->num_small_attrs[u]); + total += iter->num_small_attrs[u]; + } /* end if */ + } /* end for */ + printf("\tTotal # of objects with small # of attributes: %lu\n", total); + + printf("Attribute bins:\n"); + total = 0; + power = 1; + for(u = 1; u < iter->attr_nbins; u++) { + if(iter->attr_bins[u] > 0) { + printf("\t# of objects with %lu - %lu attributes: %lu\n", power, (power * 10) - 1, + iter->attr_bins[u]); + total += iter->attr_bins[u]; + } /* end if */ + power *= 10; + } /* end for */ + printf("\tTotal # of objects with attributes: %lu\n", total); + printf("\tMax. # of attributes to objects: %lu\n", (unsigned long)iter->max_attrs); + + return 0; +} /* print_attr_info() */ + + +/*------------------------------------------------------------------------- * Function: print_freespace_info * * Purpose: Prints information about free space in the file @@ -1270,42 +1470,41 @@ print_storage_summary(const iter_t *iter) HDfprintf(stdout, "File space management strategy: %s\n", FS_STRATEGY_NAME[iter->fs_strategy]); printf("Summary of file space information:\n"); total_meta = - iter->super_size + iter->super_ext_size + iter->ublk_size + - iter->group_ohdr_info.total_size + - iter->dset_ohdr_info.total_size + - iter->dtype_ohdr_info.total_size + - iter->groups_btree_storage_size + - iter->groups_heap_storage_size + - iter->attrs_btree_storage_size + - iter->attrs_heap_storage_size + - iter->datasets_index_storage_size + - iter->datasets_heap_storage_size + - iter->SM_hdr_storage_size + - iter->SM_index_storage_size + - iter->SM_heap_storage_size + - iter->free_hdr; + iter->super_size + iter->super_ext_size + iter->ublk_size + + iter->group_ohdr_info.total_size + + iter->dset_ohdr_info.total_size + + iter->dtype_ohdr_info.total_size + + iter->groups_btree_storage_size + + iter->groups_heap_storage_size + + iter->attrs_btree_storage_size + + iter->attrs_heap_storage_size + + iter->datasets_index_storage_size + + iter->datasets_heap_storage_size + + iter->SM_hdr_storage_size + + iter->SM_index_storage_size + + iter->SM_heap_storage_size + + iter->free_hdr; HDfprintf(stdout, " File metadata: %Hu bytes\n", total_meta); HDfprintf(stdout, " Raw data: %Hu bytes\n", iter->dset_storage_size); percent = ((float)iter->free_space / (float)iter->filesize) * 100; HDfprintf(stdout, " Amount/Percent of tracked free space: %Hu bytes/%3.1f%\n", - iter->free_space, percent); + iter->free_space, percent); if(iter->filesize < (total_meta+iter->dset_storage_size+iter->free_space)) { - unaccount = (total_meta + iter->dset_storage_size + iter->free_space) - iter->filesize; - HDfprintf(stdout, " ??? File has %Hu more bytes accounted for than its size! ???\n", unaccount); + unaccount = (total_meta + iter->dset_storage_size + iter->free_space) - iter->filesize; + HDfprintf(stdout, " ??? File has %Hu more bytes accounted for than its size! ???\n", unaccount); } else { - unaccount = iter->filesize - (total_meta + iter->dset_storage_size + iter->free_space); - HDfprintf(stdout, " Unaccounted space: %Hu bytes\n", unaccount); + unaccount = iter->filesize - (total_meta + iter->dset_storage_size + iter->free_space); + HDfprintf(stdout, " Unaccounted space: %Hu bytes\n", unaccount); } - HDfprintf(stdout, "Total space: %Hu bytes\n", - total_meta+iter->dset_storage_size+iter->free_space+unaccount); + HDfprintf(stdout, "Total space: %Hu bytes\n", total_meta+iter->dset_storage_size+iter->free_space+unaccount); if(iter->nexternal) - HDfprintf(stdout, "External raw data: %Hu bytes\n", iter->dset_external_storage_size); + HDfprintf(stdout, "External raw data: %Hu bytes\n", iter->dset_external_storage_size); return 0; @@ -1313,123 +1512,6 @@ print_storage_summary(const iter_t *iter) /*------------------------------------------------------------------------- - * Function: print_file_metadata - * - * Purpose: Prints file space information for file's metadata - * - * Return: Success: 0 - * - * Failure: Never fails - * - * Programmer: Elena Pourmal - * Saturday, August 12, 2006 - * - *------------------------------------------------------------------------- - */ -static herr_t -print_file_metadata(const iter_t *iter) -{ - HDfprintf(stdout, "File space information for file metadata (in bytes):\n"); - HDfprintf(stdout, "\tSuperblock: %Hu\n", iter->super_size); - HDfprintf(stdout, "\tSuperblock extension: %Hu\n", iter->super_ext_size); - HDfprintf(stdout, "\tUser block: %Hu\n", iter->ublk_size); - - HDfprintf(stdout, "\tObject headers: (total/unused)\n"); - HDfprintf(stdout, "\t\tGroups: %Hu/%Hu\n", - iter->group_ohdr_info.total_size, - iter->group_ohdr_info.free_size); - HDfprintf(stdout, "\t\tDatasets(exclude compact data): %Hu/%Hu\n", - iter->dset_ohdr_info.total_size, - iter->dset_ohdr_info.free_size); - HDfprintf(stdout, "\t\tDatatypes: %Hu/%Hu\n", - iter->dtype_ohdr_info.total_size, - iter->dtype_ohdr_info.free_size); - - HDfprintf(stdout, "\tGroups:\n"); - HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->groups_btree_storage_size); - HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->groups_heap_storage_size); - - HDfprintf(stdout, "\tAttributes:\n"); - HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->attrs_btree_storage_size); - HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->attrs_heap_storage_size); - - HDfprintf(stdout, "\tChunked datasets:\n"); - HDfprintf(stdout, "\t\tIndex: %Hu\n", iter->datasets_index_storage_size); - - HDfprintf(stdout, "\tDatasets:\n"); - HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->datasets_heap_storage_size); - - HDfprintf(stdout, "\tShared Messages:\n"); - HDfprintf(stdout, "\t\tHeader: %Hu\n", iter->SM_hdr_storage_size); - HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->SM_index_storage_size); - HDfprintf(stdout, "\t\tHeap: %Hu\n", iter->SM_heap_storage_size); - - HDfprintf(stdout, "\tFree-space managers:\n"); - HDfprintf(stdout, "\t\tHeader: %Hu\n", iter->free_hdr); - HDfprintf(stdout, "\t\tAmount of free space: %Hu\n", iter->free_space); - - return 0; -} /* print_file_metadata() */ - - -/*------------------------------------------------------------------------- - * Function: print_group_metadata - * - * Purpose: Prints file space information for groups' metadata - * - * Return: Success: 0 - * - * Failure: Never fails - * - * Programmer: Vailin Choi; October 2009 - * - *------------------------------------------------------------------------- - */ -static herr_t -print_group_metadata(const iter_t *iter) -{ - printf("File space information for groups' metadata (in bytes):\n"); - - HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", - iter->group_ohdr_info.total_size, iter->group_ohdr_info.free_size); - - HDfprintf(stdout, "\tB-tree/List: %Hu\n", iter->groups_btree_storage_size); - HDfprintf(stdout, "\tHeap: %Hu\n", iter->groups_heap_storage_size); - - return 0; -} /* print_group_metadata() */ - - -/*------------------------------------------------------------------------- - * Function: print_dataset_metadata - * - * Purpose: Prints file space information for datasets' metadata - * - * Return: Success: 0 - * - * Failure: Never fails - * - * Programmer: Vailin Choi; October 2009 - * - *------------------------------------------------------------------------- - */ -static herr_t -print_dset_metadata(const iter_t *iter) -{ - printf("File space information for datasets' metadata (in bytes):\n"); - - HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", - iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size); - - HDfprintf(stdout, "\tIndex for Chunked datasets: %Hu\n", - iter->datasets_index_storage_size); - HDfprintf(stdout, "\tHeap: %Hu\n", iter->datasets_heap_storage_size); - - return 0; -} /* print_dset_metadata() */ - - -/*------------------------------------------------------------------------- * Function: print_file_statistics * * Purpose: Prints file statistics @@ -1442,9 +1524,9 @@ print_dset_metadata(const iter_t *iter) * Saturday, August 12, 2006 * * Modifications: - * Vailin Choi; October 2009 - * Activate "display_group_metadata", "dislay_dset_metadata" and - * "display_dset_dtype_info". + * Vailin Choi; October 2009 + * Activate "display_group_metadata", "dislay_dset_metadata" and + * "display_dset_dtype_info". * *------------------------------------------------------------------------- */ @@ -1455,29 +1537,29 @@ print_file_statistics(const iter_t *iter) display_file = TRUE; display_group = TRUE; display_dset = TRUE; - display_dset_dtype_meta = TRUE; + display_dset_dtype_meta = TRUE; display_attr = TRUE; - display_free_sections = TRUE; - display_summary = TRUE; + display_free_sections = TRUE; + display_summary = TRUE; display_file_metadata = TRUE; display_group_metadata = TRUE; display_dset_metadata = TRUE; } - if(display_file) print_file_info(iter); - if(display_file_metadata) print_file_metadata(iter); + if(display_file) print_file_info(iter); + if(display_file_metadata) print_file_metadata(iter); - if(display_group) print_group_info(iter); - if(!display_all && display_group_metadata) print_group_metadata(iter); + if(display_group) print_group_info(iter); + if(!display_all && display_group_metadata) print_group_metadata(iter); - if(display_dset) print_dataset_info(iter); + if(display_dset) print_dataset_info(iter); if(display_dset_dtype_meta) print_dset_dtype_meta(iter); - if(!display_all && display_dset_metadata) print_dset_metadata(iter); + if(!display_all && display_dset_metadata) print_dset_metadata(iter); - if(display_attr) print_attr_info(iter); - if(display_free_sections) print_freespace_info(iter); - if(display_summary) print_storage_summary(iter); + if(display_attr) print_attr_info(iter); + if(display_free_sections) print_freespace_info(iter); + if(display_summary) print_storage_summary(iter); } @@ -1533,12 +1615,13 @@ print_statistics(const char *name, const iter_t *iter) int main(int argc, const char *argv[]) { - iter_t iter; - const char *fname = NULL; - hid_t fid; - hid_t fcpl; - struct handler_t *hand; - H5F_info2_t finfo; + iter_t iter; + const char *fname = NULL; + hid_t fid; + hid_t fcpl; + struct handler_t *hand = NULL; + H5F_info2_t finfo; + int i; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -1548,11 +1631,10 @@ main(int argc, const char *argv[]) /* Initialize h5tools lib */ h5tools_init(); - hand = parse_command_line (argc, argv); - if(!hand) { - error_msg("unable to parse command line arguments \n"); - leave(EXIT_FAILURE); - } /* end if */ + + if((hand = parse_command_line(argc, argv))==NULL) { + goto done; + } fname = argv[opt_ind]; @@ -1561,27 +1643,28 @@ main(int argc, const char *argv[]) fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); if(fid < 0) { error_msg("unable to open file \"%s\"\n", fname); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } /* end if */ /* Initialize iter structure */ iter_init(&iter, fid); if(H5Fget_filesize(fid, &iter.filesize) < 0) - warn_msg("Unable to retrieve file size\n"); - assert(iter.filesize != 0); + warn_msg("Unable to retrieve file size\n"); + HDassert(iter.filesize != 0); /* Get storge info for file-level structures */ if(H5Fget_info2(fid, &finfo) < 0) - warn_msg("Unable to retrieve file info\n"); + warn_msg("Unable to retrieve file info\n"); else { - iter.super_size = finfo.super.super_size; - iter.super_ext_size = finfo.super.super_ext_size; - iter.SM_hdr_storage_size = finfo.sohm.hdr_size; - iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size; - iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size; - iter.free_space = finfo.free.tot_space; - iter.free_hdr = finfo.free.meta_size; + iter.super_size = finfo.super.super_size; + iter.super_ext_size = finfo.super.super_ext_size; + iter.SM_hdr_storage_size = finfo.sohm.hdr_size; + iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size; + iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size; + iter.free_space = finfo.free.tot_space; + iter.free_hdr = finfo.free.meta_size; } /* end else */ if((fcpl = H5Fget_create_plist(fid)) < 0) @@ -1592,7 +1675,7 @@ main(int argc, const char *argv[]) if(H5Pget_file_space(fcpl, &iter.fs_strategy, &iter.fs_threshold) < 0) warn_msg("Unable to retrieve file space information\n"); - assert(iter.fs_strategy != 0 && iter.fs_strategy < H5F_FILE_SPACE_NTYPES); + HDassert(iter.fs_strategy != 0 && iter.fs_strategy < H5F_FILE_SPACE_NTYPES); /* get information for free-space sections */ if(freespace_stats(fid, &iter) < 0) @@ -1605,26 +1688,39 @@ main(int argc, const char *argv[]) u = 0; while(hand[u].obj) { if (h5trav_visit(fid, hand[u].obj, TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0) - warn_msg("Unable to traverse object \"%s\"\n", hand[u].obj); - else - print_statistics(hand[u].obj, &iter); + warn_msg("Unable to traverse object \"%s\"\n", hand[u].obj); + else + print_statistics(hand[u].obj, &iter); u++; } /* end while */ } /* end if */ else { if (h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0) - warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname); - else - print_statistics("/", &iter); + warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname); + else + print_statistics("/", &iter); } /* end else */ - if (hand) free(hand); - - if(H5Fclose(fid) < 0) { - error_msg("unable to close file \"%s\"\n", fname); - leave(EXIT_FAILURE); +done: + if(hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + + /* Free iter structure */ + iter_free(&iter); + + if(H5Fclose(fid) < 0) { + error_msg("unable to close file \"%s\"\n", fname); + h5tools_setstatus(EXIT_FAILURE); + } } - leave(EXIT_SUCCESS); + leave(h5tools_getstatus()); } diff --git a/tools/h5stat/h5stat_gentest.c b/tools/h5stat/h5stat_gentest.c index cf17195..20e78ff 100644 --- a/tools/h5stat/h5stat_gentest.c +++ b/tools/h5stat/h5stat_gentest.c @@ -47,7 +47,7 @@ static void gen_file(void) { hid_t fcpl; /* File creation property */ hid_t fapl; /* File access property */ - hid_t file; /* File id */ + hid_t file; /* File id */ hid_t gid; /* Group id */ hid_t type_id; /* Datatype id */ hid_t space_id; /* Dataspace id */ @@ -55,7 +55,7 @@ static void gen_file(void) hid_t dset_id; /* Dataset id */ char name[30]; /* Group name */ char attrname[30]; /* Attribute name */ - int ret; /* Return value */ + int ret; /* Return value */ int i; /* Local index variable */ fapl = H5Pcreate(H5P_FILE_ACCESS); diff --git a/tools/h5stat/testh5stat.sh.in b/tools/h5stat/testh5stat.sh.in index c6c377e..c4e99d7 100644 --- a/tools/h5stat/testh5stat.sh.in +++ b/tools/h5stat/testh5stat.sh.in @@ -32,6 +32,7 @@ STAT_BIN=`pwd`/$STAT # The path of the tool binary CMP='cmp -s' DIFF='diff -c' +CP='cp' nerrors=0 verbose=yes @@ -41,7 +42,79 @@ if test -z "$srcdir"; then srcdir=. fi -test -d ./testfiles || mkdir ./testfiles +# source dirs +SRC_TOOLS="$srcdir/.." +SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" + +# testfiles source dirs for tools +SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES" +SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES" +SRC_H5DIFF_TESTFILES="$SRC_TOOLS/h5diff/testfiles" +SRC_H5COPY_TESTFILES="$SRC_TOOLS/h5copy/testfiles" +SRC_H5REPACK_TESTFILES="$SRC_TOOLS/h5repack/testfiles" +SRC_H5JAM_TESTFILES="$SRC_TOOLS/h5jam/testfiles" +SRC_H5STAT_TESTFILES="$SRC_TOOLS/h5stat/testfiles" +SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/h5import/testfiles" + +TESTDIR=./testfiles +test -d $TESTDIR || mkdir $TESTDIR + +###################################################################### +# test files +# -------------------------------------------------------------------- +# All the test files copy from source directory to test directory +# NOTE: Keep this framework to add/remove test files. +# Any test files from other tools can be used in this framework. +# This list are also used for checking exist. +# Comment '#' without space can be used. +# -------------------------------------------------------------------- +LIST_HDF5_TEST_FILES=" +$SRC_H5STAT_TESTFILES/h5stat_filters.h5 +$SRC_H5STAT_TESTFILES/h5stat_tsohm.h5 +$SRC_H5STAT_TESTFILES/h5stat_newgrat.h5 +" + +LIST_OTHER_TEST_FILES=" +$SRC_H5STAT_TESTFILES/h5stat_help1.ddl +$SRC_H5STAT_TESTFILES/h5stat_help2.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-file.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-F.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-d.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-g.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-dT.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-UD.ddl +$SRC_H5STAT_TESTFILES/h5stat_filters-UT.ddl +$SRC_H5STAT_TESTFILES/h5stat_tsohm.ddl +$SRC_H5STAT_TESTFILES/h5stat_newgrat.ddl +$SRC_H5STAT_TESTFILES/h5stat_newgrat-UG.ddl +$SRC_H5STAT_TESTFILES/h5stat_newgrat-UA.ddl +" + +# +# copy test files and expected output files from source dirs to test dir +# +COPY_TESTFILES="$LIST_HDF5_TEST_FILES $LIST_OTHER_TEST_FILES" + +COPY_TESTFILES_TO_TESTDIR() +{ + # copy test files. Used -f to make sure get a new copy + for tstfile in $COPY_TESTFILES + do + # ignore '#' comment + echo $tstfile | tr -d ' ' | grep '^#' > /dev/null + RET=$? + if [ $RET -eq 1 ]; then + if [ -a $tstfile ]; then + $CP -f $tstfile $TESTDIR + else + echo "Error: FAILED to copy $tstfile" + echo " $tstfile doesn't exist!" + exit $EXIT_FAILURE + fi + fi + done +} # Print a line-line message left justified in a field of 70 characters # beginning with the word "Testing". @@ -60,9 +133,9 @@ TESTING() { # non-zero value. # TOOLTEST() { - expect="$srcdir/testfiles/$1" - actual="./testfiles/`basename $1 .ddl`.out" - actual_err="./testfiles/`basename $1 .ddl`.err" + expect="$TESTDIR/$1" + actual="$TESTDIR/`basename $1 .ddl`.out" + actual_err="$TESTDIR/`basename $1 .ddl`.err" shift # Run test. @@ -71,7 +144,7 @@ TOOLTEST() { echo "#############################" echo "Expected output for '$STAT $@'" echo "#############################" - cd $srcdir/testfiles + cd $TESTDIR $RUNSERIAL $STAT_BIN $@ ) >$actual 2>$actual_err cat $actual_err >> $actual @@ -110,6 +183,8 @@ SKIP() { ### T H E T E S T S ### ############################################################################## ############################################################################## +# prepare for test +COPY_TESTFILES_TO_TESTDIR # Test for help flag TOOLTEST h5stat_help1.ddl -h |