2 * Copyright (c) 2005-2007 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
10 #pragma ident "%Z%%M% %I% %E% SMI"
13 SM_IDSTR(id
, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
18 ** Simple test program for memstat
34 fprintf(stderr
, "usage: %s [options]\n", prg
);
35 fprintf(stderr
, "options:\n");
36 fprintf(stderr
, "-l n loop n times\n");
37 fprintf(stderr
, "-m n allocate n bytes per iteration\n");
38 fprintf(stderr
, "-r name use name as resource to query\n");
39 fprintf(stderr
, "-s n sleep n seconds per iteration\n");
47 int r
, r2
, i
, l
, slp
, sz
;
54 while ((r
= getopt(argc
, argv
, "l:m:r:s:")) != -1)
59 l
= strtol(optarg
, NULL
, 0);
63 sz
= strtol(optarg
, NULL
, 0);
67 resource
= strdup(optarg
);
71 slp
= strtol(optarg
, NULL
, 0);
80 r
= sm_memstat_open();
82 for (i
= 0; i
< l
; i
++)
86 r2
= sm_memstat_get(resource
, &v
);
87 if (slp
> 0 && i
+ 1 < l
&& 0 == r
)
89 printf("open=%d, memstat=%d, %s=%ld\n", r
, r2
,
90 resource
!= NULL
? resource
: "default-value",
96 ** Just allocate some memory to test the
97 ** values that are returned.
98 ** Note: this is a memory leak, but that
99 ** doesn't matter here.
104 printf("malloc(%d) failed\n", sz
);
108 printf("open=%d, memstat=%d, %s=%ld\n", r
, r2
,
109 resource
!= NULL
? resource
: "default-value", v
);
110 r
= sm_memstat_close();