summaryrefslogtreecommitdiffstats
path: root/tools/h5stat/h5stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5stat/h5stat.c')
-rw-r--r--tools/h5stat/h5stat.c327
1 files changed, 93 insertions, 234 deletions
diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c
index c69d801..f03efd7 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -47,8 +47,7 @@ typedef struct ohdr_info_t {
/* Info to pass to the iteration functions */
typedef struct iter_t {
- const char *container; /* Full name of the container object */
- unsigned long curr_depth; /* Current depth of hierarchy */
+ hid_t fid; /* File ID */
unsigned long uniq_groups; /* Number of unique groups */
unsigned long uniq_dsets; /* Number of unique datasets */
@@ -56,7 +55,6 @@ typedef struct iter_t {
unsigned long uniq_links; /* Number of unique links */
unsigned long uniq_others; /* Number of other unique objects */
- unsigned long max_depth; /* Maximum depth of hierarchy */
unsigned long max_links; /* Maximum # of links to an object */
hsize_t max_fanout; /* Maximum fanout from a group */
unsigned long num_small_groups[SIZE_SMALL_GROUPS]; /* Size of small groups tracked */
@@ -95,16 +93,6 @@ typedef struct iter_t {
} iter_t;
-/* Table containing object id and object name */
-static struct {
- int nalloc; /* number of slots allocated */
- int nobjs; /* number of objects */
- struct {
- haddr_t id; /* object number */
- char *name; /* full object name */
- } *obj;
-} idtab_g;
-
const char *progname = "h5stat";
int d_status = EXIT_SUCCESS;
static int display_all = TRUE;
@@ -260,123 +248,6 @@ ceil_log10(unsigned long x)
/*-------------------------------------------------------------------------
- * Function: sym_insert
- *
- * Purpose: Add a symbol to the table.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- *-------------------------------------------------------------------------
- */
-static void
-sym_insert(H5O_info_t *oi, const char *name)
-{
- /* Don't add it if the link count is 1 because such an object can only
- * have one name. */
- if(oi->rc > 1) {
- int n;
-
- /* Extend the table */
- if(idtab_g.nobjs >= idtab_g.nalloc) {
- idtab_g.nalloc = MAX(256, 2 * idtab_g.nalloc);
- idtab_g.obj = realloc(idtab_g.obj, idtab_g.nalloc * sizeof(idtab_g.obj[0]));
- } /* end if */
-
- /* Insert the entry */
- n = idtab_g.nobjs++;
- idtab_g.obj[n].id = oi->addr;
- idtab_g.obj[n].name = strdup(name);
- } /* end if */
-} /* end sym_insert() */
-
-
-/*-------------------------------------------------------------------------
- * Function: sym_lookup
- *
- * Purpose: Find another name for the specified object.
- *
- * Return: Success: Ptr to another name.
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-sym_lookup(H5O_info_t *oi)
-{
- int n;
-
- /*only one name possible*/
- if(oi->rc < 2)
- return NULL;
-
- for(n = 0; n < idtab_g.nobjs; n++)
- if(idtab_g.obj[n].id == oi->addr)
- return idtab_g.obj[n].name;
-
- return NULL;
-} /* end sym_lookup() */
-
-
-/*-------------------------------------------------------------------------
- * Function: fix_name
- *
- * Purpose: Returns a malloc'd buffer that contains the PATH and BASE
- * names separated by a single slash. It also removes duplicate
- * and trailing slashes.
- *
- * Return: Success: Ptr to fixed name from malloc()
- *
- * Failure: NULL
- *
- * Programmer: Robb Matzke
- * Thursday, January 21, 1999
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static char *
-fix_name(const char *path, const char *base)
-{
- size_t n = (path ? strlen(path) : 0) + (base ? strlen(base) : 0) + 3;
- char *s = malloc(n), prev='\0';
- size_t len = 0;
-
- if (path) {
- /* Path, followed by slash */
- for (/*void*/; *path; path++)
- if ('/'!=*path || '/'!=prev)
- prev = s[len++] = *path;
- if ('/' != prev)
- prev = s[len++] = '/';
- }
-
- if (base) {
- /* Base name w/o trailing slashes */
- const char *end = base + strlen(base);
- while (end > base && '/' == end[-1])
- --end;
-
- for (/*void*/; base < end; base++)
- if ('/' != *base || '/' != prev)
- prev = s[len++] = *base;
- }
-
- s[len] = '\0';
- return s;
-}
-
-
-/*-------------------------------------------------------------------------
* Function: attribute_stats
*
* Purpose: Gather statistics about attributes on an object
@@ -453,25 +324,21 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi)
*-------------------------------------------------------------------------
*/
static herr_t
-group_stats(hid_t group, const char *name, const char *fullname,
- const H5O_info_t *oi, H5L_iterate_t walk, iter_t *iter)
+group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
{
- const char *last_container;
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++;
- if(iter->curr_depth > iter->max_depth)
- iter->max_depth = iter->curr_depth;
/* Get object header information */
iter->group_ohdr_info.total_size += oi->hdr.space.total;
iter->group_ohdr_info.free_size += oi->hdr.space.free;
/* Get group information */
- ret = H5Gget_info_by_name(group, name, &ginfo, H5P_DEFAULT);
+ ret = H5Gget_info_by_name(iter->fid, name, &ginfo, H5P_DEFAULT);
assert(ret >= 0);
/* Update link stats */
@@ -506,18 +373,6 @@ group_stats(hid_t group, const char *name, const char *fullname,
ret = attribute_stats(iter, oi);
assert(ret >= 0);
- /* Update current container info */
- last_container = iter->container;
- iter->container = fullname;
- iter->curr_depth++;
-
- /* Recursively descend into current group's objects */
- H5Literate_by_name(group, name, H5_INDEX_NAME, H5_ITER_INC, NULL, walk, iter, H5P_DEFAULT);
-
- /* Revert current container info */
- iter->container = last_container;
- iter->curr_depth--;
-
return 0;
} /* end group_stats() */
@@ -549,7 +404,7 @@ group_stats(hid_t group, const char *name, const char *fullname,
*-------------------------------------------------------------------------
*/
static herr_t
-dataset_stats(hid_t group, const char *name, const H5O_info_t *oi, iter_t *iter)
+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 */
@@ -575,7 +430,7 @@ dataset_stats(hid_t group, const char *name, const H5O_info_t *oi, iter_t *iter)
iter->dset_ohdr_info.total_size += oi->hdr.space.total;
iter->dset_ohdr_info.free_size += oi->hdr.space.free;
- did = H5Dopen2(group, name, H5P_DEFAULT);
+ did = H5Dopen2(iter->fid, name, H5P_DEFAULT);
assert(did > 0);
/* Update dataset metadata info */
@@ -710,89 +565,90 @@ dataset_stats(hid_t group, const char *name, const H5O_info_t *oi, iter_t *iter)
/*-------------------------------------------------------------------------
- * Function: walk
+ * Function: obj_stats
*
- * Purpose: Gather statistics about the file
+ * Purpose: Gather statistics about an object
*
* Return: Success: 0
- * Failure: -1
*
- * Programmer: Quincey Koziol
- * Tuesday, August 16, 2005
+ * Failure: -1
*
- * Modifications:
+ * Programmer: Quincey Koziol
+ * Tuesday, November 6, 2007
*
*-------------------------------------------------------------------------
*/
static herr_t
-walk(hid_t group, const char *name, const H5L_info_t *linfo, void *_iter)
+obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
+ void *_iter)
{
iter_t *iter = (iter_t *)_iter;
- char *fullname = NULL;
- herr_t ret; /* Generic return value */
-
- if(!linfo || linfo->type == H5L_TYPE_HARD) {
- H5O_info_t oi;
- char *s;
-
- /* Get object information */
- ret = H5Oget_info_by_name(group, name, &oi, H5P_DEFAULT);
- assert(ret >= 0);
-
- /* If the object has already been printed then just show the object ID
- * and return. */
- if((s = sym_lookup(&oi))) {
- printf("%s same as %s\n", name, s);
- } else {
- /* Get the full object name */
- fullname = fix_name(iter->container, name);
- sym_insert(&oi, fullname);
-
- /* Gather some statistics about the object */
- if(oi.rc > iter->max_links)
- iter->max_links = oi.rc;
-
- switch(oi.type) {
- case H5O_TYPE_GROUP:
- group_stats(group, name, fullname, &oi, walk, iter);
- break;
-
- case H5O_TYPE_DATASET:
- dataset_stats(group, name, &oi, iter);
- break;
-
- case H5O_TYPE_NAMED_DATATYPE:
- /* Gather statistics about this type of object */
- iter->uniq_types++;
- break;
-
- default:
- /* Gather statistics about this type of object */
- iter->uniq_others++;
- break;
- } /* end switch */
- }
- } /* end if */
- else {
- switch(linfo->type) {
- case H5L_TYPE_SOFT:
- case H5L_TYPE_EXTERNAL:
- /* Gather statistics about links and UD links */
- iter->uniq_links++;
+
+ /* If the object has already been seen then just return */
+ if(NULL == already_visited) {
+ /* Gather some general statistics about the object */
+ if(oi->rc > iter->max_links)
+ iter->max_links = oi->rc;
+
+ switch(oi->type) {
+ case H5O_TYPE_GROUP:
+ group_stats(iter, path, oi);
+ break;
+
+ case H5O_TYPE_DATASET:
+ dataset_stats(iter, path, oi);
+ break;
+
+ case H5O_TYPE_NAMED_DATATYPE:
+ /* Gather statistics about this type of object */
+ iter->uniq_types++;
break;
default:
/* Gather statistics about this type of object */
iter->uniq_others++;
break;
- } /* end switch() */
- } /* end else */
+ } /* end switch */
+ } /* end if */
- if(fullname)
- free(fullname);
+ return 0;
+} /* end obj_stats() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: lnk_stats
+ *
+ * Purpose: Gather statistics about a link
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Quincey Koziol
+ * Tuesday, November 6, 2007
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+lnk_stats(const char UNUSED *path, const H5L_info_t *li, void *_iter)
+{
+ iter_t *iter = (iter_t *)_iter;
+
+ switch(li->type) {
+ case H5L_TYPE_SOFT:
+ case H5L_TYPE_EXTERNAL:
+ /* Gather statistics about links and UD links */
+ iter->uniq_links++;
+ break;
+
+ default:
+ /* Gather statistics about this type of object */
+ iter->uniq_others++;
+ break;
+ } /* end switch() */
return 0;
-}
+} /* end lnk_stats() */
/*-------------------------------------------------------------------------
@@ -915,13 +771,13 @@ parse_command_line(int argc, const char *argv[])
*-------------------------------------------------------------------------
*/
static herr_t
-iter_init(iter_t *iter)
+iter_init(iter_t *iter, hid_t fid)
{
/* Clear everything to zeros */
- memset(iter, 0, sizeof(*iter));
+ HDmemset(iter, 0, sizeof(*iter));
- /* Initialize non-zero information */
- iter->container = "/";
+ /* Set the file ID for later use in callbacks */
+ iter->fid = fid;
return 0;
}
@@ -953,7 +809,6 @@ print_file_info(const iter_t *iter)
printf("\t# of unique links: %lu\n", iter->uniq_links);
printf("\t# of unique other: %lu\n", iter->uniq_others);
printf("\tMax. # of links to object: %lu\n", iter->max_links);
- printf("\tMax. depth of hierarchy: %lu\n", iter->max_depth);
HDfprintf(stdout, "\tMax. # of objects in group: %Hu\n", iter->max_fanout);
return 0;
@@ -1318,8 +1173,6 @@ main(int argc, const char *argv[])
const char *fname = NULL;
hid_t fid;
struct handler_t *hand;
- char root[] = "/";
- int i;
H5F_info_t finfo;
@@ -1329,25 +1182,23 @@ main(int argc, const char *argv[])
/* Initialize h5tools lib */
h5tools_init();
hand = parse_command_line (argc, argv);
- if (!hand) {
+ if(!hand) {
error_msg(progname, "unable to parse command line arguments \n");
leave(EXIT_FAILURE);
- }
+ } /* end if */
fname = argv[opt_ind];
- if(!display_object)
- hand[0].obj = root;
printf("Filename: %s\n", fname);
fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
- if (fid < 0) {
+ if(fid < 0) {
error_msg(progname, "unable to open file \"%s\"\n", fname);
leave(EXIT_FAILURE);
- }
+ } /* end if */
/* Initialize iter structure */
- iter_init(&iter);
+ iter_init(&iter, fid);
/* Get storge info for SOHM's btree/list/heap and superblock extension */
if(H5Fget_info(fid, &finfo) < 0)
@@ -1357,15 +1208,23 @@ main(int argc, const char *argv[])
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;
- }
+ } /* end else */
/* Walk the objects or all file */
- i = 0;
- while(hand[i].obj) {
- walk(fid, hand[i].obj, NULL, &iter);
- print_statistics(hand[i].obj, &iter);
- i++;
- } /* end while */
+ if(display_object) {
+ unsigned u;
+
+ u = 0;
+ while(hand[u].obj) {
+ h5trav_visit(fid, hand[u].obj, TRUE, TRUE, obj_stats, lnk_stats, &iter);
+ print_statistics(hand[u].obj, &iter);
+ u++;
+ } /* end while */
+ } /* end if */
+ else {
+ h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter);
+ print_statistics("/", &iter);
+ } /* end else */
free(hand);