From: Mark Huang Date: Mon, 1 May 2006 18:28:22 +0000 (+0000) Subject: add stupid test program that leaks memory at a configurable rate X-Git-Tag: planetlab-3_3-branch-point~6 X-Git-Url: http://git.onelab.eu/?p=mom.git;a=commitdiff_plain;h=72f7c344fe26e33cbe48cbc1fe5c9b09fd019c5c add stupid test program that leaks memory at a configurable rate --- diff --git a/Makefile b/Makefile index 06048a0..9b75c7f 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,20 @@ -# @COPYRIGHT@ # -# $Id: Makefile,v 1.2 2004/11/17 20:24:11 acb Exp $ - -BASE=pl_mom -VERSION=0.3 -TARFILE=$(BASE)-$(VERSION).tgz - -all: pl_mom.pl pl_mom +# pl_mom suite of node monitors +# +# Mark Huang +# Copyright (C) 2006 The Trustees of Princeton University +# +# $Id$ +# -install: - install -D -m 755 pl_mom.pl /usr/local/planetlab/bin/pl_mom.pl - install -D -m 755 pl_mom /etc/init.d/pl_mom +ALL := leak -tarball: - rm -f $(TARFILE) - tar cvfz $(TARFILE) -C .. --exclude=CVS $(BASE)-$(VERSION) +CC := gcc +CFLAGS := -Wall -O2 -rpm:: tarball - sudo cp $(TARFILE) /usr/src/redhat/SOURCES - sudo rpmbuild -ba $(BASE).spec +all: $(ALL) +clean: + rm -f $(ALL) +.PHONY: all clean diff --git a/leak.c b/leak.c new file mode 100644 index 0000000..271d41b --- /dev/null +++ b/leak.c @@ -0,0 +1,61 @@ +/* + * Stupid program that leaks memory at a configurable rate, to test swapmon + * + * Mark Huang + * Copyright (C) 2006 The Trustees of Princeton University + * + * $Id$ + */ + +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int rate = 16; + int leaked; + + for (;;) { + int c, option_index = 0; + static struct option long_options[] = { + { "rate", required_argument, NULL, 'r' }, + { "help", no_argument, NULL, 'h' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "r:h", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'r': + rate = atoi(optarg); + break; + case 'h': + default: + fprintf(stderr, "Usage: %s [OPTION]...\n", argv[0]); + fprintf(stderr, "\t-r, --rate=MiB/sec\tRate to leak memory in MiB/sec\n"); + return 0; + } + } + + leaked = 0; + for (;;) { + int i, bufsize = rate * 1024 * 1024; + char *buf = malloc(bufsize); + if (buf) { + /* Touch every page in the buffer */ + for (i = 0; i < bufsize; i += 4096) + buf[i] = 1; + leaked += rate; + printf("\r%d MiB", leaked); + fflush(stdout); + } + sleep(1); + } + + return 0; +}