/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include long long getMilli(); long long getMicro(); void malloctest(int loopcount, int memsize, int touch); void freetest(int loopcount, int memsize); void mmaptest(int loopcount, int memsize, int touch); void unmaptest(int loopcount, int memsize); main(int argc, char ** argv) { int loopcount; int memsize; if(argc < 4) { printf("Usage: memtest X loopcount memsize(MB)\n"); printf("where X = \n"); printf("1 : malloc test \n"); printf("2 : mmap test \n"); printf("3 : malloc test + touch pages\n"); printf("4 : mmap test + touch pages\n"); printf("5 : malloc/free test \n"); printf("6 : mmap/munmap test \n"); printf("loopcount - number of loops\n"); printf("memsize - memory segment size to allocate in MB.\n"); exit(1); } loopcount = atoi(argv[2]); memsize = atoi(argv[3]); switch(atoi(argv[1])) { case 1: malloctest(loopcount, memsize , 0 ); break; case 2: mmaptest(loopcount, memsize,0); break; case 3: malloctest(loopcount, memsize,1); break; case 4: mmaptest(loopcount, memsize,1); break; case 5: freetest(loopcount, memsize); break; case 6: unmaptest(loopcount, memsize); break; default: break; } } long long getMilli() { struct timeval tick_time; gettimeofday(&tick_time, 0); return ((long long)tick_time.tv_sec) * ((long long)1000) + ((long long)tick_time.tv_usec) / ((long long)1000); } long long getMicro(){ struct timeval tick_time; int res = gettimeofday(&tick_time, 0); long long secs = tick_time.tv_sec; long long micros = tick_time.tv_usec; micros = secs*1000000+micros; return micros; } void malloctest(int loopcount, int memsize, int touch) { long long start=0; int total=0; int i=0, j=0; int size=memsize*1024*1024; /*bytes*/; float mean; char * ptr =0; printf("Staring malloctest "); if(touch) printf("with touch\n"); else printf("\n"); start=getMicro(); for(i=0; i