mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
further development of mem testing program
This commit is contained in:
parent
2d3f4be2ea
commit
23656e31ed
@ -15,39 +15,31 @@
|
|||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
#define FILE_NAME "tst_mem1.nc"
|
#define FILE_NAME "tst_mem1.nc"
|
||||||
#define NUM_FILE_OPENS 100
|
#define NUM_FILE_OPENS 10000
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int dataset_id, time_id, dummyvar_id, idx;
|
int ncid, varid, idx;
|
||||||
size_t start[1] = {0};
|
|
||||||
size_t count[1] = {100};
|
|
||||||
double data[100];
|
|
||||||
struct rusage r_usage;
|
struct rusage r_usage;
|
||||||
|
|
||||||
for (idx = 0; idx < 100; idx++)
|
|
||||||
{
|
|
||||||
data[idx]=-99;
|
|
||||||
};
|
|
||||||
|
|
||||||
printf("\n*** Testing netcdf-4 memory use.\n");
|
printf("\n*** Testing netcdf-4 memory use.\n");
|
||||||
printf("*** testing mem use opening/closing file...");
|
printf("*** testing mem use opening/closing file...");
|
||||||
{
|
{
|
||||||
long my_rss = 0;
|
long my_rss = 0;
|
||||||
|
|
||||||
if (nc_create(FILE_NAME, NC_CLOBBER | NC_NETCDF4, &dataset_id)) ERR;
|
/* if (nc_create(FILE_NAME, NC_CLOBBER | NC_NETCDF4, &ncid)) ERR; */
|
||||||
if (nc_def_dim(dataset_id, "time", NC_UNLIMITED, &time_id)) ERR;
|
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
|
||||||
if (nc_def_var(dataset_id, "dummy", NC_DOUBLE, 1, &time_id, &dummyvar_id)) ERR;
|
if (nc_def_var(ncid, "dummy", NC_DOUBLE, 0, NULL, &varid)) ERR;
|
||||||
if (nc_put_vara(dataset_id, dummyvar_id, start, count, data)) ERR;
|
if (nc_close(ncid)) ERR;
|
||||||
if (nc_close(dataset_id)) ERR;
|
|
||||||
|
|
||||||
for (idx = 0; idx < NUM_FILE_OPENS; idx++)
|
for (idx = 0; idx < NUM_FILE_OPENS; idx++)
|
||||||
{
|
{
|
||||||
if (nc_open(FILE_NAME, NC_NOWRITE, &dataset_id)) ERR;
|
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
|
||||||
if (nc_close(dataset_id)) ERR;
|
if (nc_close(ncid)) ERR;
|
||||||
getrusage(RUSAGE_SELF, &r_usage);
|
getrusage(RUSAGE_SELF, &r_usage);
|
||||||
printf("Memory usage: %ld kilobytes\n",r_usage.ru_maxrss);
|
if (!(idx % 100))
|
||||||
if (!my_rss)
|
printf("Memory usage: %ld kilobytes\n",r_usage.ru_maxrss);
|
||||||
|
if (!my_rss || idx < 10)
|
||||||
my_rss = r_usage.ru_maxrss;
|
my_rss = r_usage.ru_maxrss;
|
||||||
else
|
else
|
||||||
if (my_rss != r_usage.ru_maxrss) ERR;
|
if (my_rss != r_usage.ru_maxrss) ERR;
|
||||||
|
Loading…
Reference in New Issue
Block a user