Sha256: 83bb75a4b242e298c195b2bc3f254c5e913b869869f006e456fa939967502e0b

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

module OneApm
  class Transaction

    @@java_classes_loaded = false

    if defined? JRuby
      begin
        require 'java'
        java_import 'java.lang.management.ManagementFactory'
        java_import 'com.sun.management.OperatingSystemMXBean'
        @@java_classes_loaded = true
      rescue
      end
    end

    OA_JRUBY_CPU_TIME_ERROR = "Error calculating JRuby CPU Time".freeze

    def jruby_cpu_time
      return nil unless @@java_classes_loaded
      threadMBean = Java::JavaLangManagement::ManagementFactory.getThreadMXBean()

      return nil unless threadMBean.isCurrentThreadCpuTimeSupported
      java_utime = threadMBean.getCurrentThreadUserTime()  # ns

      -1 == java_utime ? 0.0 : java_utime/1e9
    rescue => e
      OneApm::Manager.logger.log_once(:warn, :jruby_cpu_time, OA_JRUBY_CPU_TIME_ERROR, e)
      OneApm::Manager.logger.debug(OA_JRUBY_CPU_TIME_ERROR, e)
      nil
    end

    def jruby_cpu_burn
      return unless @jruby_cpu_start
      jruby_cpu_time - @jruby_cpu_start
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.4.1 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.4.0 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.3.7 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/transaction/transaction_jruby_functions.rb