Skip to content

Commit

Permalink
Require configure for profiling
Browse files Browse the repository at this point in the history
Some functions are not necessary if one is not profiling. Hence, add
option --enable-profiling to configure which enables profiling (default
is no). This will define the preprocessor definition FLINT_PROFILE,
which can then be used to include/exclude source code that is only used
when profiling.
  • Loading branch information
albinahlback committed Dec 3, 2023
1 parent 954038e commit f74d9c8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ STATIC:=@STATIC@
SHARED:=@SHARED@

COVERAGE:=@COVERAGE@
PROFILING:=@PROFILING@

WANT_NTL:=@WANT_NTL@

WANT_DEPS:=@WANT_DEPS@
Expand Down Expand Up @@ -199,13 +201,18 @@ TEMPLATE_DIRS := \
fq_embed_templates fq_templates

BUILD_DIRS := \
$(BUILD_DIR) \
$(BUILD_DIR) \
$(patsubst %, $(BUILD_DIR)/%, $(DIRS)) \
$(patsubst %, $(BUILD_DIR)/%/profile, $(DIRS)) \
$(patsubst %, $(BUILD_DIR)/%/test, $(DIRS)) \
$(patsubst %, $(BUILD_DIR)/%/tune, $(DIRS)) \
$(BUILD_DIR)/examples $(BUILD_DIR)/profile \
$(BUILD_DIR)/test $(BUILD_DIR)/tune
$(BUILD_DIR)/examples $(BUILD_DIR)/test \
$(BUILD_DIR)/tune

ifneq ($(PROFILING), 0)
BUILD_DIRS +=
$(patsubst %, $(BUILD_DIR)/%/profile, $(DIRS)) \
$(BUILD_DIR)/profile
endif
ifneq ($(WANT_NTL), 0)
BUILD_DIRS += \
$(BUILD_DIR)/interfaces $(BUILD_DIR)/interfaces/test
Expand Down Expand Up @@ -262,12 +269,14 @@ fmpz_lll_SOURCES := $(filter-out $(SRC_DIR)/fmpz_lll/babai.c $(SRC_DIR)/fmpz_lll

SOURCES := $(foreach dir,$(DIRS),$($(dir)_SOURCES))

ifneq ($(PROFILING), 0)
define xxx_PROF_SOURCES
$(1)_PROF_SOURCES := $(wildcard $(SRC_DIR)/$(1)/profile/*.c)
endef
_PROF_SOURCES := $(wildcard $(SRC_DIR)/profile/*.c)
$(foreach dir, $(DIRS), $(eval $(call xxx_PROF_SOURCES,$(dir))))
PROF_SOURCES := $(foreach dir,$(DIRS),$($(dir)_PROF_SOURCES)) $(_PROF_SOURCES)
endif

# FIXME: De-hardcode fq_zech_vec from this.
fq_zech_vec_TEST_SOURCES := $(wildcard $(SRC_DIR)/fq_zech_vec/test/main.c)
Expand Down Expand Up @@ -319,12 +328,14 @@ endif
# executables
################################################################################

ifneq ($(PROFILING), 0)
define xxx_PROFS
$(1)_PROFS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%$(EXEEXT),$($(1)_PROF_SOURCES))
endef
_PROFS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%$(EXEEXT),$(_PROF_SOURCES))
$(foreach dir, $(DIRS), $(eval $(call xxx_PROFS,$(dir))))
PROFS := $(foreach dir,$(DIRS),$($(dir)_PROFS)) $(_PROFS)
endif

define xxx_TESTS
$(1)_TESTS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%$(EXEEXT),$($(1)_TEST_SOURCES))
Expand Down Expand Up @@ -551,6 +562,7 @@ endif
# executables
################################################################################

ifneq ($(PROFILING), 0)
ifeq ($(SHARED), 0)
$(BUILD_DIR)/profile/%$(EXEEXT): $(SRC_DIR)/profile/%.c $(FLINT_DIR)/$(FLINT_LIB_STATIC) | $(BUILD_DIR)/profile
@echo " CC $(@:$(BUILD_DIR)/%=%)"
Expand All @@ -576,6 +588,7 @@ endef
endif

$(foreach dir, $(DIRS), $(eval $(call xxx_PROFS_rule,$(dir))))
endif

ifeq ($(SHARED), 0)
$(BUILD_DIR)/test/%$(EXEEXT): $(SRC_DIR)/test/%.c $(FLINT_DIR)/$(FLINT_LIB_STATIC) | $(BUILD_DIR)/test
Expand Down Expand Up @@ -666,11 +679,13 @@ checkexamples: examples $(EXMPS:%=%_EXMP_RUN)
# profiling
################################################################################

ifneq ($(PROFILING), 0)
ifdef MOD
profile: library $(foreach dir, $(MOD), $($(dir)_PROFS))
else
profile: library $(PROFS)
endif
endif

################################################################################
# tests
Expand Down
27 changes: 27 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ AC_CONFIG_HEADERS(src/config.h src/flint-config.h)
# features
################################################################################

AC_ARG_ENABLE(profiling,
[AS_HELP_STRING([--enable-profiling],[Enable profiling [default=no]])],
[case $enableval in
yes|no)
;;
*)
AC_MSG_ERROR([Bad value $enableval for --enable-profiling. Need yes or no.])
;;
esac],
enable_profiling="no")

AC_ARG_ENABLE(pthread,
[AS_HELP_STRING([--enable-pthread],[Enable pthread [default=yes]])],
[case $enableval in
Expand Down Expand Up @@ -1005,6 +1016,15 @@ else
TESTCFLAGS="$TESTCFLAGS $save_CFLAGS"
fi

################################################################################
# CPPFLAGS
################################################################################

if test "$enable_profiling" = "yes";
then
CPPFLAGS="$CPPFLAGS -DFLINT_PROFILE"
fi

CPPFLAGS="-I./src $CPPFLAGS"

################################################################################
Expand Down Expand Up @@ -1138,6 +1158,13 @@ else
AC_SUBST(STATIC,0)
fi

if test "$enable_profiling" = "yes";
then
AC_SUBST(PROFILING,1)
else
AC_SUBST(PROFILING,0)
fi

if test "$enable_coverage" = "yes";
then
AC_SUBST(COVERAGE,1)
Expand Down

0 comments on commit f74d9c8

Please sign in to comment.