OILS / benchmarks / mimalloc.sh View on Github | oilshell.org

107 lines, 44 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# benchmarks/mimalloc.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10# Docs: https://github.com/microsoft/mimalloc
11
12readonly DIR=~/git/oilshell/mimalloc
13
14build-ld-preload() {
15 gcc -Wall -fPIC -shared -o _tmp/ld_preload_hook.so demo/ld_preload_hook.c -ldl
16
17 gcc -o _tmp/ld_preload_main demo/ld_preload_main.c
18}
19
20#
21# These work. mimalloc doesn't work?
22#
23
24run-main-hook() {
25 LD_PRELOAD=_tmp/ld_preload_hook.so _tmp/ld_preload_main || true
26}
27
28run-osh-hook() {
29 LD_PRELOAD=_tmp/ld_preload_hook.so _bin/cxx-dbg/osh -c 'echo hi'
30}
31
32
33#
34# Mimalloc
35#
36
37build-mimalloc() {
38 pushd $DIR
39
40 # Unity build!
41 # -fPIC for shared library
42 gcc -O2 -fPIC -I include -o mimalloc.o -c src/static.c
43 ls -l mimalloc.*
44
45 # -lpthread required
46 gcc -shared -o mimalloc.so mimalloc.o -lpthread
47
48 popd
49}
50
51build-main() {
52 ### static build of main + mimalloc
53
54 # Note that alloc.c #includes alloc-override.c
55
56 gcc -O2 -I $DIR/include -o _tmp/mimalloc.o -c $DIR/src/static.c
57
58 gcc -O2 -o _tmp/ld_preload_main.o -c demo/ld_preload_main.c
59 file _tmp/ld_preload_main.o
60
61 #gcc -o _tmp/main _tmp/ld_preload_main.o ../mimalloc/mimalloc.o -lpthread
62 #gcc -o _tmp/main ../mimalloc/mimalloc.o _tmp/ld_preload_main.o -lpthread
63
64 gcc -o _tmp/main _tmp/mimalloc.o _tmp/ld_preload_main.o -lpthread
65 file _tmp/main
66
67 nm _tmp/main | grep -i malloc
68
69 set -x
70 MIMALLOC_VERBOSE=1 _tmp/main
71}
72
73# https://microsoft.github.io/mimalloc/environment.html
74
75# Not working, try STATIC linking
76# https://microsoft.github.io/mimalloc/overrides.html
77
78run-main-mim() {
79 # Doesn't show stats?
80 # MIMALLOC_SHOW_STATS=1 LD_PRELOAD=$DIR/mimalloc.so ls
81
82 # Works
83 MIMALLOC_VERBOSE=1 LD_PRELOAD=$DIR/mimalloc.so \
84 _tmp/ld_preload_main
85}
86
87run-osh-mim() {
88 local osh=_bin/cxx-opt/osh
89
90 #local osh=_bin/cxx-opt/mycpp/demo/gc_header
91
92 #local osh=_bin/cxx-dbg/osh
93
94 ninja $osh
95 #export MIMALLOC_SHOW_STATS=1
96 MIMALLOC_VERBOSE=1 LD_PRELOAD=$DIR/mimalloc.so \
97 $osh "$@"
98}
99
100# No stats?
101osh-demo() {
102 run-osh-mim -c 'for i in $(seq 1000); do echo $i; done'
103}
104
105
106
107"$@"