added test

This commit is contained in:
Ed Hartnett 2018-06-19 14:59:07 -06:00
parent 77936f2884
commit eafe151f13
6 changed files with 169 additions and 49 deletions

View File

@ -18,31 +18,6 @@
int nc4typelen(nc_type type);
/**
* @internal Get the attribute list for either a varid or NC_GLOBAL
*
* @param grp Group
* @param varid Variable ID | NC_BLOGAL
* @param varp Pointer into which to return created NC_VAR_INFO_T instance
*
* @return Attribute list | NULL
* @author Dennis Heimbigner
*/
static NCindex *
getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp)
{
if (varid == NC_GLOBAL) {
if(varp) *varp = NULL;
return grp->att;
} else {
NC_VAR_INFO_T* var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
if (!var) return NULL;
assert(var->hdr.id == varid);
if(varp) *varp = var;
return var->att;
}
}
/**
* @internal Get the attribute list for either a varid or NC_GLOBAL
*
@ -56,7 +31,7 @@ getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp)
* @author Dennis Heimbigner, Ed Hartnett
*/
static int
getattlist2(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp,
getattlist(NC_GRP_INFO_T *grp, int varid, NC_VAR_INFO_T **varp,
NCindex **attlist)
{
NC_VAR_INFO_T* var;
@ -143,7 +118,7 @@ NC4_rename_att(int ncid, int varid, const char *name, const char *newname)
/* Get the list of attributes. */
/* if (!(list = getattlist(grp,varid,&var))) */
/* return NC_ENOTVAR; */
if ((retval = getattlist2(grp, varid, &var, &list)))
if ((retval = getattlist(grp, varid, &var, &list)))
return retval;
/* Is new name in use? */
@ -257,10 +232,8 @@ NC4_del_att(int ncid, int varid, const char *name)
/* Get either the global or a variable attribute list. */
/* if (!(attlist = getattlist(grp,varid,NULL))) */
/* return NC_ENOTVAR; */
if ((retval = getattlist2(grp, varid, &var, &attlist)))
if ((retval = getattlist(grp, varid, &var, &attlist)))
return retval;
/* if (!(attlist = getattlist(grp,varid,NULL))) */
/* return NC_ENOTVAR; */
/* Determine the location id in the HDF5 file. */
if (varid == NC_GLOBAL)
@ -351,11 +324,8 @@ NC4_put_att(int ncid, int varid, const char *name, nc_type file_type,
/* Find att, if it exists. (Must check varid first or nc_test will
* break.) */
if ((ret = getattlist2(grp, varid, &var, &attlist)))
if ((ret = getattlist(grp, varid, &var, &attlist)))
return ret;
/* attlist = getattlist(grp,varid,&var); */
/* if(attlist == NULL) */
/* return NC_ENOTVAR; */
/* The length needs to be positive (cast needed for braindead
systems with signed size_t). */

View File

@ -2073,8 +2073,9 @@ read_var(NC_GRP_INFO_T *grp, hid_t datasetid, const char *obj_name,
}
/* Read variable attributes. */
if ((retval = nc4_read_var_atts(grp, var)))
BAIL(retval);
var->atts_not_read = 1;
/* if ((retval = nc4_read_var_atts(grp, var))) */
/* BAIL(retval); */
/* Is this a deflated variable with a chunksize greater than the
* current cache size? */
@ -2466,6 +2467,8 @@ nc4_rec_read_metadata(NC_GRP_INFO_T *grp)
/* Defer the reading of global atts until someone asks for one. */
grp->atts_not_read = 1;
/* if ((retval = nc4_read_grp_atts(grp))) */
/* return retval; */
/* when exiting define mode, mark all variable written */
for (i=0; i<ncindexsize(grp->vars); i++) {

View File

@ -116,6 +116,7 @@ nc4_get_att(int ncid, int varid, const char *name, nc_type *xtype,
NC_GRP_INFO_T *grp;
NC_HDF5_FILE_INFO_T *h5;
NC_ATT_INFO_T *att = NULL;
NC_VAR_INFO_T *var;
int my_attnum = -1;
int need_to_convert = 0;
int range_error = NC_NOERR;
@ -136,9 +137,9 @@ nc4_get_att(int ncid, int varid, const char *name, nc_type *xtype,
return retval;
/* Check varid */
if (varid != NC_GLOBAL) {
NC_VAR_INFO_T* var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
if(var == NULL)
if (varid != NC_GLOBAL)
{
if (!(var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid)))
return NC_ENOTVAR;
assert(var->hdr.id == varid);
}
@ -150,11 +151,19 @@ nc4_get_att(int ncid, int varid, const char *name, nc_type *xtype,
if ((retval = nc4_normalize_name(name, norm_name)))
BAIL(retval);
/* Read the global atts for this group, if they have not been
* read. */
if (varid == NC_GLOBAL && grp->atts_not_read)
if ((retval = nc4_read_grp_atts(grp)))
return retval;
/* Read the atts for this group/var, if they have not been read. */
if (varid == NC_GLOBAL)
{
if (grp->atts_not_read)
if ((retval = nc4_read_grp_atts(grp)))
return retval;
}
else
{
if (var->atts_not_read)
if ((retval = nc4_read_var_atts(grp, var)))
return retval;
}
/* If this is one of the reserved atts, use nc_get_att_special. */
if (nc->ext_ncid == ncid && varid == NC_GLOBAL) {

View File

@ -121,8 +121,8 @@ TESTS += run_par_test.sh
endif
if ENABLE_METADATA_PERF
check_PROGRAMS += bigmeta openbigmeta
TESTS += perftest.sh
check_PROGRAMS += bigmeta openbigmeta tst_attsperf
TESTS += tst_attsperf perftest.sh
endif
EXTRA_DIST = run_par_test.sh run_bm.sh run_bm_test1.sh \

6
nc_test4/perftest.sh Normal file → Executable file
View File

@ -1,8 +1,8 @@
#!/bin/sh
#PROF=1
#DEBUG=1
#MEM=1
PROF=1
DEBUG=1
MEM=1
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh

138
nc_test4/tst_attsperf.c Normal file
View File

@ -0,0 +1,138 @@
/* This is part of the netCDF package. Copyright 2018 University
* Corporation for Atmospheric Research/Unidata. See COPYRIGHT file
* for conditions of use.
*
* Test the netCDF-4 attribute code.
*
* WARNING: do not attempt to run this under windows because of the use
* of gettimeofday().
*
* Ed Hartnett 6/19/18
*/
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include "nc4internal.h"
#include <sys/time.h>
#define TEST "tst_attsperf"
#define VAR "bigvar"
#define NDIMS 2
#define DIM0 "d0"
#define DIM1 "d1"
#define DIMSIZE0 16
#define DIMSIZE1 512
#define TOTALSIZE (DIMSIZE0 * DIMSIZE1)
#define NUM_ATTS 100
#define ATT_LEN 10
#define NUM_VARS 100
int
add_attributes(int ncid, int varid)
{
char att_name[NC_MAX_NAME + 1];
double att_data[ATT_LEN];
int i, a;
/* Fill up data. */
for (i = 0; i < ATT_LEN; i++)
att_data[i] = i;
/* Write a bunch of attributes. */
for (a = 0; a < NUM_ATTS; a++)
{
sprintf(att_name, "%s_varid_%d_att_%d", TEST, varid, a);
if (nc_put_att_double(ncid, varid, att_name, NC_DOUBLE,
ATT_LEN, att_data)) ERR;
}
return 0;
}
int
buildfile(int file_no)
{
int ncid, varid;
int dimids[NDIMS];
char file_name[NC_MAX_NAME + 1];
int v;
sprintf(file_name, "%s_%d.nc", TEST, file_no);
if (nc_create(file_name, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, DIM0, DIMSIZE0, &dimids[0])) ERR;
if (nc_def_dim(ncid, DIM1, DIMSIZE1, &dimids[1])) ERR;
for (v = 0; v < NUM_VARS; v++)
{
char var_name[NC_MAX_NAME + 1];
sprintf(var_name, "%s_var_%d", TEST, v);
if (nc_def_var(ncid, var_name, NC_INT, NDIMS, dimids, &varid)) ERR;
if (add_attributes(ncid, v)) ERR;
}
if (add_attributes(ncid, NC_GLOBAL)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_close(ncid)) ERR;
return 0;
}
long long
readfile(int inq_all)
{
int ncid;
struct timeval starttime, endtime;
long long delta;
long long startt, endt;
char file_name[NC_MAX_NAME + 1];
sprintf(file_name, "%s_%d.nc", TEST, inq_all);
/* Start the clock. */
gettimeofday(&starttime, NULL);
/* Open the file. */
if (nc_open(file_name, NC_NETCDF4, &ncid)) ERR;
/* Simulate old open by triggering attribute reads, if desired. */
if (inq_all)
{
int natts;
int v;
/* When checking the number of atts, we trigger the read. */
if (nc_inq(ncid, NULL, NULL, &natts, NULL)) ERR;
for (v = 0; v < NUM_VARS; v++)
if (nc_inq_varnatts(ncid, v, &natts)) ERR;
}
gettimeofday(&endtime, NULL);
/* Close the file. */
if (nc_close(ncid)) ERR;
/* Compute the time delta */
startt = (1000000 * starttime.tv_sec) + starttime.tv_usec;
endt = (1000000 * endtime.tv_sec) + endtime.tv_usec;
delta = endt - startt;
return delta;
}
int
main(int argc, char **argv)
{
long long zerodelta, onedelta, factor;
printf("testing speed of open with files with lots of metadata...\n");
if (buildfile(0)) ERR;
if (buildfile(1)) ERR;
if ((zerodelta = readfile(0)) == -1) ERR;
if ((onedelta = readfile(1)) == -1) ERR;
/* Print results to the millisec */
factor = onedelta / zerodelta;
printf("Lazy Atts time=%lld Read Atts at Open time=%lld Speedup=%lld\n",
zerodelta, onedelta, factor);
SUMMARIZE_ERR;
FINAL_RESULTS;
}