2 * Stupid program that leaks memory at a configurable rate, to test swapmon
4 * Mark Huang <mlhuang@cs.princeton.edu>
5 * Copyright (C) 2006 The Trustees of Princeton University
16 main(int argc, char *argv[])
22 int c, option_index = 0;
23 static struct option long_options[] = {
24 { "rate", required_argument, NULL, 'r' },
25 { "help", no_argument, NULL, 'h' },
29 c = getopt_long(argc, argv, "r:h", long_options, &option_index);
39 fprintf(stderr, "Usage: %s [OPTION]...\n", argv[0]);
40 fprintf(stderr, "\t-r, --rate=MiB/sec\tRate to leak memory in MiB/sec\n");
47 int i, bufsize = rate * 1024 * 1024;
48 char *buf = malloc(bufsize);
50 /* Touch every page in the buffer */
51 for (i = 0; i < bufsize; i += 4096)
54 printf("\r%d MiB", leaked);