#!/bin/bash # Capture one DynamoRIO trace per selected SimPoint, then raw2trace + minimize. # # Mirrors scarab-infra's cluster_then_trace flow (common/scripts/ # run_simpoint_trace.py) with SEG_SIZE as both the fingerprint segment size and # the drraw2trace chunk size, and one warmup chunk. Each released archive keeps # chunk.0000 (warmup) + chunk.0001 (the SimPoint region) == 2 * SEG_SIZE # instructions. set -euo pipefail W=/work/simpoint_flow/sqlite SEG_SIZE=60000000 WARMUP_CHUNKS=1 BINCMD="/work/bin/sqlite_query /work/db/records.db 3 60000 50000 4900 5000 3000000" DR=$DYNAMORIO_HOME mapfile -t PAIRS < "$W/simpoints/selected.txt" # " " per line echo "=== tracing ${#PAIRS[@]} simpoints ===" pids=() for pair in "${PAIRS[@]}"; do seg=${pair%% *} segdir="$W/traces_simp/$seg" rm -rf "$segdir"; mkdir -p "$segdir" roi_end=$(( (seg + 1) * SEG_SIZE )) warmup=$(( SEG_SIZE * WARMUP_CHUNKS )) roi_start=$(( seg * SEG_SIZE )) if [ "$roi_start" -gt "$warmup" ]; then roi_start=$(( roi_start - warmup )) else roi_start=0 fi roi_len=$(( roi_end - roi_start )) echo "segment $seg: trace_after=$roi_start trace_for=$roi_len" if [ "$roi_start" -eq 0 ]; then "$DR"/bin64/drrun -disable_traces -max_bb_instrs 256 -opt_cleancall 2 \ -t drcachesim -jobs 8 -outdir "$segdir" -offline \ -count_fetched_instrs -trace_for_instrs "$roi_len" \ -- $BINCMD >/dev/null 2>"$segdir/drrun.log" & else "$DR"/bin64/drrun -disable_traces -max_bb_instrs 256 -opt_cleancall 2 \ -t drcachesim -jobs 8 -outdir "$segdir" -offline \ -count_fetched_instrs -trace_after_instrs "$roi_start" \ -trace_for_instrs "$roi_len" \ -- $BINCMD >/dev/null 2>"$segdir/drrun.log" & fi pids+=($!) done for p in "${pids[@]}"; do wait "$p"; done echo "=== tracing done ===" echo "=== raw2trace ===" pids=() for pair in "${PAIRS[@]}"; do seg=${pair%% *} tp="$W/traces_simp/$seg" mv "$tp"/dr*/raw/ "$tp/raw/" mkdir -p "$tp/bin" cp "$tp/raw/modules.log" "$tp/bin/modules.log" cp "$tp/raw/modules.log" "$tp/raw/modules.log.bak" python2 /tmp_home/scarab/utils/memtrace/portabilize_trace.py "$tp" >/dev/null cp "$tp/bin/modules.log" "$tp/raw/modules.log" "$DR"/tools/bin64/drraw2trace -jobs 8 -indir "$tp/raw" \ -chunk_instr_count "$SEG_SIZE" >"$tp/raw2trace.log" 2>&1 & pids+=($!) done for p in "${pids[@]}"; do wait "$p"; done echo "=== raw2trace done ===" echo "=== minimize ===" dest="$W/traces_simp/trace" mkdir -p "$dest" "$W/traces_simp/bin" keep=$(( WARMUP_CHUNKS + 1 )) for pair in "${PAIRS[@]}"; do seg=${pair%% *} tp="$W/traces_simp/$seg" src=$(find "$tp" -name 'drmemtrace.*.trace.zip' | head -1) big="$tp/trace/$seg.big.zip" mv "$src" "$big" nchunk=$(unzip -l "$big" | grep -c 'chunk\.') echo "segment $seg: $nchunk chunks in full archive" chunks="" for ((i = 0; i < keep; i++)); do chunks="$chunks $(printf 'chunk.%04d' $i)"; done ( cd "$tp/trace" && zip "$seg.big.zip" --copy $chunks --out "$dest/$seg.zip" >/dev/null ) rm -f "$big" cp "$tp/bin/modules.log" "$W/traces_simp/bin/modules.log" done echo "=== minimize done ===" ls -la "$dest"