t-memstat.c revision 157001
1/* 2 * Copyright (c) 2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 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 */ 9 10#include <sm/gen.h> 11SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.5 2005/12/22 19:05:42 ca Exp $") 12 13/* 14** Simple test program for memstat 15*/ 16 17#include <stdlib.h> 18#include <unistd.h> 19#include <stdio.h> 20#include <strings.h> 21 22int 23main(argc, argv) 24 int argc; 25 char **argv; 26{ 27 int r, r2, i, l, slp, sz; 28 long v; 29 char *resource; 30 31 l = 1; 32 sz = slp = 0; 33 resource = NULL; 34 while ((r = getopt(argc, argv, "l:m:r:s:")) != -1) 35 { 36 switch ((char) r) 37 { 38 case 'l': 39 l = strtol(optarg, NULL, 0); 40 break; 41 42 case 'm': 43 sz = strtol(optarg, NULL, 0); 44 break; 45 46 case 'r': 47 resource = strdup(optarg); 48 break; 49 50 case 's': 51 slp = strtol(optarg, NULL, 0); 52 break; 53 54 default: 55 break; 56 } 57 } 58 59 r = sm_memstat_open(); 60 r2 = -1; 61 for (i = 0; i < l; i++) 62 { 63 char *mem; 64 65 r2 = sm_memstat_get(resource, &v); 66 if (slp > 0 && i + 1 < l && 0 == r) 67 { 68 printf("open=%d, memstat=%d, %s=%ld\n", r, r2, 69 resource != NULL ? resource : "default-value", 70 v); 71 sleep(slp); 72 if (sz > 0) 73 { 74 /* 75 ** Just allocate some memory to test the 76 ** values that are returned. 77 ** Note: this is a memory leak, but that 78 ** doesn't matter here. 79 */ 80 81 mem = malloc(sz); 82 if (NULL == mem) 83 printf("malloc(%d) failed\n", sz); 84 } 85 } 86 } 87 printf("open=%d, memstat=%d, %s=%ld\n", r, r2, 88 resource != NULL ? resource : "default-value", v); 89 r = sm_memstat_close(); 90 return r; 91} 92