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.
11 SM_IDSTR(id
, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
16 ** Simple test program for memstat
32 fprintf(stderr
, "usage: %s [options]\n", prg
);
33 fprintf(stderr
, "options:\n");
34 fprintf(stderr
, "-l n loop n times\n");
35 fprintf(stderr
, "-m n allocate n bytes per iteration\n");
36 fprintf(stderr
, "-r name use name as resource to query\n");
37 fprintf(stderr
, "-s n sleep n seconds per iteration\n");
45 int r
, r2
, i
, l
, slp
, sz
;
52 while ((r
= getopt(argc
, argv
, "l:m:r:s:")) != -1)
57 l
= strtol(optarg
, NULL
, 0);
61 sz
= strtol(optarg
, NULL
, 0);
65 resource
= strdup(optarg
);
69 slp
= strtol(optarg
, NULL
, 0);
78 r
= sm_memstat_open();
80 for (i
= 0; i
< l
; i
++)
84 r2
= sm_memstat_get(resource
, &v
);
85 if (slp
> 0 && i
+ 1 < l
&& 0 == r
)
87 printf("open=%d, memstat=%d, %s=%ld\n", r
, r2
,
88 resource
!= NULL
? resource
: "default-value",
94 ** Just allocate some memory to test the
95 ** values that are returned.
96 ** Note: this is a memory leak, but that
97 ** doesn't matter here.
102 printf("malloc(%d) failed\n", sz
);
106 printf("open=%d, memstat=%d, %s=%ld\n", r
, r2
,
107 resource
!= NULL
? resource
: "default-value", v
);
108 r
= sm_memstat_close();