1*058561cbSjbeck /* 2*058561cbSjbeck * Copyright (c) 2005, 2006 Sendmail, Inc. and its suppliers. 3*058561cbSjbeck * All rights reserved. 4*058561cbSjbeck * 5*058561cbSjbeck * By using this file, you agree to the terms and conditions set 6*058561cbSjbeck * forth in the LICENSE file which can be found at the top level of 7*058561cbSjbeck * the sendmail distribution. 8*058561cbSjbeck */ 9*058561cbSjbeck 10*058561cbSjbeck #pragma ident "%Z%%M% %I% %E% SMI" 11*058561cbSjbeck 12*058561cbSjbeck #include <sm/gen.h> 13*058561cbSjbeck SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.7 2006/06/28 23:57:59 ca Exp $") 14*058561cbSjbeck 15*058561cbSjbeck #include <sm/misc.h> 16*058561cbSjbeck 17*058561cbSjbeck /* 18*058561cbSjbeck ** Simple test program for memstat 19*058561cbSjbeck */ 20*058561cbSjbeck 21*058561cbSjbeck #include <stdlib.h> 22*058561cbSjbeck #include <unistd.h> 23*058561cbSjbeck #include <stdio.h> 24*058561cbSjbeck #include <strings.h> 25*058561cbSjbeck #include <string.h> 26*058561cbSjbeck 27*058561cbSjbeck extern char *optarg; 28*058561cbSjbeck extern int optind; 29*058561cbSjbeck 30*058561cbSjbeck int 31*058561cbSjbeck main(argc, argv) 32*058561cbSjbeck int argc; 33*058561cbSjbeck char **argv; 34*058561cbSjbeck { 35*058561cbSjbeck int r, r2, i, l, slp, sz; 36*058561cbSjbeck long v; 37*058561cbSjbeck char *resource; 38*058561cbSjbeck 39*058561cbSjbeck l = 1; 40*058561cbSjbeck sz = slp = 0; 41*058561cbSjbeck resource = NULL; 42*058561cbSjbeck while ((r = getopt(argc, argv, "l:m:r:s:")) != -1) 43*058561cbSjbeck { 44*058561cbSjbeck switch ((char) r) 45*058561cbSjbeck { 46*058561cbSjbeck case 'l': 47*058561cbSjbeck l = strtol(optarg, NULL, 0); 48*058561cbSjbeck break; 49*058561cbSjbeck 50*058561cbSjbeck case 'm': 51*058561cbSjbeck sz = strtol(optarg, NULL, 0); 52*058561cbSjbeck break; 53*058561cbSjbeck 54*058561cbSjbeck case 'r': 55*058561cbSjbeck resource = strdup(optarg); 56*058561cbSjbeck break; 57*058561cbSjbeck 58*058561cbSjbeck case 's': 59*058561cbSjbeck slp = strtol(optarg, NULL, 0); 60*058561cbSjbeck break; 61*058561cbSjbeck 62*058561cbSjbeck default: 63*058561cbSjbeck break; 64*058561cbSjbeck } 65*058561cbSjbeck } 66*058561cbSjbeck 67*058561cbSjbeck r = sm_memstat_open(); 68*058561cbSjbeck r2 = -1; 69*058561cbSjbeck for (i = 0; i < l; i++) 70*058561cbSjbeck { 71*058561cbSjbeck char *mem; 72*058561cbSjbeck 73*058561cbSjbeck r2 = sm_memstat_get(resource, &v); 74*058561cbSjbeck if (slp > 0 && i + 1 < l && 0 == r) 75*058561cbSjbeck { 76*058561cbSjbeck printf("open=%d, memstat=%d, %s=%ld\n", r, r2, 77*058561cbSjbeck resource != NULL ? resource : "default-value", 78*058561cbSjbeck v); 79*058561cbSjbeck sleep(slp); 80*058561cbSjbeck if (sz > 0) 81*058561cbSjbeck { 82*058561cbSjbeck /* 83*058561cbSjbeck ** Just allocate some memory to test the 84*058561cbSjbeck ** values that are returned. 85*058561cbSjbeck ** Note: this is a memory leak, but that 86*058561cbSjbeck ** doesn't matter here. 87*058561cbSjbeck */ 88*058561cbSjbeck 89*058561cbSjbeck mem = malloc(sz); 90*058561cbSjbeck if (NULL == mem) 91*058561cbSjbeck printf("malloc(%d) failed\n", sz); 92*058561cbSjbeck } 93*058561cbSjbeck } 94*058561cbSjbeck } 95*058561cbSjbeck printf("open=%d, memstat=%d, %s=%ld\n", r, r2, 96*058561cbSjbeck resource != NULL ? resource : "default-value", v); 97*058561cbSjbeck r = sm_memstat_close(); 98*058561cbSjbeck return r; 99*058561cbSjbeck } 100