SHELL := bash .ONESHELL: ATT = $(EXE:=.att) $(shell echo {consumidor,productor}-{{0..3},g,s,z}.att) DAT = $(REO:=.dat) EXE = $(basename $(SRC)) LOG = $(REO:=.log) REO = $(sort $(filter reorder%,$(EXE))) SRC = $(wildcard *.cc) TXT = $(REO:=.txt) CXXFLAGS = -fanalyzer -mno-{avx,sse} -g -O3 -std=c++20 -Wall all: att stat att: $(ATT) clave: | $(REO) @printf '%80s\n' | tr ' ' '-' echo "key:" echo -e " r1=r2=0: number of reorders detected" echo -e " iter : iterations of the program" echo -e " real : real time in seconds" echo -e " user : user time in seconds" echo -e " system : system time in seconds" echo -e " u+s : user time + system time" echo -e " rate : iterations per second" clean: -rm -fv $(ATT) $(DAT) $(EXE) $(LOG) $(TXT) *~ exe: $(EXE) stat: clave @printf '%80s\n' | tr ' ' '-' for i in $(TXT); do make -s $$i if [[ "$$i" == "$(firstword $(TXT))" ]]; then head -n 1 $$i printf '%80s\n' | tr ' ' '-' fi tail -n 1 $$i done printf '%80s\n' | tr ' ' '-' sort: $(TXT) | clave @declare -a F=('programa' 'r1=r2=0' 'iter' 'real' 'user' 'system' 'u+s' 'rate') declare -a R=('' '' 'r' '' '' '' '' 'r') printf '%80s\n' | tr ' ' '-' for ((i=0; i<$${#F[@]}; ++i)); do head -n 1 -q $(firstword $(TXT)) | sed "s/ $${F[$$i]}/\[$${F[$$i]}\]/" printf '%80s\n' | tr ' ' '-' tail -n 1 -q $^ | sort -k$$((i + 1)),$$((i + 1))$${R[$$i]} -k8,8r -k7,7 printf '%80s\n' | tr ' ' '-' done ipc-0: CXXFLAGS += -O0 ipc-1: CXXFLAGS += -O1 ipc-2: CXXFLAGS += -O2 ipc-3: CXXFLAGS += -O3 ipc-g: CXXFLAGS += -Og ipc-s: CXXFLAGS += -Os ipc-z: CXXFLAGS += -Oz consumidor-%.att: ipc-% gdb -batch -ex "file $<" -ex "disass consumidor" | c++filt | sed 's/0x0000000000/0x/g' > $@ productor-%.att: ipc-% gdb -batch -ex "file $<" -ex "disass productor" | c++filt | sed 's/0x0000000000/0x/g' > $@ %.att: % objdump -Cd $< > $@ %.dat %.log: % @governor=$$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) [ "$$USER" == "gustavo" ] && echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor &> /dev/null /usr/bin/time -f "%e\n%U\n%S" -o ./$<.dat ./$< > ./$<.log 2> /dev/null [ "$$USER" == "gustavo" ] && echo $$governor | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor &> /dev/null %.txt: %.dat %.log makefile @LC_ALL=C reorders=$$(tail -1 "./$*.log" | cut -d ' ' -f 1) iteraciones=$$(tail -1 "./$*.log" | cut -d ' ' -f 5) real=$$(sed '1q;d' "./$*.dat") usuario=$$(sed '2q;d' "./$*.dat") sistema=$$(sed '3q;d' "./$*.dat") total=$$(printf '%.2f' $$(bc -lq <<< "$$usuario + $$sistema")) rate=$$(bc -q <<< "$$iteraciones/$$total") printf '%17s%9s%9s%9s%9s%9s%9s%9s\n' programa r1=r2=0 iter real user system u+s rate > $@ printf '%17s%9s%9s%9s%9s%9s%9s%9s\n' $* $$reorders $$iteraciones $$real $$usuario $$sistema $$total $$rate >> $@ .PRECIOUS: $(DAT) $(LOG) $(TXT) .PHONY: all att clave clean exe stat