class Mmtrix::Agent::Threading::AgentThread

Public Class Methods

backing_thread_class() click to toggle source
# File lib/mmtrix/agent/threading/agent_thread.rb, line 66
def self.backing_thread_class
  @backing_thread_class
end
backing_thread_class=(clazz) click to toggle source
# File lib/mmtrix/agent/threading/agent_thread.rb, line 70
def self.backing_thread_class=(clazz)
  @backing_thread_class = clazz
end
bucket_thread(thread, profile_agent_code) click to toggle source
# File lib/mmtrix/agent/threading/agent_thread.rb, line 36
def self.bucket_thread(thread, profile_agent_code) #THREAD_LOCAL_ACCESS
  if thread.key?(:mmtrix_label)
    profile_agent_code ? :agent : :ignore
  else
    state = TransactionState.tl_state_for(thread)
    if state.in_background_transaction?
      :background
    elsif state.in_web_transaction?
      :request
    else
      :other
    end
  end
end
create(label, &blk) click to toggle source
# File lib/mmtrix/agent/threading/agent_thread.rb, line 10
def self.create(label, &blk)
  ::Mmtrix::Agent.logger.debug("Creating Mmtrix thread: #{label}")
  wrapped_blk = Proc.new do
    begin
      blk.call
    rescue => e
      ::Mmtrix::Agent.logger.error("Thread #{label} exited with error", e)
    rescue Exception => e
      ::Mmtrix::Agent.logger.error("Thread #{label} exited with exception. Re-raising in case of interupt.", e)
      raise
    ensure
      ::Mmtrix::Agent.logger.debug("Exiting Mmtrix thread: #{label}")
    end
  end

  thread = backing_thread_class.new(&wrapped_blk)
  thread[:mmtrix_label] = label
  thread
end
list() click to toggle source

Simplifies testing if we don’t directly use ::Thread.list, so keep the accessor for it here on AgentThread to use and stub.

# File lib/mmtrix/agent/threading/agent_thread.rb, line 32
def self.list
  backing_thread_class.list
end
scrub_backtrace(thread, profile_agent_code) click to toggle source
# File lib/mmtrix/agent/threading/agent_thread.rb, line 51
def self.scrub_backtrace(thread, profile_agent_code)
  begin
    bt = thread.backtrace
  rescue Exception => e
    ::Mmtrix::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
  end
  return nil unless bt
  bt.reject! { |t| t.include?('/mmtrix_rpm-') } unless profile_agent_code
  bt
end