-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile-memory.sh
More file actions
executable file
·29 lines (26 loc) · 1.06 KB
/
Copy pathprofile-memory.sh
File metadata and controls
executable file
·29 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Memory profiling helper script
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <command> [args...]"
exit 1
fi
OS=$(uname -s)
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
if [[ "$OS" == "Darwin" ]]; then
echo "Running memory profiling on macOS..."
# Use leaks and malloc debugging
export MallocStackLogging=1
export MallocScribble=1
"$@"
echo "Memory profile complete. Check system logs for malloc info."
elif [[ "$OS" == "Linux" ]]; then
if command -v valgrind &>/dev/null; then
echo "Running valgrind memory profiling..."
valgrind --tool=massif --massif-out-file=benchmark_results/memory_profiles/massif_$TIMESTAMP.out "$@"
ms_print benchmark_results/memory_profiles/massif_$TIMESTAMP.out > benchmark_results/memory_profiles/massif_$TIMESTAMP.txt
echo "Memory profile saved to benchmark_results/memory_profiles/massif_$TIMESTAMP.txt"
else
echo "Valgrind not available. Running basic memory tracking..."
/usr/bin/time -v "$@" 2>&1 | tee benchmark_results/memory_profiles/time_$TIMESTAMP.txt
fi
fi