#!/usr/bin/env bash set -euo pipefail # Measure steady-state RSS for Tiny sizes by maintaining a live set # and churning short-lived allocations. Reports peak and end RSS. # # Usage: scripts/measure_rss_tiny.sh ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT_DIR" if [[ $# -lt 3 ]]; then echo "usage: $0 " >&2 exit 1 fi size=$1; live=$2; iters=$3 cat > "$ROOT_DIR/.tmp_rss_bench.c" <<'EOF' #include #include #include #include #include #include static size_t get_rss_kb(void) { FILE* f = fopen("/proc/self/statm","r"); if (!f) return 0; unsigned long size, res; fscanf(f, "%lu %lu", &size, &res); fclose(f); long ps = sysconf(_SC_PAGESIZE); return (size_t)((res * ps) / 1024); } int main(int argc, char** argv) { size_t size = (size_t)strtoull(argv[1],NULL,10); int live = atoi(argv[2]); int iters = atoi(argv[3]); void** L = (void**)malloc(sizeof(void*)*(size_t)live); for (int i=0;ipeak) peak=rss; } size_t end_rss = get_rss_kb(); printf("peak_rss_kb=%zu end_rss_kb=%zu\n", peak, end_rss); for (int i=0;i/dev/null || true echo "[case] HAKMEM (LD_PRELOAD)" out_h=$(HAKMEM_LD_SAFE=1 LD_PRELOAD="$ROOT_DIR/libhakmem.so" ./.tmp_rss_bench "$size" "$live" "$iters") echo "$out_h" echo "[case] System" out_s=$(./.tmp_rss_bench "$size" "$live" "$iters") echo "$out_s" rm -f .tmp_rss_bench .tmp_rss_bench.c