module PAPI

Constants

COMPONENTS
COMPONENTS_HASH
EventModifier
HUGE_STR_LEN
MAX_INFO_TERMS
MAX_STR_LEN
MAX_STR_LEN2
MIN_STR_LEN
OK
PAPI_NULL
PMU_MAX
PRESET_EVENTS
PRESET_EVENTS_HASH
VERSION

Public Class Methods

error_check(errcode) click to toggle source
# File lib/PAPI/Error.rb, line 108
def self.error_check(errcode)
    return nil if errcode >= OK
    klass = Error::error_class(errcode)
    if klass then
      raise klass::new
    else
      raise Error::new("#{errcode}")
    end
end
get_components_info() click to toggle source
# File lib/PAPI/Component.rb, line 128
def self.get_components_info
  if VERSION < Version::new(4,0,0,0) then
    info_p = PAPI_get_substrate_info()
    COMPONENTS.push( Component::new(Component::Info::new(info_p)))
    COMPONENTS_HASH[0] = COMPONENTS[0]
  else
    (0...PAPI_num_components()).each { |cid|
      info_p = PAPI_get_component_info(cid)
      info = Component::Info::new(info_p)
      if VERSION >= Version::new(5,0,0,0) and info[:disabled] != 0 then
        #puts "#{info[:name].to_ptr.read_string}: #{info[:disabled_reason].to_ptr.read_string}"
      else
        COMPONENTS.push( Component::new(info, cid) )
        COMPONENTS_HASH[cid] = COMPONENTS.last
      end
    }
  end
  if COMPONENTS.length > 0 then
    COMPONENTS[0].preset = PRESET_EVENTS
  end
  COMPONENTS.each { |c|
    get_native_events( c )
  }
end
get_events_info() click to toggle source
# File lib/PAPI/Event.rb, line 120
def self.get_events_info
  e_p = FFI::MemoryPointer::new(:uint)
  e_p.write_uint(0 | Event::PRESET_MASK)
  PAPI_enum_event(e_p, :enum_first)
  info = Event::Info::new
  e = PAPI_get_event_info( e_p.read_int, info )
  ev = Event::new(info)
  PRESET_EVENTS.push(ev)
  PRESET_EVENTS_HASH[ev.to_i] = ev
  while PAPI_enum_event(e_p, :preset_enum_avail) == OK do
    info = Event::Info::new
    e = PAPI_get_event_info( e_p.read_int, info )
    ev = Event::new(info)
    PRESET_EVENTS.push(ev)
    PRESET_EVENTS_HASH[ev.to_i] = ev
  end
end
get_mask_info( code, component ) click to toggle source
# File lib/PAPI/Component.rb, line 71
def self.get_mask_info( code, component )
  m_p = FFI::MemoryPointer::new(:uint)
  m_p.write_uint( code.read_uint )
  if VERSION < Version::new(4,0,0,0) then
    e = PAPI_enum_event( m_p, :ntv_enum_umasks )
  else
    e = PAPI_enum_cmp_event( m_p, :ntv_enum_umasks, component.to_i )
  end
  return nil if e != OK
  info = Event::Info::new
  e = PAPI_get_event_info( m_p.read_int, info )
  if e == OK then
    ev = Event::new(info)
    masks = []
    masks.push(ev)
  end
  while ( VERSION < Version::new(4,0,0,0) ? PAPI_enum_event(e_p, :ntv_enum_umasks) : PAPI_enum_cmp_event( m_p, :ntv_enum_umasks, component.to_i ) ) == OK do
    info = Event::Info::new
    e = PAPI_get_event_info( m_p.read_int, info )
    next if e != OK
    ev = Event::new(info)
    masks = [] if not masks
    masks.push(ev)
  end
  return masks
end
get_native_events( component ) click to toggle source
# File lib/PAPI/Component.rb, line 98
def self.get_native_events( component )
  e_p = FFI::MemoryPointer::new(:uint)
  e_p.write_uint(0 | Event::NATIVE_MASK)
  if VERSION < Version::new(4,0,0,0) then
    e = PAPI_enum_event(e_p, :enum_first)
  else
    e = PAPI_enum_cmp_event(e_p, :enum_first, component.to_i)
  end
  return if e != OK
  info = Event::Info::new
  e = PAPI_get_event_info( e_p.read_int, info )
  if e == OK then
    ev = Event::new(info, get_mask_info( e_p, component ))
    component.native = []
    component.native.push(ev)
  end
  while ( VERSION < Version::new(4,0,0,0) ? PAPI_enum_event(e_p, :enum_events) : PAPI_enum_cmp_event(e_p, :enum_events, component.to_i) ) == OK do
    info = Event::Info::new
    e = PAPI_get_event_info( e_p.read_int, info )
    next if e != OK
    ev = Event::new(info, get_mask_info( e_p, component ) )
    component.native = [] if not component.native
    component.native.push(ev)
  end

  #puts "#{component}: #{component.to_i}"
  #puts component.native.length
  #component.native.each { |evt| puts evt.to_s(true, true) }
end
init() click to toggle source
# File lib/PAPI/Version.rb, line 57
def self.init
  6.downto(3) { |major|
    9.downto(0) { |minor|
      9.downto(0) { |revision|
        9.downto(0) { |increment|
          v = Version::new(major, minor, revision, increment)
          res = PAPI_library_init(v)
          if res == v.to_int then
            return Version::new(res)
          end
        }
      }
    }
  }
  return nil
end
list_threads() click to toggle source
# File lib/PAPI/Thread.rb, line 26
def self.list_threads
  count_p = FFI::MemoryPointer::new(:int)
  err = PAPI.PAPI_list_threads(nil, count_p)
  error_check(err)
  count = count_p.read_int
  return [] if count == 0
  id_p = FFI::MemoryPointer::new(:ulong, count)
  err = PAPI.PAPI_list_threads(id_p, count_p)
  error_check(err)
  return id_p.read_array_of_ulong(count)
end
register_thread() click to toggle source
# File lib/PAPI/Thread.rb, line 14
def self.register_thread
  err = PAPI.PAPI_register_thread
  error_check(err)
  return self
end
shutdown() click to toggle source
# File lib/PAPI/Version.rb, line 74
def self.shutdown
  PAPI_shutdown()
  return self
end
thread_init(pointer = nil) click to toggle source
# File lib/PAPI/Thread.rb, line 7
def self.thread_init(pointer = nil)
  pointer = PAPI.ffi_libraries.first.find_function("pthread_self") unless pointer
  err = PAPI.PAPI_thread_init(pointer)
  error_check(err)
  return self
end
unregister_thread() click to toggle source
# File lib/PAPI/Thread.rb, line 20
def self.unregister_thread
  err = PAPI.PAPI_unregister_thread
  error_check(err)
  return self
end