8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / t-memstat.c
blobf0ca4a1788a871d2cea93cfd98caa8f48e5b2010
1 /*
2 * Copyright (c) 2005-2007 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
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.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include <sm/gen.h>
13 SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
15 #include <sm/misc.h>
18 ** Simple test program for memstat
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <stdio.h>
24 #include <strings.h>
25 #include <string.h>
27 extern char *optarg;
28 extern int optind;
30 void
31 usage(prg)
32 char *prg;
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");
42 int
43 main(argc, argv)
44 int argc;
45 char **argv;
47 int r, r2, i, l, slp, sz;
48 long v;
49 char *resource;
51 l = 1;
52 sz = slp = 0;
53 resource = NULL;
54 while ((r = getopt(argc, argv, "l:m:r:s:")) != -1)
56 switch ((char) r)
58 case 'l':
59 l = strtol(optarg, NULL, 0);
60 break;
62 case 'm':
63 sz = strtol(optarg, NULL, 0);
64 break;
66 case 'r':
67 resource = strdup(optarg);
68 break;
70 case 's':
71 slp = strtol(optarg, NULL, 0);
72 break;
74 default:
75 usage(argv[0]);
76 exit(1);
80 r = sm_memstat_open();
81 r2 = -1;
82 for (i = 0; i < l; i++)
84 char *mem;
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",
91 v);
92 sleep(slp);
93 if (sz > 0)
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.
102 mem = malloc(sz);
103 if (NULL == mem)
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();
111 return r;