start pgo target

rust
Avril 4 years ago
parent fd9792fdcc
commit 14ead65f3d
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -17,7 +17,18 @@ DEBUG_LDFLAGS?= -O0
CFLAGS+= $(FEAT_CFLAGS) -Wall -pedantic --std=gnu11 $(addprefix -I,$(INCLUDE)) CFLAGS+= $(FEAT_CFLAGS) -Wall -pedantic --std=gnu11 $(addprefix -I,$(INCLUDE))
LDFLAGS+= $(FEAT_LDFLAGS) LDFLAGS+= $(FEAT_LDFLAGS)
# PGO specific vars
PROF_ITERATIONS=1000
PROF_LARGE_BOUND= $$(( 1024 * 1024 * 10 ))
PROF_SMALL_BOUND= $$(( 1024 * 10 ))
PROF_LOCATION?=/tmp/fcmp-pgo
PROF_FLAGS = -fprofile-generate
OBJ = $(addprefix obj/,$(SRC:.c=.o)) OBJ = $(addprefix obj/,$(SRC:.c=.o))
PGO_OBJ = $(addprefix prof/,$(SRC:.c=.o))
.PHONY: release .PHONY: release
release: | dirs $(PROJECT)-release release: | dirs $(PROJECT)-release
@ -25,12 +36,18 @@ release: | dirs $(PROJECT)-release
.PHONY: debug .PHONY: debug
debug: | dirs $(PROJECT)-debug debug: | dirs $(PROJECT)-debug
.PHONY: pgo
pgo: | dirs $(PROJECT)-pgo
dirs: dirs:
@mkdir -p obj/src @mkdir -p {obj,prof}/src
obj/%.o: %.c obj/%.o: %.c
$(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS) $(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS)
prof/%.o: %.c
$(CC) -c $< $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
$(PROJECT)-release: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS) $(PROJECT)-release: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
$(PROJECT)-release: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS) $(PROJECT)-release: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
$(PROJECT)-release: $(OBJ) $(PROJECT)-release: $(OBJ)
@ -42,6 +59,42 @@ $(PROJECT)-debug: LDFLAGS := $(DEBUG_LDFLAGS) $(LDFLAGS)
$(PROJECT)-debug: $(OBJ) $(PROJECT)-debug: $(OBJ)
$(CC) $^ $(CFLAGS) -o $@ $(LDFLAGS) $(CC) $^ $(CFLAGS) -o $@ $(LDFLAGS)
pgo-generate: $(PGO_OBJ)
$(CC) -c $< $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
pgo-reset:
find ./prof -name \*.gcda -exec rm {} +
pgo-profile: | pgo-reset pgo-generate
@mkdir -p $(PROF_LOCATION)/{large,small}
#./profile/gen $(PROF_LARGE_BOUND) "$(PROF_LOCATION)/large"
#./profile/gen $(PROF_SMALL_BOUND) "$(PROF_LOCATION)/small"
for i in {1..$(PROF_ITERATIONS)}; do \
./profile/gen $(PROF_LARGE_BOUND) "$(PROF_LOCATION)/large"; \
./profile/gen $(PROF_SMALL_BOUND) "$(PROF_LOCATION)/small"; \
./pgo-generate $(PROF_LOCATION)/large/matching > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/large/unmatching > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/small/matching > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/small/unmatching > $(PROF_LOCATION)/stdout; \
#TODO: More combinations \
done
rm -rf $(PROF_LOCATION)
rm pgo-generate
pgo-use: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
pgo-use: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
pgo-use: PROF_FLAGS = -fprofile-use
pgo-use: $(PGO_OBJ)
$(CC) -c $< $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
$(PROJECT)-pgo: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
$(PROJECT)-pgo: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
$(PROJECT)-pgo: pgo-profile
find ./prof -name \*.o -exec rm {} +
$(MAKE) pgo-use
mv pgo-use $@
strip $@
clean: clean:
rm -rf obj rm -rf {obj,prof}
rm -f $(PROJECT)-{release,debug} rm -f $(PROJECT)-{release,debug}

@ -0,0 +1,33 @@
#!/bin/bash
# Generate 100 matching
bound=$1
ITERATIONS=${ITERATIONS:-100}
BREAK_AT=50
cd $2 || exit 1
echo ">>> Generating ${ITERATIONS} matching files"
mkdir matching
dd if=/dev/urandom of=./matching/0 bs=$bound count=1 >> /dev/null 2>&1 || exit 1
pushd matching >>/dev/null
for i in $(seq 1 ${ITERATIONS}); do
cp -f 0 $i || exit 1
done
popd >>/dev/null
echo ">>> Generatig ${ITERATIONS} with unmatching file"
mkdir unmatching
dd if=/dev/urandom of=./unmatching/0 bs=$bound count=1 >> /dev/null 2>&1 || exit 1
pushd unmatching >> /dev/null
for i in $(seq 1 ${ITERATIONS}); do
if [[ $i == ${BREAK_AT} ]]; then
echo " $i < unmatching"
dd if=/dev/urandom of=$i bs=$bound count=1 >>/dev/null 2>&1 || exit
else
cp -f 0 $i || exit 1
fi
done
popd >> /dev/null
echo ">>> Generated in $2"
Loading…
Cancel
Save