some more minor stuff and a lot of debugging stuff that will be removed later.
[dragonfly/vkernel-mp.git] / contrib / sendmail-8.14 / libsm / t-memstat.c
blob3bfe39415066def65f913e02a0e0c8c4f5cd5b69
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 #include <sm/gen.h>
11 SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
13 #include <sm/misc.h>
16 ** Simple test program for memstat
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <strings.h>
23 #include <string.h>
25 extern char *optarg;
26 extern int optind;
28 void
29 usage(prg)
30 char *prg;
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");
40 int
41 main(argc, argv)
42 int argc;
43 char **argv;
45 int r, r2, i, l, slp, sz;
46 long v;
47 char *resource;
49 l = 1;
50 sz = slp = 0;
51 resource = NULL;
52 while ((r = getopt(argc, argv, "l:m:r:s:")) != -1)
54 switch ((char) r)
56 case 'l':
57 l = strtol(optarg, NULL, 0);
58 break;
60 case 'm':
61 sz = strtol(optarg, NULL, 0);
62 break;
64 case 'r':
65 resource = strdup(optarg);
66 break;
68 case 's':
69 slp = strtol(optarg, NULL, 0);
70 break;
72 default:
73 usage(argv[0]);
74 exit(1);
78 r = sm_memstat_open();
79 r2 = -1;
80 for (i = 0; i < l; i++)
82 char *mem;
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",
89 v);
90 sleep(slp);
91 if (sz > 0)
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.
100 mem = malloc(sz);
101 if (NULL == mem)
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();
109 return r;