############################################################################### .ONESHELL: ############################################################################### ATT = $(EXE:=.att) CG = $(EXE:=.cg) DAT = $(EXE:=.dat) DEP = $(EXE:=.dep) EXE = $(basename $(SRC)) LOG = $(EXE:=.log) SRC = $(wildcard *.cc) STA = $(EXE:=.sta) STM = $(shell echo $$PWD | grep -q stm && echo '-fgnu-tm') TXT = $(EXE:=.txt) ############################################################################### CXXFLAGS = $(STM) -O3 -pthread -std=c++20 -Wall LDFLAGS = -L.. LDLIBS = -lrpmallocwrap ############################################################################### all: txt att: $(ATT) check: $(EXE) @for i in $^; do if nm -C ./$$i | grep -q rpmalloc; then echo "rpmalloc lib detected in $${PWD##*/}/$$i!!!" else echo "rpmalloc lib NOT DETECTED in $${PWD##*/}/$$i!!!" fi done clean: -rm -fv $(ATT) $(EXE) $(CG) $(DAT) $(DEP) $(LOG) $(STA) $(TXT) core.* perf.* *~ dep: $(DEP) exe: $(EXE) log: $(LOG) sta: $(STA) txt: $(TXT) ############################################################################### -include $(DEP) %: %.cc | %.dep %.att: % objdump -Cd $< > $@ %.cg: % valgrind --tool=callgrind --branch-sim=yes --cache-sim=yes --callgrind-out-file=$@ --collect-bus=yes --collect-jumps=yes --dump-instr=yes --dump-line=yes -- ./$< %.dat: % perf record --call-graph dwarf --freq=max -o $@ -- ./$< %.dep: %.cc @$(CXX) -MM $(CXXFLAGS) $< | sed -e 's|.*:|$*:|' > $@ %.hel: % valgrind --tool=helgrind -- ./$< %.kcg: %.cg kcachegrind $< & %.mc: % valgrind --leak-check=full -s --show-leak-kinds=all ./$< %.perf: %.dat perf report -g 'graph,0.5,caller' -i $< %.log %.sta: % @LANG=C perf stat -r 11 > $*.log 2> $*.sta -- ./$< %.txt: %.log %.sta @lpad() { printf "%$$(( 11 - $${#1} ))s$$1"; } pprint() { lpad "$$1"; shift; (( $$# > 0 )) && pprint "$$@" || echo; } declare -a chain=() for ((i=0; i<3; ++i)); do declare -a v=($$(cut -d' ' -f$$((i + 1)) $*.log)) v2="[$$(echo $${v[@]} | tr ' ' ',')]" chain+=($$(python3 -c "import statistics; print('{0:.0f}'.format(statistics.mean($$v2)))")) chain+=($$(python3 -c "import statistics; print('{0:.0f}'.format(statistics.stdev($$v2)))")) done cpu=$$(grep -o ".* msec task-clock" $*.sta | grep -o "[[:digit:].]*") ratio=$$(python3 -c "print('{0:.2f} '.format($${chain[4]} / $$cpu))") pprint program {push,pop,sum}.{mean,stdev} cpu ratio > $@ pprint $$(basename $$(pwd)) $${chain[@]} $$cpu $$ratio >> $@ ############################################################################### .PHONY: all att clean dep exe log sta txt .PRECIOUS: $(CG) $(DAT) $(LOG) $(STA) $(TXT) ###############################################################################