tools: update profiling rules

A bunch of cleanups to make profiling possible again, and easier.

"make quickprof-CMD" generates a profile for CMD, which must be one
word and runs against one of the sample journals (the usual
quickprof-"SOME WORDS" quoting trick isn't working here for some
reason)

Also,

"make hledgerprof" builds the hledgerprof executable (in stack's bin dir) for profiling.

"make hledgercov" builds the hledgercov executable (in ./bin) for coverage reports
(renamed from hledgerhpc to remind me that HPC is nothing to do with heap coverage)
This commit is contained in:
Simon Michael 2015-07-22 08:52:30 -07:00
parent 9da0ab6af9
commit 523ab4331a
3 changed files with 97 additions and 105 deletions

140
Makefile
View File

@ -48,11 +48,11 @@ help2: \
# will die on encountering non-ascii data. Set LANG to something if not already set.
export LANG?=en_US.UTF-8
# # command to run during "make prof" and "make heap"
# PROFCMD=bin/hledger-prof balance -f data/1000x1000x10.journal >/dev/null
# command to run during profiling (time and heap)
#PROFCMD=stack exec -- hledgerprof balance -f data/1000x1000x10.journal >/dev/null
# #PROFRTSFLAGS=-p
# PROFRTSFLAGS=-P
#PROFRTSFLAGS=-p
PROFRTSFLAGS=-P
# # command to run during "make coverage"
# COVCMD=test
@ -202,7 +202,6 @@ BUILDFLAGS:=$(BUILDFLAGS1) -DVERSION='"$(VERSION)dev"'
# TIME:=$(shell date +"%Y%m%d%H%M")
###############################################################################
$(call def-help-subsection,INSTALLING:)
@ -300,12 +299,12 @@ build: \
# @/usr/bin/env which sp >/dev/null || \
# (echo '"sp" is required for auto-compilation. darcs get http://joyful.com/darcsden/simon/searchpath, make it (cabal install-ing any needed packages) and add it to your PATH'; exit 1)
# # force a compile even if binary exists, since we don't specify dependencies for these
# .PHONY: bin/hledgerdev bin/hledger-prof bin/hledgeropt bin/hledger-webdev
# force a compile even if binary exists, since we don't specify dependencies for these
.PHONY: bin/hledgerdev bin/hledgerprof # bin/hledger-webdev
# NB requires cabal macros generated by cabal build in hledger/
bin/hledgerdev hledgerdev: \
$(call def-help,hledgerdev, quickly build the hledger executable (with ghc and -DDEVELOPMENT) )
$(call def-help,hledgerdev, build an unoptimised "bin/hledgerdev" executable quickly (with ghc) )
$(GHC) $(MAIN) -o bin/hledgerdev $(BUILDFLAGS)
# bin/hledgerdev.ghc-%: $(SOURCEFILES) \
@ -323,47 +322,40 @@ bin/hledgerdev hledgerdev: \
# build hledger with the main supported GHC versions\
# )
# hledger-lib/Hledger/Read/TimelogReaderPP.hs
dev: dev.hs $(SOURCEFILES) \
$(call def-help,dev,build the dev.hs script (for quick experiments/benchmarks))
stack ghc -- $(CABALMACROSFLAGS) -ihledger-lib dev.hs \
hledgerprof: \
$(call def-help,hledgerprof, build "hledgerprof" for profiling (with stack) )
stack build hledger-lib hledger --library-profiling --executable-profiling --ghc-options=-fprof-auto
cp `stack exec which hledger`{,prof}
@echo to profile, use stack exec -- hledgerprof ...
dev-profile: $(SOURCEFILES) \
$(call def-help,dev-profile,profile the dev.hs script)
stack ghc -- $(CABALMACROSFLAGS) -ihledger-lib dev.hs -prof -fprof-auto -osuf p_o \
&& time ./dev +RTS -P \
&& cp dev.prof dev.prof.$(TIME) \
&& profiteur dev.prof
# #CABALINSTALLDIR=~/.cabal
# CABALINSTALLDIR=.cabal-sandbox
# bin/hledger: \
# $(call def-help,bin/hledger,\
# build the "production" optimised cabal build with profiling enabled.\
# )
# rm -f bin/hledger
# cabal install --disable-profiling ./hledger-lib ./hledger \
# && mv $(CABALINSTALLDIR)/bin/hledger bin/hledger
# bin/hledger-prof: \
# $(call def-help,bin/hledger-prof,\
# bin/hledgerprof: \
# $(call def-help,bin/hledgerprof,\
# build the "production" cabal build with profiling enabled.\
# )
# rm -f bin/hledger-prof
# rm -f bin/hledgerprof
# cabal install --enable-profiling --ghc-options=-fprof-auto ./hledger-lib ./hledger \
# && mv $(CABALINSTALLDIR)/bin/hledger bin/hledger-prof
# && mv $(CABALINSTALLDIR)/bin/hledger bin/hledgerprof
# # build the dev build with profiling enabled.
# # not working with cabal sandbox
# # bin/hledgerdev-prof:
# # $(GHC) $(BUILDFLAGS) $(PROFBUILDFLAGS) $(MAIN) -o $@
# hledgerhpc: \
# $(call def-help,hledgerhpc,\
# build the heap profiling binary for coverage reports and heap profiles.\
# Keep these .o files separate from the regular ones.\
# )
# $(GHC) $(MAIN) -fhpc -o bin/hledgerhpc -outputdir .hledgerhpcobjs $(BUILDFLAGS)
hledgercov: \
$(call def-help,hledgercov, build "bin/hledgercov" for coverage reports (with ghc) )
$(GHC) $(MAIN) -fhpc -o bin/hledgercov -outputdir .hledgercovobjs $(BUILDFLAGS)
# hledger-lib/Hledger/Read/TimelogReaderPP.hs
dev: dev.hs $(SOURCEFILES) \
$(call def-help,dev, build the dev.hs script for quick experiments (with ghc) )
stack ghc -- $(CABALMACROSFLAGS) -ihledger-lib dev.hs \
dev-profile: $(SOURCEFILES) \
$(call def-help,dev-profile, profile the dev.hs script )
stack ghc -- $(CABALMACROSFLAGS) -ihledger-lib dev.hs -prof -fprof-auto -osuf p_o \
&& time ./dev +RTS -P \
&& cp dev.prof dev.prof.$(TIME) \
&& profiteur dev.prof
# # build other executables quickly
@ -694,10 +686,10 @@ cabalfiletest: \
# prof: samplejournals \
# $(call def-help,prof,\
# generate and archive an execution profile\
# ) #bin/hledger-prof
# ) #bin/hledgerprof
# @echo "Profiling: $(PROFCMD)"
# -$(PROFCMD) +RTS $(PROFRTSFLAGS) -RTS
# mv hledger-prof.prof doc/profs/$(TIME).prof
# mv hledgerprof.prof doc/profs/$(TIME).prof
# (cd doc/profs; rm -f latest*.prof; ln -s $(TIME).prof latest.prof)
# viewprof: prof \
@ -706,21 +698,23 @@ cabalfiletest: \
# )
# tools/simplifyprof.hs doc/profs/latest.prof
# quickprof: samplejournals \
# $(call def-help,quickprof,\
# generate and display an execution profile, dont save or simplify\
# ) #bin/hledger-prof
# @echo "Profiling: $(PROFCMD)"
# -$(PROFCMD) +RTS $(PROFRTSFLAGS) -RTS
# echo; cat hledger-prof.prof
quickprof-%: hledgerprof samplejournals \
$(call def-help,quickprof-"CMD", profile some command against a sample journal and display the execution profile )
stack exec -- hledgerprof +RTS $(PROFRTSFLAGS) -RTS $* -f data/10000x1000x10.journal >/dev/null
profiteur hledgerprof.prof
@echo
@head -20 hledgerprof.prof
@echo ...
@echo
@echo see hledgerprof.prof or hledgerprof.prof.html for the full report
# heap: samplejournals \
# $(call def-help,heap,\
# generate and archive a graphical heap profile\
# ) #bin/hledger-prof
# ) #bin/hledgerprof
# @echo "Profiling heap with: $(PROFCMD)"
# $(PROFCMD) +RTS -hc -RTS
# mv hledger-prof.hp doc/profs/$(TIME).hp
# mv hledgerprof.hp doc/profs/$(TIME).hp
# (cd doc/profs; rm -f latest.hp; ln -s $(TIME).hp latest.hp; \
# hp2ps $(TIME).hp; rm -f latest.ps; ln -s $(TIME).ps latest.ps; rm -f *.aux)
@ -733,25 +727,25 @@ cabalfiletest: \
# quickheap: samplejournals \
# $(call def-help,quickheap,\
# generate and display a graphical heap profile, dont save\
# ) #bin/hledger-prof
# ) #bin/hledgerprof
# @echo "Profiling heap with: $(PROFCMD)"
# $(PROFCMD) +RTS -hc -RTS
# hp2ps hledger-prof.hp
# hp2ps hledgerprof.hp
# $(VIEWPS) hledger.ps
# quickcoverage: hledgerhpc \
# quickcoverage: hledgercov \
# $(call def-help,quickcoverage,\
# display a code coverage text report from running hledger COVCMD\
# )
# @echo "Generating code coverage text report for hledger command: $(COVCMD)"
# tools/runhledgerhpc "report" $(COVCMD)
# tools/runhledgercov "report" $(COVCMD)
# coverage: samplejournals hledgerhpc \
# coverage: samplejournals hledgercov \
# $(call def-help,coverage,\
# generate a code coverage html report from running hledger COVCMD\
# )
# @echo "Generating code coverage html report for hledger command: $(COVCMD)"
# tools/runhledgerhpc "markup --destdir=doc/profs/coverage" $(COVCMD)
# tools/runhledgercov "markup --destdir=doc/profs/coverage" $(COVCMD)
# cd doc/profs/coverage; rm -f index.html; ln -s hpc_index.html index.html
# viewcoverage: \
@ -781,31 +775,29 @@ ghci-web: \
$(call def-help,ghci-web, start a GHCI REPL and load the hledger-lib, hledger and hledger-web packages)
stack exec $(GHCI) -- $(BUILDFLAGS) hledger-web/app/main.hs
# samplejournals: data/sample.journal data/100x100x10.journal data/1000x1000x10.journal data/1000x10000x10.journal data/10000x1000x10.journal data/10000x10000x10.journal data/100000x1000x10.journal \
# $(call def-help,samplejournals,\
# generate standard sample journals in data/\
# )
samplejournals: data/sample.journal data/100x100x10.journal data/1000x1000x10.journal data/1000x10000x10.journal data/10000x1000x10.journal data/10000x10000x10.journal data/100000x1000x10.journal \
$(call def-help,samplejournals, regenerate standard sample journals in data/ )
# data/sample.journal:
# true # XXX should probably regenerate this
data/sample.journal:
true # XXX should probably regenerate this
# data/100x100x10.journal: tools/generatejournal
# tools/generatejournal 100 100 10 >$@
data/100x100x10.journal: tools/generatejournal
tools/generatejournal 100 100 10 >$@
# data/1000x1000x10.journal: tools/generatejournal
# tools/generatejournal 1000 1000 10 >$@
data/1000x1000x10.journal: tools/generatejournal
tools/generatejournal 1000 1000 10 >$@
# data/1000x10000x10.journal: tools/generatejournal
# tools/generatejournal 1000 10000 10 >$@
data/1000x10000x10.journal: tools/generatejournal
tools/generatejournal 1000 10000 10 >$@
# data/10000x1000x10.journal: tools/generatejournal
# tools/generatejournal 10000 1000 10 >$@
data/10000x1000x10.journal: tools/generatejournal
tools/generatejournal 10000 1000 10 >$@
# data/10000x10000x10.journal: tools/generatejournal
# tools/generatejournal 10000 10000 10 >$@
data/10000x10000x10.journal: tools/generatejournal
tools/generatejournal 10000 10000 10 >$@
# data/100000x1000x10.journal: tools/generatejournal
# tools/generatejournal 100000 1000 10 >$@
data/100000x1000x10.journal: tools/generatejournal
tools/generatejournal 100000 1000 10 >$@
###############################################################################
$(call def-help-subsection,DOCUMENTATION:)

31
tools/runhledgercov Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
# runhledgercov "HPCCOMMAND [HPCARGS]" [HLEDGERARGS]
#
# A front-end that resets the tix count, runs hledgercov (the HPC-enabled build)
# with the specified hledger args, and runs hpc with the specified hpc args.
# Should be run from hledger's top source directory.
#
# Eg:
# hledger$ tools/runhledgercov report test
# hledger$ tools/runhledgercov "markup --destdir=coverage" test 'some unit test'
hledgercov="hledgercov"
verbosity = 0 # 0=no output, 1=stderr only, 2=stdout+stderr
import sys, os
hpcargs, hledgerargs = sys.argv[1], ' '.join(sys.argv[2:])
# remove old tix files
os.system("rm -f %s.tix" % hledgercov)
# run the hpc-enabled binary with the specified hledger arguments to generate tix files
if verbosity<1:
os.system("bin/%s %s >/dev/null 2>&1" % (hledgercov,hledgerargs))
elif verbosity==1:
os.system("bin/%s %s >/dev/null" % (hledgercov,hledgerargs))
else:
os.system("bin/%s %s" % (hledgercov,hledgerargs))
# run the specified hpc command on the tix files
os.system("hpc %s %s" % (hpcargs,hledgercov))

View File

@ -1,31 +0,0 @@
#!/usr/bin/env python
# runhledgerhpc "HPCCOMMAND [HPCARGS]" [HLEDGERARGS]
#
# A front-end that resets the tix count, runs hledgerhpc with the
# specified hledger args, and runs hpc with the specified hpc args.
# Should be run from hledger's top source directory.
#
# Eg:
# hledger$ tools/runhledgerhpc report test
# hledger$ tools/runhledgerhpc "markup --destdir=coverage" test 'some unit test'
hledgerhpc="hledgerhpc"
verbosity = 0 # 0=no output, 1=stderr only, 2=stdout+stderr
import sys, os
hpcargs, hledgerargs = sys.argv[1], ' '.join(sys.argv[2:])
# remove old tix files
os.system("rm -f %s.tix" % hledgerhpc)
# run the hpc-enabled binary with the specified hledger arguments to generate tix files
if verbosity<1:
os.system("bin/%s %s >/dev/null 2>&1" % (hledgerhpc,hledgerargs))
elif verbosity==1:
os.system("bin/%s %s >/dev/null" % (hledgerhpc,hledgerargs))
else:
os.system("bin/%s %s" % (hledgerhpc,hledgerargs))
# run the specified hpc command on the tix files
os.system("hpc %s %s" % (hpcargs,hledgerhpc))