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
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)
TOOLCHAIN_PROFILE_DIR := .toolchain/profiles
mkc := $(shell mkdir -p $(TOOLCHAIN_PROFILE_DIR))
ifndef TOOLCHAIN_PROFILE_RUNNING
TOOLCHAIN_PROFILE_INIT := $(shell date +%s)
TOOLCHAIN_PROFILE_START := 0
TOOLCHAIN_PROFILE_TOTAL := 0
TOOLCHAIN_PROFILE_TRACKED := 0
TOOLCHAIN_PROFILE_UNTRACKED := 0
TOOLCHAIN_PROFILE_INIT := $(shell printf $(call epochms))
TOOLCHAIN_PROFILE_RUNNING := true
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
.PHONY: toolchain-profile
toolchain-profile:
$(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:
@bash -c ' \
while IFS=, read -r target seconds; do \
echo $$target,$$(date -u -d @$$seconds +%T); \
while IFS=, read -r target ms_start ms_stop; do \
ms_diff=$$(($$ms_stop - $$ms_start)); \
echo - $$target,$$(date -u -d @$$(( $$ms_diff / 1000 )) +%T); \
done < $(TOOLCHAIN_PROFILE_FILE)' \
| column -c 80 -s, -t
@echo "Total: $$(date -u -d @$$(( $(TOOLCHAIN_PROFILE_TOTAL) / 1000 )) +%T)";
endif
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
define toolchain-profile-tracked
@ -98,13 +96,17 @@ define toolchain-profile-untracked
endef
define toolchain-profile-start
$(eval TOOLCHAIN_PROFILE_START=$(shell date +%s))
printf "%s," "$@" >> $(TOOLCHAIN_PROFILE_FILE)
printf "%s,$(call epochms),\n" "$@" >> $(TOOLCHAIN_PROFILE_FILE);
endef
define toolchain-profile-stop
printf "%s\n" "$$(($$(date +%s)-$(TOOLCHAIN_PROFILE_START)))" \
>> $(TOOLCHAIN_PROFILE_FILE)
tmpfile=$$(mktemp -q "$(TOOLCHAIN_PROFILE_DIR)/tmp.XXXXXXXXX") \
&& cp $(TOOLCHAIN_PROFILE_FILE) $$tmpfile \
&& awk \
-v ms="$(call epochms)" \
'/^$(@),/ {$$0=$$0ms} 1' \
$$tmpfile \
> $(TOOLCHAIN_PROFILE_FILE)
endef
export
@ -150,7 +152,7 @@ toolchain-restore-mtime:
for d in $$(git ls-files | xargs -n 1 dirname | uniq); do \
mkdir -p "$$d"; \
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" ) \
&& touch -t \
$$(git log \
@ -407,7 +409,10 @@ define fetch_pgp_key
endef
define toolchain
$(MAKE) toolchain \
( test -f $(CACHE_DIR_ROOT)/toolchain.state || { \
echo "Error: toolchain.state not found. Check dependencies!"; \
exit 1; \
};) \
&& docker run \
--rm \
--tty \