Sha256: 4c1ec2d842d897b11295a4bcd12897e8e56cb50d2ef26629b85f41863f5e4f1e

Contents?: true

Size: 1.84 KB

Versions: 80

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8
java_import 'org.logstash.instrument.reports.ThreadsReport'

module LogStash
  module Util
    class ThreadDump
      SKIPPED_THREADS             = [ "Finalizer", "Reference Handler", "Signal Dispatcher" ].freeze
      THREADS_COUNT_DEFAULT       = 3.freeze
      IGNORE_IDLE_THREADS_DEFAULT = true.freeze

      attr_reader :top_count, :ignore, :dump

      def initialize(options={})
        @options   = options
        @dump = options.fetch(:dump, ThreadsReport.generate({}))
        @top_count = options.fetch(:threads, THREADS_COUNT_DEFAULT)
        @ignore    = options.fetch(:ignore_idle_threads, IGNORE_IDLE_THREADS_DEFAULT)
      end

      def each(&block)
        i=0
        dump.each do |hash|
          thread_name = hash["thread.name"]
          break if i >= top_count
          if ignore
            next if idle_thread?(thread_name, hash)
          end
          block.call(hash)
          i += 1
        end
      end

      def idle_thread?(thread_name, data)
        idle = false
        if SKIPPED_THREADS.include?(thread_name)
          # these are likely JVM dependent
          idle = true
        elsif thread_name.match(/Ruby-\d+-JIT-\d+/)
          # This are internal JRuby JIT threads, 
          # see java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor for details.
          idle = true
        elsif thread_name.match(/pool-\d+-thread-\d+/)
          # This are threads used by the internal JRuby implementation to dispatch
          # calls and tasks, see prg.jruby.internal.runtime.methods.DynamicMethod.call
          idle = true
        else
          data["thread.stacktrace"].each do |trace|
            if trace.start_with?("java.util.concurrent.ThreadPoolExecutor.getTask")
              idle = true
              break
            end
          end
        end
        idle
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 5 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/util/thread_dump.rb
logstash-core-5.6.16-java lib/logstash/util/thread_dump.rb
logstash-core-5.6.15-java lib/logstash/util/thread_dump.rb
logstash-core-6.5.4-java lib/logstash/util/thread_dump.rb
logstash-core-6.5.3-java lib/logstash/util/thread_dump.rb
logstash-core-5.6.14-java lib/logstash/util/thread_dump.rb
logstash-core-6.5.2-java lib/logstash/util/thread_dump.rb
logstash-core-6.5.1-java lib/logstash/util/thread_dump.rb
logstash-core-7.0.0.alpha1-java lib/logstash/util/thread_dump.rb
logstash-core-6.5.0-java lib/logstash/util/thread_dump.rb