2017-01-27 03:34:12 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Created: swmr_remove_reader.c
|
|
|
|
*
|
|
|
|
* Purpose: Reads data from a randomly selected subset of the datasets
|
|
|
|
* in the SWMR test file. Unlike the regular reader, these
|
|
|
|
* datasets will be shrinking.
|
|
|
|
*
|
|
|
|
* This program is intended to run concurrently with the
|
|
|
|
* swmr_remove_writer program.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
/* Headers */
|
|
|
|
/***********/
|
|
|
|
|
|
|
|
#include "h5test.h"
|
|
|
|
#include "swmr_common.h"
|
|
|
|
|
|
|
|
/*******************/
|
|
|
|
/* Local Variables */
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
static hid_t symbol_tid = -1;
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
/* Local Prototypes */
|
|
|
|
/********************/
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record, hid_t rec_sid);
|
|
|
|
static int read_records(const char *filename, unsigned verbose, unsigned long nseconds, unsigned poll_time,
|
|
|
|
unsigned ncommon, unsigned nrandom);
|
2017-01-27 03:34:12 +08:00
|
|
|
static void usage(void);
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: check_dataset
|
|
|
|
*
|
|
|
|
* Purpose: For a given dataset, checks to make sure that the stated
|
|
|
|
* and actual sizes are the same. If they are not, then
|
|
|
|
* we have an inconsistent dataset due to a SWMR error.
|
|
|
|
*
|
|
|
|
* Parameters: hid_t fid
|
|
|
|
* The SWMR test file's ID.
|
|
|
|
*
|
|
|
|
* unsigned verbose
|
|
|
|
* Whether verbose console output is desired.
|
|
|
|
*
|
|
|
|
* const char *sym_name
|
|
|
|
* The name of the dataset from which to read.
|
|
|
|
*
|
|
|
|
* symbol_t *record
|
|
|
|
* Memory for the record. Must be pre-allocated.
|
|
|
|
*
|
|
|
|
* hid_t rec_sid
|
|
|
|
* The memory dataspace for access. It's always the same so
|
|
|
|
* there is no need to re-create it every time this function
|
|
|
|
* is called.
|
|
|
|
*
|
|
|
|
* Return: Success: 0
|
|
|
|
* Failure: -1
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2020-09-30 22:27:10 +08:00
|
|
|
check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record, hid_t rec_sid)
|
2017-01-27 03:34:12 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t dsid; /* Dataset ID */
|
|
|
|
hid_t file_sid; /* Dataset's space ID */
|
|
|
|
hssize_t snpoints; /* Number of elements in dataset */
|
|
|
|
hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
HDassert(fid >= 0);
|
|
|
|
HDassert(sym_name);
|
|
|
|
HDassert(record);
|
|
|
|
HDassert(rec_sid >= 0);
|
|
|
|
|
|
|
|
/* Open dataset for symbol */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get the dataset's dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((file_sid = H5Dget_space(dsid)) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get the number of elements (= records, for 1-D datasets) */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);
|
|
|
|
|
|
|
|
/* Check if there are records for symbol */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (snpoints > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Choose a random record in the dataset, choosing the last record half
|
|
|
|
* the time */
|
|
|
|
start[1] = (hsize_t)(HDrandom() % (snpoints * 2));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (start[1] > (hsize_t)(snpoints - 1))
|
2017-01-27 03:34:12 +08:00
|
|
|
start[1] = (hsize_t)(snpoints - 1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/* Read record from dataset */
|
2017-01-27 03:34:12 +08:00
|
|
|
#ifdef FILLVAL_WORKS
|
|
|
|
/* When shrinking the dataset, we cannot guarantee that the buffer will
|
|
|
|
* even be touched, unless there is a fill value. Since fill values do
|
|
|
|
* not work with SWMR currently (see note in swmr_generator.c), we
|
|
|
|
* simply initialize rec_id to 0. */
|
|
|
|
record->rec_id = (uint64_t)ULLONG_MAX - 1;
|
2021-01-29 20:55:18 +08:00
|
|
|
#else /* FILLVAL_WORKS */
|
2017-01-27 03:34:12 +08:00
|
|
|
record->rec_id = (uint64_t)0;
|
|
|
|
#endif /* FILLVAL_WORKS */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Verify record value - note that it may be the fill value, because the
|
|
|
|
* chunk may be deleted before the object header has the updated
|
|
|
|
* dimensions */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (record->rec_id != start[1] && record->rec_id != (uint64_t)0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "*** ERROR ***\n");
|
|
|
|
HDfprintf(stderr, "Incorrect record value!\n");
|
2020-09-30 22:27:10 +08:00
|
|
|
HDfprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name,
|
|
|
|
(long long)snpoints, (unsigned long long)record->rec_id);
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
} /* end if */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Close the dataset's dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(file_sid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Close dataset for symbol */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dclose(dsid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} /* end check_dataset() */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: read_records
|
|
|
|
*
|
|
|
|
* Purpose: For a given dataset, checks to make sure that the stated
|
|
|
|
* and actual sizes are the same. If they are not, then
|
|
|
|
* we have an inconsistent dataset due to a SWMR error.
|
|
|
|
*
|
|
|
|
* The "common" datasets are a random selection from among
|
|
|
|
* the level 0 datasets. The "random" datasets are a random
|
|
|
|
* selection from among all the file's datasets. This scheme
|
|
|
|
* ensures that the level 0 datasets are interrogated vigorously.
|
|
|
|
*
|
|
|
|
* Parameters: const char *filename
|
|
|
|
* The SWMR test file's name.
|
|
|
|
*
|
|
|
|
* unsigned verbose
|
|
|
|
* Whether verbose console output is desired.
|
|
|
|
*
|
|
|
|
* unsigned long nseconds
|
|
|
|
* The amount of time to read records (ns).
|
|
|
|
*
|
|
|
|
* unsigned poll_time
|
|
|
|
* The amount of time to sleep (s).
|
|
|
|
*
|
|
|
|
* unsigned ncommon
|
|
|
|
* The number of common/non-random datasets that will be opened.
|
|
|
|
*
|
|
|
|
* unsigned nrandom
|
|
|
|
* The number of random datasets that will be opened.
|
|
|
|
*
|
|
|
|
* Return: Success: 0
|
|
|
|
* Failure: -1
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2020-09-30 22:27:10 +08:00
|
|
|
read_records(const char *filename, unsigned verbose, unsigned long nseconds, unsigned poll_time,
|
|
|
|
unsigned ncommon, unsigned nrandom)
|
2017-01-27 03:34:12 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
time_t start_time; /* Starting time */
|
|
|
|
time_t curr_time; /* Current time */
|
|
|
|
symbol_info_t **sym_com = NULL; /* Pointers to array of common dataset IDs */
|
|
|
|
symbol_info_t **sym_rand = NULL; /* Pointers to array of random dataset IDs */
|
|
|
|
hid_t mem_sid; /* Memory dataspace ID */
|
|
|
|
hid_t fid; /* SWMR test file ID */
|
|
|
|
hid_t fapl; /* File access property list */
|
|
|
|
symbol_t record; /* The record to add to the dataset */
|
|
|
|
unsigned v; /* Local index variable */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
HDassert(filename);
|
|
|
|
HDassert(nseconds != 0);
|
|
|
|
HDassert(poll_time != 0);
|
|
|
|
|
|
|
|
/* Reset the record */
|
|
|
|
/* (record's 'info' field might need to change for each record written, also) */
|
|
|
|
HDmemset(&record, 0, sizeof(record));
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Choosing datasets\n");
|
|
|
|
|
|
|
|
/* Allocate space for 'common' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (ncommon > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Allocate array to hold pointers to symbols for common datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (sym_com = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * ncommon)))
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Open the common datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (v = 0; v < ncommon; v++) {
|
|
|
|
unsigned offset; /* Offset of symbol to use */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Determine the offset of the symbol, within level 0 symbols */
|
|
|
|
/* (level 0 symbols are the most common symbols) */
|
2020-09-30 22:27:10 +08:00
|
|
|
offset = (unsigned)HDrandom() % symbol_count[0];
|
2017-01-27 03:34:12 +08:00
|
|
|
sym_com[v] = &symbol_info[0][offset];
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
|
|
|
|
} /* end for */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Allocate space for 'random' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nrandom > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Allocate array to hold pointers to symbols for random datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (sym_rand = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * nrandom)))
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Determine the random datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (v = 0; v < nrandom; v++) {
|
|
|
|
symbol_info_t *sym; /* Symbol to use */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Determine the symbol, within all symbols */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (sym = choose_dataset()))
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
sym_rand[v] = sym;
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Random symbol #%u = '%s'\n", v, sym->name);
|
|
|
|
} /* end for */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create a dataspace for the record to read */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((mem_sid = H5Screate(H5S_SCALAR)) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Reading records\n");
|
|
|
|
|
|
|
|
/* Get the starting time */
|
|
|
|
start_time = HDtime(NULL);
|
2020-09-30 22:27:10 +08:00
|
|
|
curr_time = start_time;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create file access property list */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fapl = h5_fileaccess()) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Loop over reading records until [at least] the correct # of seconds have passed */
|
2020-09-30 22:27:10 +08:00
|
|
|
while (curr_time < (time_t)(start_time + (time_t)nseconds)) {
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
|
|
|
HDfprintf(stderr, "Opening file: %s\n", filename);
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Open the file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check 'common' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (ncommon > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Checking common symbols\n");
|
|
|
|
|
|
|
|
/* Iterate over common datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (v = 0; v < ncommon; v++) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Check common dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (check_dataset(fid, verbose, sym_com[v]->name, &record, mem_sid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
HDmemset(&record, 0, sizeof(record));
|
|
|
|
} /* end for */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Check 'random' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nrandom > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Checking random symbols\n");
|
|
|
|
|
|
|
|
/* Iterate over random datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (v = 0; v < nrandom; v++) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Check random dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (check_dataset(fid, verbose, sym_rand[v]->name, &record, mem_sid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
HDmemset(&record, 0, sizeof(record));
|
|
|
|
} /* end for */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Closing file\n");
|
|
|
|
|
|
|
|
/* Close the file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(fid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Sleep for the appropriate # of seconds */
|
|
|
|
HDsleep(poll_time);
|
|
|
|
|
|
|
|
/* Retrieve the current time */
|
|
|
|
curr_time = HDtime(NULL);
|
|
|
|
} /* end while */
|
|
|
|
|
|
|
|
/* Close the fapl */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(fapl) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Close the memory dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(mem_sid) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Closing datasets\n");
|
|
|
|
|
|
|
|
/* Close 'random' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nrandom > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Release array holding dataset ID's for random datasets */
|
|
|
|
HDfree(sym_rand);
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
/* Close 'common' datasets, if any */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (ncommon > 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* Release array holding dataset ID's for common datasets */
|
|
|
|
HDfree(sym_com);
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} /* end read_records() */
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2019-08-16 05:46:00 +08:00
|
|
|
HDprintf("\n");
|
|
|
|
HDprintf("Usage error!\n");
|
|
|
|
HDprintf("\n");
|
|
|
|
HDprintf("Usage: swmr_remove_reader [-q] [-s <# of seconds to sleep between\n");
|
|
|
|
HDprintf(" polling>] [-h <# of common symbols to poll>] [-l <# of random symbols\n");
|
|
|
|
HDprintf(" to poll>] [-r <random seed>] <# of seconds to test>\n");
|
|
|
|
HDprintf("\n");
|
|
|
|
HDprintf("Defaults to verbose (no '-q' given), 1 second between polling ('-s 1'),\n");
|
|
|
|
HDprintf("5 common symbols to poll ('-h 5'), 10 random symbols to poll ('-l 10'),\n");
|
|
|
|
HDprintf("and will generate a random seed (no -r given).\n");
|
|
|
|
HDprintf("\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2020-04-21 07:12:00 +08:00
|
|
|
}
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int
|
2022-01-29 06:30:33 +08:00
|
|
|
main(int argc, char *argv[])
|
2017-01-27 03:34:12 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
long nseconds = 0; /* # of seconds to test */
|
|
|
|
int poll_time = 1; /* # of seconds between polling */
|
|
|
|
int ncommon = 5; /* # of common symbols to poll */
|
|
|
|
int nrandom = 10; /* # of random symbols to poll */
|
|
|
|
unsigned verbose = 1; /* Whether to emit some informational messages */
|
|
|
|
unsigned use_seed = 0; /* Set to 1 if a seed was set on the command line */
|
|
|
|
unsigned random_seed = 0; /* Random # seed */
|
|
|
|
unsigned u; /* Local index variables */
|
|
|
|
int temp;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Parse command line options */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (argc < 2)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
2020-09-30 22:27:10 +08:00
|
|
|
if (argc > 1) {
|
2017-01-27 03:34:12 +08:00
|
|
|
u = 1;
|
2020-09-30 22:27:10 +08:00
|
|
|
while (u < (unsigned)argc) {
|
|
|
|
if (argv[u][0] == '-') {
|
|
|
|
switch (argv[u][1]) {
|
2017-01-27 03:34:12 +08:00
|
|
|
/* # of common symbols to poll */
|
|
|
|
case 'h':
|
|
|
|
ncommon = HDatoi(argv[u + 1]);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (ncommon < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
u += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* # of random symbols to poll */
|
|
|
|
case 'l':
|
|
|
|
nrandom = HDatoi(argv[u + 1]);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nrandom < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
u += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Be quiet */
|
|
|
|
case 'q':
|
|
|
|
verbose = 0;
|
|
|
|
u++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Random # seed */
|
|
|
|
case 'r':
|
|
|
|
use_seed = 1;
|
2020-09-30 22:27:10 +08:00
|
|
|
temp = HDatoi(argv[u + 1]);
|
|
|
|
if (temp < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
else
|
|
|
|
random_seed = (unsigned)temp;
|
|
|
|
u += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* # of seconds between polling */
|
|
|
|
case 's':
|
|
|
|
poll_time = HDatoi(argv[u + 1]);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (poll_time < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
u += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
} /* end switch */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2017-01-27 03:34:12 +08:00
|
|
|
else {
|
|
|
|
/* Get the number of records to append */
|
|
|
|
nseconds = HDatol(argv[u]);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (nseconds <= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
|
|
|
|
u++;
|
|
|
|
} /* end else */
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end while */
|
|
|
|
} /* end if */
|
|
|
|
if (nseconds <= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
2020-09-30 22:27:10 +08:00
|
|
|
if (poll_time >= nseconds)
|
2017-01-27 03:34:12 +08:00
|
|
|
usage();
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Parameters:\n");
|
|
|
|
HDfprintf(stderr, "\t# of seconds between polling = %d\n", poll_time);
|
|
|
|
HDfprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon);
|
|
|
|
HDfprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom);
|
|
|
|
HDfprintf(stderr, "\t# of seconds to test = %ld\n", nseconds);
|
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
/* Set the random seed */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (0 == use_seed) {
|
2017-01-27 03:34:12 +08:00
|
|
|
struct timeval t;
|
|
|
|
HDgettimeofday(&t, NULL);
|
|
|
|
random_seed = (unsigned)(t.tv_usec);
|
|
|
|
} /* end if */
|
|
|
|
HDsrandom(random_seed);
|
|
|
|
/* ALWAYS emit the random seed for possible debugging */
|
|
|
|
HDfprintf(stderr, "Using reader random seed: %u\n", random_seed);
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Generating symbol names\n");
|
|
|
|
|
|
|
|
/* Generate dataset names */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (generate_symbols() < 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Error generating symbol names!\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2017-01-27 03:34:12 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
/* Create datatype for creating datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((symbol_tid = create_symbol_datatype()) < 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Reading records from datasets */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon,
|
|
|
|
(unsigned)nrandom) < 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Error reading records from datasets!\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2017-01-27 03:34:12 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Releasing symbols\n");
|
|
|
|
|
|
|
|
/* Clean up the symbols */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (shutdown_symbols() < 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Error releasing symbols!\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2017-01-27 03:34:12 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
/* Emit informational message */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (verbose)
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Closing objects\n");
|
|
|
|
|
|
|
|
/* Close objects created */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Tclose(symbol_tid) < 0) {
|
2017-01-27 03:34:12 +08:00
|
|
|
HDfprintf(stderr, "Error closing symbol datatype!\n");
|
2019-09-07 09:06:26 +08:00
|
|
|
HDexit(EXIT_FAILURE);
|
2017-01-27 03:34:12 +08:00
|
|
|
} /* end if */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|