Build system: switched to valgrind for profiling

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-26 19:04:54 +00:00
parent f6008b603d
commit 201ac2d401
2 changed files with 21 additions and 12 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@
first
*.rom
make.deps
gmon.out
callgrind.out

View File

@ -1,5 +1,4 @@
QUIET=1
PROFILING=1
ADDRESS_SANITIZE=1
all:first
@ -15,21 +14,18 @@ include make.deps
ifeq "${QUIET}" "1"
QUIET_CC = @echo ' CC '$@;
QUIET_LINK = @echo ' LINK '$@;
QUIET_FAS = @echo ' FAS '$@;
QUIET_CLEAN = @echo ' CLEAN .';
Q = @
QUIET_CC = @echo ' CC '$@;
QUIET_LINK = @echo ' LINK '$@;
QUIET_FAS = @echo ' FAS '$@;
QUIET_CLEAN = @echo ' CLEAN .';
QUIET_VALGRIND = @echo ' VALGRIND '$@;
Q = @
else
Q =
endif
CFLAGS::=-O2 $(shell pkg-config ncursesw --cflags)
ifeq "${PROFILING}" "1"
CFLAGS += -pg
LDFLAGS += -pg
endif
ifeq "${ADDRESS_SANITIZE}" "1"
CFLAGS += -fsanitize=address -ggdb
LDFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=leak
@ -52,7 +48,20 @@ gprof:
${QUIET_CC}
${Q}gcc -c $< -Wall -Wextra -Werror ${CFLAGS}
callgrind.out:first ${MAIN_ROM}
${QUIET_VALGRIND}
${Q}if ldd first |grep asan > /dev/null;\
then\
echo ERROR: Binary build with libasan, please rebuild without address sanitiser;\
else\
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes --callgrind-out-file=callgrind.out ./first -i programs/3d_renderer.rom;\
fi
profile: callgrind.out
kcachegrind $<
.PHONY: clean
clean:
${QUIET_CLEAN}
${Q} rm -f ${OBJECT_FILES} first ${ROMS} gmon.out
${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out