Sha256: 04556c0f7fa5391bfdab218a6abe189d54287819c64c081ddf330a968a8dc5a8

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 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

    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::Agent.logger.log_once(:warn, :jruby_cpu_time, JRUBY_CPU_TIME_ERROR, e)
      ::OneApm::Agent.logger.debug(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

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.2 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.1.1 lib/one_apm/transaction/transaction_jruby_functions.rb
oneapm_rpm-1.1.0 lib/one_apm/transaction/transaction_jruby_functions.rb