-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (58 loc) · 2.62 KB
/
Copy pathMakefile
File metadata and controls
83 lines (58 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
VERBOSITY ?= 0
COVERAGE ?= 0
CXX ?= g++
CXXFLAGS = -Wall -fno-omit-frame-pointer -fvisibility=hidden -std=gnu++17 $(UNWIND_INCLUDES) -DVERBOSITY=$(VERBOSITY)
ifeq ($(COVERAGE),1)
CXXFLAGS += --coverage
endif
PYTHON ?= python3
all: libmemtrail.so sample benchmark
libmemtrail.so: memtrail.cpp memtrail.version
ifeq ($(shell test -d libunwind && echo true),true)
$(info info: using local libunwind)
libunwind/configure: libunwind/configure.ac
autoreconf -i libunwind
libunwind/Makefile: libunwind/configure
cd libunwind && ./configure --disable-cxx-exceptions --disable-debug-frame --disable-block-signals --disable-shared --enable-static --with-pic --prefix=$(abspath local)
local/lib/pkgconfig/libunwind.pc: libunwind/Makefile
$(MAKE) -C libunwind install
libmemtrail.so: local/lib/pkgconfig/libunwind.pc
export PKG_CONFIG_PATH := $(abspath local)/lib/pkgconfig:$(PKG_CONFIG_PATH)
else
$(info info: using system's libunwind)
endif
libmemtrail.so: Makefile
pkg-config --cflags --libs --static libunwind
$(CXX) -O2 -g2 $(CXXFLAGS) -shared -fPIC -Wl,--version-script,memtrail.version -o $@ memtrail.cpp $$(pkg-config --cflags --libs --static libunwind) -ldl
%: %.cpp
$(CXX) -O0 -g2 -Wno-unused-result -o $@ $< -ldl
gprof2dot.py:
wget --quiet --timestamping https://raw.githubusercontent.com/jrfonseca/gprof2dot/main/gprof2dot.py
chmod +x gprof2dot.py
sample: sample.cpp memtrail.h
test: libmemtrail.so sample gprof2dot.py
$(RM) memtrail.data $(wildcard memtrail.*.json) $(wildcard memtrail.*.dot)
ifeq ($(COVERAGE),1)
$(RM) *.gcda
endif
$(PYTHON) memtrail record ./sample
ifeq ($(COVERAGE),1)
$(PYTHON) -m gcovr --exclude-unreachable-branches --exclude-throw-branches --object-directory . --html-details coverage.html
endif
$(PYTHON) memtrail dump
$(PYTHON) memtrail report --show-snapshots --show-snapshot-deltas --show-cumulative-snapshot-delta --show-maximum --show-leaks --output-graphs
$(foreach LABEL, snapshot-0 snapshot-1 snapshot-1-delta maximum leaked, ./gprof2dot.py -f json memtrail.$(LABEL).json > memtrail.$(LABEL).dot ;)
test-debug: libmemtrail.so sample
$(RM) memtrail.data $(wildcard memtrail.*.json) $(wildcard memtrail.*.dot)
$(PYTHON) memtrail record --debug ./sample
bench: libmemtrail.so benchmark
$(RM) memtrail.data
$(PYTHON) memtrail record ./benchmark
time -p $(PYTHON) memtrail report --show-maximum
profile: benchmark gprof2dot.py
$(PYTHON) memtrail record ./benchmark
$(PYTHON) -m cProfile -o memtrail.pstats -- memtrail report --show-maximum
./gprof2dot.py -f pstats memtrail.pstats > memtrail.dot
clean:
$(RM) libmemtrail.so gprof2dot.py sample benchmark
.PHONY: all test test-debug bench profile clean