Skip to content

Instantly share code, notes, and snippets.

@CandyMi
Last active August 13, 2024 11:36
Show Gist options
  • Save CandyMi/2d49ca12ced3906d0b33a3a3d273473f to your computer and use it in GitHub Desktop.
Save CandyMi/2d49ca12ced3906d0b33a3a3d273473f to your computer and use it in GitHub Desktop.
Unix-Like 运行包装脚本

运行脚本

自动搜索安装的内存分配器并加入到LDPRELAOD中, 然后运行后续参数的内容.

使用示例

运行后在下面的命令:

root@localhost:~/xrioadmin$ ./start.sh luac -

然后通过procfs查看内存分布情况:

root@localhost:~/xrioadmin$ cat /proc/`pidof luac`/map
55caea1c8000-55caea1cb000 r--p 00000000 08:30 21172                      /usr/bin/luac5.4
55caea1cb000-55caea1ea000 r-xp 00003000 08:30 21172                      /usr/bin/luac5.4
55caea1ea000-55caea1f4000 r--p 00022000 08:30 21172                      /usr/bin/luac5.4
55caea1f4000-55caea1f5000 r--p 0002b000 08:30 21172                      /usr/bin/luac5.4
55caea1f5000-55caea1f6000 rw-p 0002c000 08:30 21172                      /usr/bin/luac5.4
7f5dba000000-7f5dba800000 rw-p 00000000 00:00 0 
7f5dba845000-7f5dba84c000 rw-p 00000000 00:00 0 
7f5dba84c000-7f5dba84f000 r--p 00000000 08:30 1711                       /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7f5dba84f000-7f5dba866000 r-xp 00003000 08:30 1711                       /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7f5dba866000-7f5dba86a000 r--p 0001a000 08:30 1711                       /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7f5dba86a000-7f5dba86b000 r--p 0001d000 08:30 1711                       /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7f5dba86b000-7f5dba86c000 rw-p 0001e000 08:30 1711                       /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
7f5dba86c000-7f5dba905000 r--p 00000000 08:30 1313                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30
7f5dba905000-7f5dbaa06000 r-xp 00099000 08:30 1313                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30
7f5dbaa06000-7f5dbaa75000 r--p 0019a000 08:30 1313                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30
7f5dbaa75000-7f5dbaa80000 r--p 00209000 08:30 1313                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30
7f5dbaa80000-7f5dbaa83000 rw-p 00214000 08:30 1313                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30
7f5dbaa83000-7f5dbaa86000 rw-p 00000000 00:00 0 
7f5dbaa86000-7f5dbaaac000 r--p 00000000 08:30 21311                      /usr/lib/x86_64-linux-gnu/libc.so.6
7f5dbaaac000-7f5dbac01000 r-xp 00026000 08:30 21311                      /usr/lib/x86_64-linux-gnu/libc.so.6
7f5dbac01000-7f5dbac54000 r--p 0017b000 08:30 21311                      /usr/lib/x86_64-linux-gnu/libc.so.6
7f5dbac54000-7f5dbac58000 r--p 001ce000 08:30 21311                      /usr/lib/x86_64-linux-gnu/libc.so.6
7f5dbac58000-7f5dbac5a000 rw-p 001d2000 08:30 21311                      /usr/lib/x86_64-linux-gnu/libc.so.6
7f5dbac5a000-7f5dbac67000 rw-p 00000000 00:00 0 
7f5dbac67000-7f5dbac77000 r--p 00000000 08:30 21314                      /usr/lib/x86_64-linux-gnu/libm.so.6
7f5dbac77000-7f5dbacea000 r-xp 00010000 08:30 21314                      /usr/lib/x86_64-linux-gnu/libm.so.6
7f5dbacea000-7f5dbad44000 r--p 00083000 08:30 21314                      /usr/lib/x86_64-linux-gnu/libm.so.6
7f5dbad44000-7f5dbad45000 r--p 000dc000 08:30 21314                      /usr/lib/x86_64-linux-gnu/libm.so.6
7f5dbad45000-7f5dbad46000 rw-p 000dd000 08:30 21314                      /usr/lib/x86_64-linux-gnu/libm.so.6
7f5dbad4c000-7f5dbad55000 r--p 00000000 08:30 18076                      /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
7f5dbad55000-7f5dbadfb000 r-xp 00009000 08:30 18076                      /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
7f5dbadfb000-7f5dbae13000 r--p 000af000 08:30 18076                      /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
7f5dbae13000-7f5dbae19000 r--p 000c6000 08:30 18076                      /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
7f5dbae19000-7f5dbae1a000 rw-p 000cc000 08:30 18076                      /usr/lib/x86_64-linux-gnu/libjemalloc.so.2
7f5dbae1a000-7f5dbb03b000 rw-p 00000000 00:00 0 
7f5dbb03b000-7f5dbb03c000 r--p 00000000 08:30 21308                      /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7f5dbb03c000-7f5dbb061000 r-xp 00001000 08:30 21308                      /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7f5dbb061000-7f5dbb06b000 r--p 00026000 08:30 21308                      /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7f5dbb06b000-7f5dbb06d000 r--p 00030000 08:30 21308                      /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7f5dbb06d000-7f5dbb06f000 rw-p 00032000 08:30 21308                      /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
7fffca71c000-7fffca73e000 rw-p 00000000 00:00 0                          [stack]
7fffca7c5000-7fffca7c9000 r--p 00000000 00:00 0                          [vvar]
7fffca7c9000-7fffca7cb000 r-xp 00000000 00:00 0                          [vdso]
#!/usr/bin/env bash
xrio_exec=''
function xrio_check_args() {
xrio_nargs=$#
if [ $xrio_nargs -lt 1 ]; then
echo "The first argument is the executable file name."
exit 1;
fi
local file=`which $1`
if [ ! -f $file ]; then
echo "file '$1' doest not exist."
exit 1;
fi
if [ ! -x file ]; then
xrio_exec="./"
fi
}
xrio_os=`uname -s`
xrio_allocator=''
function xrio_check_allocator() {
xrio_allocator="`find /usr/local/lib -name *malloc.so*`"
if [ -z $xrio_allocator ]; then
# Homebrew for MacOS
if [ $xrio_os = 'Darwin' ]; then
xrio_allocator="`find /usr/local/Celler -name *malloc.so*`"
fi
# find allocator in system path.
if [ -z $xrio_allocator ]; then
xrio_allocator="`find /usr/lib -name *malloc.so*`"
fi
fi
}
function xrio_run() {
LD_PRELOAD="${xrio_allocator}:${LD_PRELOAD}" $xrio_exec$@
}
xrio_check_args $@
xrio_check_allocator
xrio_run $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment