############################################################################### SHELL := bash .ONESHELL: ############################################################################### CXXFLAGS = -march=native -O3 -pthread -std=c++20 -Wall LDLIBS = -lrt ############################################################################### ATT = $(EXE:=.att) SRC = $(wildcard *.cc) EXE = $(basename $(SRC)) DAT = $(EXE:=.dat) LOG = $(EXE:=.log) RUN = 10 TXT = $(EXE:=.txt) ############################################################################### all: @if make -qs $(TXT); then make -s sort else make -s stat fi att: $(ATT) key: @printf '%54s\n' | tr ' ' - echo "key: program = IPC type" echo " messages = averaged (pings + pongs)" echo " elapsed = elapsed time (ms)" echo " cpu = cpu-clock time (ms)" echo " ratio = messages / cpu" clean: -rm -fv $(ATT) $(DAT) $(EXE) $(LOG) $(TXT) {vg,}core.* perf.data *~ exe: $(EXE) sort: $(TXT) | key @declare -a F=(program messages elapsed cpu ratio) declare -a R=('-b' '-r' '-s' '-s' '-r') for ((i=0; i<$${#F[@]}; ++i)); do printf '%54s\n' | tr ' ' '-' head -n 1 -q $< | sed "s/ $${F[$$i]}/\[$${F[$$i]}\]/" printf '%54s\n' | tr ' ' '-' for t in $^; do tail -n 1 $$t done | sort -k$$((i+1)),$$((i+1)) -k$${#F[@]},$${#F[@]} $${R[$$i]} done printf '%54s\n' | tr ' ' '-' stat: key @for i in $(TXT); do make -s $$i if [[ "$$i" == "$(firstword $(TXT))" ]]; then printf '%54s\n' | tr ' ' - head -n 1 $$i printf '%54s\n' | tr ' ' - fi tail -n 1 $$i done printf '%54s\n' | tr ' ' - txt: $(TXT) ############################################################################### %.att: % objdump -CdS $< > $@ %.dat %.log: % @LANG=C perf stat -e cpu-clock,duration_time -r $(RUN) -x ',' -- ./$< 1> $*.log 2> $*.dat %.txt: %.dat %.log while read -r a b c; read d e f; do min=$$((c < f ? c : f)) max=$$((c > f ? c : f)) if (( max > min + 1 )); then echo "fallo en $*.log: nº de pings != nº de pongs!!!" exit 1 fi sum=$$((c + f)) done < $*.log avg=$$((sum / $(RUN))) time=$$(grep duration_time $*.dat | cut -d',' -f1) time=$$(bc -l <<< "scale=2; $$time/1000000" 2> /dev/null) cpu=$$(grep cpu-clock $*.dat | cut -d',' -f1) ratio=$$(bc -l <<< "scale=2; $$avg/$$cpu" 2> /dev/null) printf '%10s %10s %10s %10s %10s\n' program messages elapsed cpu ratio > $@ printf '%10s %10s %10s %10s %10s\n' $* $$avg $$time $$cpu $$ratio >> $@ ############################################################################### .PHONY: all att key clean exe sort stat txt .PRECIOUS: $(LOG) $(DAT) .NOEXPORT: ###############################################################################