Compare commits

...

2 Commits

1 changed files with 26 additions and 21 deletions

View File

@ -54,39 +54,37 @@ PATH_PREFIX := /home/build/.local/bin:/home/build/$(CACHE_DIR)/bin:/home/build/$
PREFIX := $(HOME)/.local PREFIX := $(HOME)/.local
XDG_CONFIG_HOME := $(HOME)/.config XDG_CONFIG_HOME := $(HOME)/.config
# MacOS users do not have a 'date' command that supports milliseconds
# This is what we are forced to do. Other ideas welcome
define epochms
$$(python3 -c 'from time import time; print(int(round(time() * 1000)))')
endef
ifneq ($(TOOLCHAIN_PROFILE),false) ifneq ($(TOOLCHAIN_PROFILE),false)
TOOLCHAIN_PROFILE_DIR := .toolchain/profiles TOOLCHAIN_PROFILE_DIR := .toolchain/profiles
mkc := $(shell mkdir -p $(TOOLCHAIN_PROFILE_DIR)) mkc := $(shell mkdir -p $(TOOLCHAIN_PROFILE_DIR))
ifndef TOOLCHAIN_PROFILE_RUNNING ifndef TOOLCHAIN_PROFILE_RUNNING
TOOLCHAIN_PROFILE_INIT := $(shell date +%s) TOOLCHAIN_PROFILE_INIT := $(shell printf $(call epochms))
TOOLCHAIN_PROFILE_START := 0
TOOLCHAIN_PROFILE_TOTAL := 0
TOOLCHAIN_PROFILE_TRACKED := 0
TOOLCHAIN_PROFILE_UNTRACKED := 0
TOOLCHAIN_PROFILE_RUNNING := true TOOLCHAIN_PROFILE_RUNNING := true
TOOLCHAIN_PROFILE_FILE := \ TOOLCHAIN_PROFILE_FILE := \
$(TOOLCHAIN_PROFILE_DIR)/$(HOSTNAME)-$(USERNAME)-$(HOST_OS)-$(HOST_ARCH).$(shell date -u -d @$(TOOLCHAIN_PROFILE_INIT) +%Y%m%dT%H%M%S).csv $(TOOLCHAIN_PROFILE_DIR)/$(HOSTNAME)-$(USERNAME)-$(HOST_OS)-$(HOST_ARCH).$(shell date -u -d @$$(($(TOOLCHAIN_PROFILE_INIT) / 1000)) +%Y%m%dT%H%M%S).csv
endif endif
.PHONY: toolchain-profile .PHONY: toolchain-profile
toolchain-profile: toolchain-profile:
$(call toolchain-profile-total) $(call toolchain-profile-total)
$(call toolchain-profile-tracked)
$(call toolchain-profile-untracked)
@printf "unprofiled,%s\n" "$(TOOLCHAIN_PROFILE_UNTRACKED)" \
>> $(TOOLCHAIN_PROFILE_FILE)
@printf "total,%s\n" "$(TOOLCHAIN_PROFILE_TOTAL)" \
>> $(TOOLCHAIN_PROFILE_FILE)
@echo Build times: @echo Build times:
@bash -c ' \ @bash -c ' \
while IFS=, read -r target seconds; do \ while IFS=, read -r target ms_start ms_stop; do \
echo $$target,$$(date -u -d @$$seconds +%T); \ ms_diff=$$(($$ms_stop - $$ms_start)); \
echo - $$target,$$(date -u -d @$$(( $$ms_diff / 1000 )) +%T); \
done < $(TOOLCHAIN_PROFILE_FILE)' \ done < $(TOOLCHAIN_PROFILE_FILE)' \
| column -c 80 -s, -t | column -c 80 -s, -t
@echo "Total: $$(date -u -d @$$(( $(TOOLCHAIN_PROFILE_TOTAL) / 1000 )) +%T)";
endif endif
define toolchain-profile-total define toolchain-profile-total
$(eval TOOLCHAIN_PROFILE_TOTAL=$(shell expr $(shell date +%s) - $(TOOLCHAIN_PROFILE_INIT)) ) $(eval TOOLCHAIN_PROFILE_TOTAL=$(shell expr $(call epochms) - $(TOOLCHAIN_PROFILE_INIT)) )
endef endef
define toolchain-profile-tracked define toolchain-profile-tracked
@ -98,13 +96,17 @@ define toolchain-profile-untracked
endef endef
define toolchain-profile-start define toolchain-profile-start
$(eval TOOLCHAIN_PROFILE_START=$(shell date +%s)) printf "%s,$(call epochms),\n" "$@" >> $(TOOLCHAIN_PROFILE_FILE);
printf "%s," "$@" >> $(TOOLCHAIN_PROFILE_FILE)
endef endef
define toolchain-profile-stop define toolchain-profile-stop
printf "%s\n" "$$(($$(date +%s)-$(TOOLCHAIN_PROFILE_START)))" \ tmpfile=$$(mktemp -q "$(TOOLCHAIN_PROFILE_DIR)/tmp.XXXXXXXXX") \
>> $(TOOLCHAIN_PROFILE_FILE) && cp $(TOOLCHAIN_PROFILE_FILE) $$tmpfile \
&& awk \
-v ms="$(call epochms)" \
'/^$(@),/ {$$0=$$0ms} 1' \
$$tmpfile \
> $(TOOLCHAIN_PROFILE_FILE)
endef endef
export export
@ -150,7 +152,7 @@ toolchain-restore-mtime:
for d in $$(git ls-files | xargs -n 1 dirname | uniq); do \ for d in $$(git ls-files | xargs -n 1 dirname | uniq); do \
mkdir -p "$$d"; \ mkdir -p "$$d"; \
done; \ done; \
for f in $$(git ls-tree -r -t --full-name --name-only "HEAD"); do \ for f in $$((git ls-files --modified; git ls-files) | sort | uniq -u); do \
( test -f "$$f" || test -d "$$f" ) \ ( test -f "$$f" || test -d "$$f" ) \
&& touch -t \ && touch -t \
$$(git log \ $$(git log \
@ -407,7 +409,10 @@ define fetch_pgp_key
endef endef
define toolchain define toolchain
$(MAKE) toolchain \ ( test -f $(CACHE_DIR_ROOT)/toolchain.state || { \
echo "Error: toolchain.state not found. Check dependencies!"; \
exit 1; \
};) \
&& docker run \ && docker run \
--rm \ --rm \
--tty \ --tty \