From 201ac2d401075d5a71274ba69680e8733a1e3933 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Mon, 26 Feb 2024 19:04:54 +0000 Subject: [PATCH] Build system: switched to valgrind for profiling --- .gitignore | 2 +- Makefile | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 0a437a2..5209825 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ first *.rom make.deps -gmon.out +callgrind.out diff --git a/Makefile b/Makefile index 09a1d4a..3abe627 100644 --- a/Makefile +++ b/Makefile @@ -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