############################################################################### .ONESHELL: ############################################################################### ATT = $(EXE:=.att) EXE = $(basename $(SRC)) LOG = $(addsuffix .log,$(filter-out test,$(EXE))) SRC = $(wildcard *.cc) STA = $(addsuffix .sta,$(filter-out test,$(EXE))) TXT = $(addsuffix .txt,$(filter-out test,$(EXE))) ############################################################################### DEBUG = -fno-inline -Og OPT = -O3 CXXFLAGS = -fanalyzer -g -pthread -std=c++20 -Wall $(OPT) LDFLAGS = -L.. LDLIBS = -latomic -ldl -lrpmalloc export LC_ALL=C export LD_LIBRARY_PATH=. ifeq ($(findstring stm,$(notdir $(CURDIR))),stm) CXXFLAGS += -fgnu-tm DEBUG += -Os # trick to avoid undefined behavior!!! else DEBUG += -fsanitize={address,alignment,bool,bounds,bounds-strict,builtin,enum,float-cast-overflow,float-divide-by-zero,integer-divide-by-zero,leak,nonnull-attribute,null,object-size,pointer-compare,pointer-overflow,pointer-subtract,return,returns-nonnull-attribute,shift,shift-base,shift-exponent,signed-integer-overflow,undefined,unreachable,vla-bound,vptr} endif ############################################################################### 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) $(CAC) $(CAL) $(DAT) $(DEP) $(LOG) $(STA) $(TXT) callgrind.out.* core.* perf.* *.dat.old *~ exe: $(EXE) log: $(LOG) sta: $(STA) txt: $(TXT) ############################################################################### %.att: % objdump -Cd $< > $@ %.log %.sta: % @LANG=C sudo sysctl kernel.perf_event_paranoid=-1 perf stat -r 33 > $*.log 2> $*.sta -- ./$< %.txt: %.log %.sta @v="[$$(cat $*.log | tr '\n' ',')]" sum=$$(python3 -c "import statistics; print('{0:.0f}'.format(sum($$v)))") median=$$(python3 -c "import statistics; print('{0:.0f}'.format(statistics.median($$v)))") mean=$$(python3 -c "import statistics; print('{0:.0f}'.format(statistics.mean($$v)))") stdev=$$(python3 -c "import statistics; print('{0:.0f}'.format(statistics.stdev($$v)))") cpu=$$(grep -o ".* msec task-clock" $*.sta | grep -o "[[:digit:].]*") # ratio=$$(python3 -c "print('{0:.2f}'.format($$sum / $$cpu))") ratio=$$(python3 -c "print('{0:.2f}'.format($$median / $$cpu))") hc=$$(grep 'N = 1;' stack.cc > /dev/null && echo '.' || echo ':') printf "%18s%10s%10s%10s%10s%10s\n" program median mean stdev cpu ratio | tee $@ printf "%18s%10s%10s%10s%10s%10s\n" "$$(basename $$(pwd))$$hc" $$median $$mean $$stdev $$cpu $$ratio | tee -a $@ ############################################################################### .PHONY: all att check clean exe log sta txt .PRECIOUS: $(LOG) $(STA) $(TXT) ###############################################################################