Skip to content

Commit

Permalink
- Use prctl to set the lwp/thread name under Linux. This makes the
Browse files Browse the repository at this point in the history
  threads easily identifiable in top.
  • Loading branch information
jordansissel committed Jan 17, 2013
1 parent 5c0b272 commit 0c40cb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/logstash/util.rb
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
1 change: 1 addition & 0 deletions logstash.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "minitest" # for running the tests from the jar
gem.add_runtime_dependency "pry"
gem.add_runtime_dependency "stud"
gem.add_runtime_dependency "sys-uname" # for platform detection

# Web dependencies
gem.add_runtime_dependency "ftw", ["~> 0.0.26"]
Expand Down

0 comments on commit 0c40cb8

Please sign in to comment.