forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use prctl to set the lwp/thread name under Linux. This makes the
threads easily identifiable in top.
- Loading branch information
1 parent
5c0b272
commit 0c40cb8
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
require "logstash/namespace" | ||
require "ffi" # gem ffi | ||
require "sys/uname" # gem sys-uname | ||
|
||
module LogStash::Util | ||
PR_SET_NAME = 15 | ||
UNAME = Sys::Uname.uname.sysname | ||
|
||
module LibC | ||
extend FFI::Library | ||
if UNAME == "Linux" | ||
ffi_lib 'c' | ||
|
||
# Ok so the 2nd arg isn't really a string... but whaatever | ||
attach_function :prctl, [:int, :string, :long, :long, :long], :int | ||
end | ||
end | ||
|
||
def self.set_thread_name(name) | ||
if RUBY_ENGINE == "jruby" | ||
# Keep java and ruby thread names in sync. | ||
Java::java.lang.Thread.currentThread.setName(name) | ||
end | ||
Thread.current[:name] = name | ||
|
||
if UNAME == "Linux" | ||
# prctl PR_SET_NAME allows up to 16 bytes for a process name | ||
# since MRI 1.9 and JRuby use system threads for this. | ||
LibC.prctl(PR_SET_NAME, name[0..16], 0, 0, 0) | ||
end | ||
end # def set_thread_name | ||
end # module LogStash::Util |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters