-
Notifications
You must be signed in to change notification settings - Fork 29
/
je
executable file
·44 lines (40 loc) · 1.06 KB
/
je
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
#!/usr/bin/env ruby
# Help
def usage
puts <<END
Usage: je [ARGS]...
Options:
-v verbose mode
--version show version
END
exit
end
# Option parsing
$verbose = false
$sys_jemalloc = '/usr/lib/x86_64-linux-gnu/libjemalloc.so.2'
argv = ARGV
usage() if argv.length == 0
if argv[0] == '-v'
$verbose = true
argv = argv[1..-1]
elsif argv[0] == '--version'
require 'jemalloc/version'
puts "jemalloc version #{JEMalloc::VERSION}"
exit
end
usage() if argv.length == 0
# Set ENV for preloading jemalloc
lib_dir = File.expand_path('../lib/', File.dirname(__FILE__))
if File.exist? (lib_dir + "/jemalloc.so")
puts "=> Injecting jemalloc..." if $verbose
ENV.store("LD_PRELOAD", lib_dir + "/jemalloc.so")
elsif File.exist? (lib_dir + "/jemalloc.bundle")
puts "=> Injecting jemalloc..." if $verbose
ENV.store("DYLD_INSERT_LIBRARIES", lib_dir + "/jemalloc.bundle")
elsif File.exist? ($sys_jemalloc)
puts "=> Injecting jemalloc..." if $verbose
ENV.store("LD_PRELOAD", $sys_jemalloc)
else
puts "=> Can't inject, jemalloc not found"
end
Kernel.exec *argv