############################################################################### .ONESHELL: ############################################################################### ATT = $(EXE:=.att) CAC = $(EXE:=.cac) CAL = $(EXE:=.cal) DAT = $(EXE:=.dat) DEP = $(addprefix .,$(EXE:=.d)) EXE = $(basename $(SRC)) FOL = $(EXE:=.fol) GBM != grep -l benchmark.h *.cc | sed 's/.cc$$//' LOG = $(EXE:=.cac) $(EXE:=.cal) $(wildcard *.log) OLD = $(DAT:=.old) $(wildcard *.cal-*) PNG = $(SVG:.svg=.png) SRC = $(wildcard *.c *.cc) SVG = $(EXE:=.svg) ############################################################################### CFLAGS = -g -MF .$*.d -MMD -O3 -Wall CXXFLAGS = $(CFLAGS) -std=c++23 $(GBM): LDLIBS += -lbenchmark %2: CFLAGS += -fno-inline -Og ############################################################################### all: exe att: $(ATT) clean: stop -rm -fv $(ATT) $(CAC) $(CAL) $(DAT) $(DEP) $(EXE) $(FOL) $(LOG) $(OLD) $(PNG) $(SVG) {cache,call}grind.out.* {vg,}core.* gmon.out perf.data* *~ exe: $(EXE) png: $(PNG) sm: selfmod gdb ./$< start: -@if sudo -n true &> /dev/null; then hash cpupower && sudo cpupower frequency-set --governor performance &> /dev/null if [ -e /sys/devices/system/cpu/cpufreq/boost ]; then echo 0 | sudo tee /sys/devices/system/cpu/cpufreq/boost &> /dev/null fi sudo sysctl -w kernel.perf_cpu_time_max_percent=0 echo 0 | sudo tee /proc/sys/kernel/nmi_watchdog fi stop: -@if sudo -n true &> /dev/null; then -@hash cpupower && sudo cpupower frequency-set --governor powersave &> /dev/null if [ -e /sys/devices/system/cpu/cpufreq/boost ]; then echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/boost &> /dev/null fi fi svg: $(SVG) ############################################################################### %.att: % objdump -Cd $< > $@ %.cga: %.cac cg_annotate --auto=yes $< %.cla: %.cal callgrind_annotate --auto=yes $< %.dat: % make -s start -perf record --call-graph=dwarf -F max -o $@ -- ./$< make -s stop %.cac: % -valgrind --branch-sim=yes --cachegrind-out-file=$@ --cache-sim=yes --demangle=yes --tool=cachegrind ./$< %.cal: % -valgrind --branch-sim=yes --cache-sim=yes --callgrind-out-file=$@ --collect-jumps=yes --demangle=yes --dump-instr=yes --instr-atstart=yes -q --tool=callgrind -- ./$< %.fg: %.svg eog $< & %.fol: %.dat perf script -i $< | stackcollapse-perf.pl | grep -v cpu_idle > $@ %.kcg: %.cal kcachegrind $< & %.leak: % # valgrind --leak-check=full --show-error-list=yes --show-leak-kinds=all --track-origins=yes --verbose ./$< valgrind --leak-check=summary --show-leak-kinds=all --track-origins=yes ./$< %.perf: %.dat perf report -i $< %.png: %.svg magick -density 600 $< -quality 100 $@ %.svg: %.fol flamegraph.pl $< > $@ -include $(DEP) ############################################################################### .PHONY: all att clean exe png sm start stop svg .PRECIOUS: $(DAT) $(FOL) $(LOG) $(SVG) .NOEXPORT: ###############################################################################