diff --git a/run_all.sh b/run_all.sh index 55643b1..c29f866 100755 --- a/run_all.sh +++ b/run_all.sh @@ -64,15 +64,25 @@ profile_resources() { local pid=$1 local mem_output_file=$2 local cpu_output_file=$3 + local timeline_file=$4 local peak_mem=0 local peak_cpu=0 local current_mem local current_cpu + local start_time=$(date +%s%N) + local sample_count=0 + + # Clear output files + > "$mem_output_file" + > "$cpu_output_file" + > "$timeline_file" # Sample resources every 10ms while process is running while kill -0 "$pid" 2>/dev/null; do current_mem=$(get_memory_usage "$pid") current_cpu=$(get_cpu_usage "$pid") + current_time=$(date +%s%N) + elapsed_ms=$(( (current_time - start_time) / 1000000 )) if [ "$current_mem" -gt "$peak_mem" ]; then peak_mem=$current_mem @@ -81,12 +91,16 @@ profile_resources() { peak_cpu=$current_cpu fi - echo "$current_mem" >> "$mem_output_file" - echo "$current_cpu" >> "$cpu_output_file" + # Store time-series data + echo "$elapsed_ms $current_mem" >> "$mem_output_file" + echo "$elapsed_ms $current_cpu" >> "$cpu_output_file" + echo "$elapsed_ms $current_mem $current_cpu" >> "$timeline_file" + + sample_count=$((sample_count + 1)) sleep 0.01 2>/dev/null || sleep 0.1 done - echo "$peak_mem $peak_cpu" + echo "$peak_mem $peak_cpu $sample_count" } echo "=== Pi-beräkning med $DECIMALS decimaler (4 körningar, genomsnitt av 3 efter warmup) ==="