hunk ./README 4 -It is an early alpha release but for basic use of the High Level interface -it should be fully functional. +It is an early alpha release and the interface may change +but for basic use of the High Level interface it should be fully functional. hunk ./README 10 -Please report any bugs to . +Please report any bugs to . hunk ./README 40 +Comparison with GHC's built-in PAPI +=================================== +GHC supports a build-in version of PAPI +(see http://hackage.haskell.org/trac/ghc/wiki/PAPI). +This system is different in a few ways. + +First, hpapi allows you to measure specific parts of a program +while GHCI's PAPI only does whole program measurement + +Second, since hpapi is a library you can have fine grained +and sophisticated control over how things are measured. +On the otherhand GHC's PAPI as part of the RTS gives you less +control, but on the plus side doesn't require any modification +to the program. + +Finally, GHC's PAPI splits appart the counts that come from +the garbage collector from those that come from the mutator, +while hpapi combines them. This is a limitation of hpapi +we hope to correct some time in the future. + +It remains to be seen whether it would be worth while +to unify these two systems. + hunk ./README 65 -TODO: separate out GC numbers -TODO: other future directions + - The following "advanced" features of PAPI have been left + out in this first release: + - Multiplexing + - Threads + - Locks + - Overflow + - Statistical Profiling + + - Separate GC and mutator counters + + - Integration with GHC's built-in PAPI + + - Improved documentation. + + - Depending on feedback, modules may get reorganized hunk ./README 81 -TODO: restrict interface -TODO: deriving instances -TODO: note about differences from http://hackage.haskell.org/trac/ghc/wiki/PAPI + - Better handling of errors from the PAPI library + (currently they just throw IO errors) hunk ./System/PAPI.hs 26 --- TODO: empty LowLevel.hsc --- TODO: empty Types.hsc --- TODO: determine if PAPI.Util is needed - hunk ./System/PAPI.hs 28 --- TODO: minor fixes hunk ./System/PAPI.hs 43 --- TODO: getOpt and setOpt hunk ./System/PAPI.hs 47 +-- PAPI Error Handling +import System.PAPI.Error + hunk ./System/PAPI.hs 90 --- PAPI Error Handling -import System.PAPI.Error - --------- - --- TODO: check PAPI_MIN_STR_LEN, PAPI_MAX_STR_LEN, PAPI_2MAX_STR_LEN and PAPI_HUGE_STR_LEN - hunk ./System/PAPI/Error.hsc 15 -module System.PAPI.Error where +module System.PAPI.Error ( + papiThrow +, papiStrError +, PapiError(..) +, papiErrorOk +, papiErrorEinval +, papiErrorEnomem +, papiErrorEsys +, papiErrorEsbstr +, papiErrorEnosupp +, papiErrorEbug +, papiErrorEnoevnt +, papiErrorEcnflct +, papiErrorEnotrun +, papiErrorEisrun +, papiErrorEnoevst +, papiErrorEnotpreset +, papiErrorEnocntr +, papiErrorEmisc +, papiErrorEperm +, papiErrorEnoinit +, papiErrorEbuf +) where hunk ./System/PAPI/Error.hsc 44 +-- Private functions hunk ./System/PAPI/Error.hsc 48 -foreign import ccall "PAPI_strerror" papi_strerror :: ReturnCode -> CString +foreign import ccall "PAPI_strerror" papi_strerror :: PapiError -> CString + hunk ./System/PAPI/Error.hsc 52 -papiThrow :: String -> ReturnCode -> IO CInt -papiThrow _ (ReturnCode err) | err >= 0 = return err +-- Public functions +papiThrow :: String -> PapiError -> IO CInt +papiThrow _ (PapiError err) | err >= 0 = return err hunk ./System/PAPI/Error.hsc 57 -nullThrow :: String -> Ptr a -> IO (Ptr a) -nullThrow str ptr = if ptr == nullPtr then error str else return ptr - -papiStrError :: ReturnCode -> IO String +papiStrError :: PapiError -> IO String hunk ./System/PAPI/Error.hsc 61 - then return $ "Unknown error " ++ show (unReturnCode err) + then return $ "Unknown error " ++ show (unPapiError err) hunk ./System/PAPI/Error.hsc 64 - if err /= papi_esys + if err /= papiErrorEsys hunk ./System/PAPI/Error.hsc 70 -newtype ReturnCode = ReturnCode { unReturnCode :: CInt } deriving (Eq) -#{enum ReturnCode, ReturnCode -, papi_ok = PAPI_OK /*No error */ -, papi_einval = PAPI_EINVAL /*Invalid argument */ -, papi_enomem = PAPI_ENOMEM /*Insufficient memory */ -, papi_esys = PAPI_ESYS /*A SystemC library call failed please check errno */ -, papi_esbstr = PAPI_ESBSTR /*Substrate returned an error - usually the result of an unimplemented feature */ -, papi_enosupp = PAPI_ENOSUPP /*Access to the counters was lost or interrupted */ -, papi_ebug = PAPI_EBUG /*Internal error. please send mail to the developers */ -, papi_enoevnt = PAPI_ENOEVNT /*Hardware Event does not exist */ -, papi_ecnflct = PAPI_ECNFLCT /*Hardware Event exists but cannot be counted - due to counter resource limitations */ -, papi_enotrun = PAPI_ENOTRUN /*No Events or EventSets are currently counting */ -, papi_eisrun = PAPI_EISRUN /*Events or EventSets are currently counting */ -, papi_enoevst = PAPI_ENOEVST /* No EventSet Available */ -, papi_enotpreset = PAPI_ENOTPRESET /* Not a Preset Event in argument */ -, papi_enocntr = PAPI_ENOCNTR /* Hardware does not support counters */ -, papi_emisc = PAPI_EMISC /* No clue as to what this error code means */ -, papi_eperm = PAPI_EPERM /* You lack the necessary permissions */ -, papi_enoinit = PAPI_ENOINIT /* PAPI hasn't been initialized yet */ -, papi_ebuf = PAPI_EBUF /* Buffer size exceeded (usually strings) */ +newtype PapiError = PapiError { unPapiError :: CInt } deriving (Eq, Show) +#{enum PapiError, PapiError +, papiErrorOk = PAPI_OK /*No error*/ +, papiErrorEinval = PAPI_EINVAL /*Invalid argument*/ +, papiErrorEnomem = PAPI_ENOMEM /*Insufficient memory*/ +, papiErrorEsys = PAPI_ESYS /*A SystemC library call failed please check errno*/ +, papiErrorEsbstr = PAPI_ESBSTR /*Substrate returned an error + usually the result of an unimplemented feature*/ +, papiErrorEnosupp = PAPI_ENOSUPP /*Access to the counters was lost or interrupted*/ +, papiErrorEbug = PAPI_EBUG /*Internal error. please send mail to the developers*/ +, papiErrorEnoevnt = PAPI_ENOEVNT /*Hardware Event does not exist*/ +, papiErrorEcnflct = PAPI_ECNFLCT /*Hardware Event exists but cannot be counted + due to counter resource limitations*/ +, papiErrorEnotrun = PAPI_ENOTRUN /*No Events or EventSets are currently counting*/ +, papiErrorEisrun = PAPI_EISRUN /*Events or EventSets are currently counting*/ +, papiErrorEnoevst = PAPI_ENOEVST /* No EventSet Available*/ +, papiErrorEnotpreset = PAPI_ENOTPRESET /* Not a Preset Event in argument*/ +, papiErrorEnocntr = PAPI_ENOCNTR /* Hardware does not support counters*/ +, papiErrorEmisc = PAPI_EMISC /* No clue as to what this error code means*/ +, papiErrorEperm = PAPI_EPERM /* You lack the necessary permissions*/ +, papiErrorEnoinit = PAPI_ENOINIT /* PAPI hasn't been initialized yet*/ +, papiErrorEbuf = PAPI_EBUF /* Buffer size exceeded (usually strings)*/ hunk ./System/PAPI/Event.hsc 15 -module System.PAPI.Event where +module System.PAPI.Event ( + enumEvent +, getEventInfo +, queryEvent +, eventCodeToName +, eventNameToCode + +, EventCode(..) +, papi_null +, papi_br_cn +, papi_br_ins +, papi_br_msp +, papi_br_ntk +, papi_br_prc +, papi_br_tkn +, papi_br_ucn +, papi_bru_idl +, papi_btac_m +, papi_ca_cln +, papi_ca_inv +, papi_ca_itv +, papi_ca_shr +, papi_ca_snp +, papi_csr_fal +, papi_csr_suc +, papi_csr_tot +, papi_fad_ins +, papi_fdv_ins +, papi_fma_ins +, papi_fml_ins +, papi_fnv_ins +, papi_fp_ins +, papi_fp_ops +, papi_fp_stal +, papi_fpu_idl +, papi_fsq_ins +, papi_ful_ccy +, papi_ful_icy +, papi_fxu_idl +, papi_hw_int +, papi_int_ins +, papi_tot_cyc +, papi_tot_iis +, papi_tot_ins +, papi_vec_ins +, papi_l1_dca +, papi_l1_dch +, papi_l1_dcm +, papi_l1_dcr +, papi_l1_dcw +, papi_l1_ica +, papi_l1_ich +, papi_l1_icm +, papi_l1_icr +, papi_l1_icw +, papi_l1_ldm +, papi_l1_stm +, papi_l1_tca +, papi_l1_tch +, papi_l1_tcm +, papi_l1_tcr +, papi_l1_tcw +, papi_l2_dca +, papi_l2_dch +, papi_l2_dcm +, papi_l2_dcr +, papi_l2_dcw +, papi_l2_ica +, papi_l2_ich +, papi_l2_icm +, papi_l2_icr +, papi_l2_icw +, papi_l2_ldm +, papi_l2_stm +, papi_l2_tca +, papi_l2_tch +, papi_l2_tcm +, papi_l2_tcr +, papi_l2_tcw +, papi_l3_dca +, papi_l3_dch +, papi_l3_dcm +, papi_l3_dcr +, papi_l3_dcw +, papi_l3_ica +, papi_l3_ich +, papi_l3_icm +, papi_l3_icr +, papi_l3_icw +, papi_l3_ldm +, papi_l3_stm +, papi_l3_tca +, papi_l3_tch +, papi_l3_tcm +, papi_l3_tcr +, papi_l3_tcw +, papi_ld_ins +, papi_lst_ins +, papi_lsu_idl +, papi_mem_rcy +, papi_mem_scy +, papi_mem_wcy +, papi_prf_dm +, papi_res_stl +, papi_sr_ins +, papi_stl_ccy +, papi_stl_icy +, papi_syc_ins +, papi_tlb_dm +, papi_tlb_im +, papi_tlb_sd +, papi_tlb_tl + +, Modifier(..) +, papiEnumEvents +, papiEnumFirst +, papiPresetEnumAvail +, papiPresetEnumMsc +, papiPresetEnumIns +, papiPresetEnumIdl +, papiPresetEnumBr +, papiPresetEnumCnd +, papiPresetEnumMem +, papiPresetEnumCach +, papiPresetEnumL1 +, papiPresetEnumL2 +, papiPresetEnumL3 +, papiPresetEnumTlb +, papiPresetEnumFp +, papiNtvEnumUmasks +, papiNtvEnumUmaskCombos +, papiNtvEnumIarr +, papiNtvEnumDarr +, papiNtvEnumOpcm +, papiNtvEnumIear +, papiNtvEnumDear +, papiNtvEnumGroups +, papiEnumAll + +, EventType +, EventInfo(..) + +) where hunk ./System/PAPI/Event.hsc 172 - :: Ptr EventCode -> Modifier -> IO ReturnCode + :: Ptr EventCode -> Modifier -> IO PapiError hunk ./System/PAPI/Event.hsc 180 - :: EventCode -> Ptr EventInfo -> IO ReturnCode + :: EventCode -> Ptr EventInfo -> IO PapiError hunk ./System/PAPI/Event.hsc 188 - :: EventCode -> IO ReturnCode + :: EventCode -> IO PapiError hunk ./System/PAPI/Event.hsc 192 - if ret == papi_enoevnt + if ret == papiErrorEnoevnt hunk ./System/PAPI/Event.hsc 198 - :: EventCode -> CString -> IO ReturnCode + :: EventCode -> CString -> IO PapiError hunk ./System/PAPI/Event.hsc 206 - :: CString -> Ptr EventCode -> IO ReturnCode + :: CString -> Ptr EventCode -> IO PapiError hunk ./System/PAPI/Event.hsc 215 -newtype EventCode = EventCode { unEventCode :: CInt } deriving (Eq,Storable) +newtype EventCode = EventCode { unEventCode :: CInt } + deriving (Eq, Show,Storable) hunk ./System/PAPI/Event.hsc 341 -newtype Modifier = Modifier { unModifier :: CInt } deriving (Eq) +newtype Modifier = Modifier { unModifier :: CInt } deriving (Eq, Show) hunk ./System/PAPI/Event.hsc 344 -, papi_enum_events = PAPI_ENUM_EVENTS // Always enumerate all events -, papi_enum_first = PAPI_ENUM_FIRST // Enumerate first event (preset or native) -, papi_preset_enum_avail = PAPI_PRESET_ENUM_AVAIL // Enumerate events that exist here +, papiEnumEvents = PAPI_ENUM_EVENTS // Always enumerate all events +, papiEnumFirst = PAPI_ENUM_FIRST // Enumerate first event (preset or native) +, papiPresetEnumAvail = PAPI_PRESET_ENUM_AVAIL // Enumerate events that exist here hunk ./System/PAPI/Event.hsc 349 -, papi_preset_enum_msc = PAPI_PRESET_ENUM_MSC // Miscellaneous preset events -, papi_preset_enum_ins = PAPI_PRESET_ENUM_INS // Instruction related preset events -, papi_preset_enum_idl = PAPI_PRESET_ENUM_IDL // Stalled or Idle preset events -, papi_preset_enum_br = PAPI_PRESET_ENUM_BR // Branch related preset events -, papi_preset_enum_cnd = PAPI_PRESET_ENUM_CND // Conditional preset events -, papi_preset_enum_mem = PAPI_PRESET_ENUM_MEM // Memory related preset events -, papi_preset_enum_cach = PAPI_PRESET_ENUM_CACH // Cache related preset events -, papi_preset_enum_l1 = PAPI_PRESET_ENUM_L1 // L1 cache related preset events -, papi_preset_enum_l2 = PAPI_PRESET_ENUM_L2 // L2 cache related preset events -, papi_preset_enum_l3 = PAPI_PRESET_ENUM_L3 // L3 cache related preset events -, papi_preset_enum_tlb = PAPI_PRESET_ENUM_TLB // Translation Lookaside Buffer events -, papi_preset_enum_fp = PAPI_PRESET_ENUM_FP // Floating Point related preset events +, papiPresetEnumMsc = PAPI_PRESET_ENUM_MSC // Miscellaneous preset events +, papiPresetEnumIns = PAPI_PRESET_ENUM_INS // Instruction related preset events +, papiPresetEnumIdl = PAPI_PRESET_ENUM_IDL // Stalled or Idle preset events +, papiPresetEnumBr = PAPI_PRESET_ENUM_BR // Branch related preset events +, papiPresetEnumCnd = PAPI_PRESET_ENUM_CND // Conditional preset events +, papiPresetEnumMem = PAPI_PRESET_ENUM_MEM // Memory related preset events +, papiPresetEnumCach = PAPI_PRESET_ENUM_CACH // Cache related preset events +, papiPresetEnumL1 = PAPI_PRESET_ENUM_L1 // L1 cache related preset events +, papiPresetEnumL2 = PAPI_PRESET_ENUM_L2 // L2 cache related preset events +, papiPresetEnumL3 = PAPI_PRESET_ENUM_L3 // L3 cache related preset events +, papiPresetEnumTlb = PAPI_PRESET_ENUM_TLB // Translation Lookaside Buffer events +, papiPresetEnumFp = PAPI_PRESET_ENUM_FP // Floating Point related preset events hunk ./System/PAPI/Event.hsc 363 -, papi_ntv_enum_umasks = PAPI_NTV_ENUM_UMASKS // all individual bits for given group -, papi_ntv_enum_umask_combos = PAPI_NTV_ENUM_UMASK_COMBOS // all combinations of mask bits for given group -, papi_ntv_enum_iarr = PAPI_NTV_ENUM_IARR // Enumerate events that support IAR (instruction address ranging) -, papi_ntv_enum_darr = PAPI_NTV_ENUM_DARR // Enumerate events that support DAR (data address ranging) -, papi_ntv_enum_opcm = PAPI_NTV_ENUM_OPCM // Enumerate events that support OPC (opcode matching) -, papi_ntv_enum_iear = PAPI_NTV_ENUM_IEAR // Enumerate IEAR (instruction event address register) events -, papi_ntv_enum_dear = PAPI_NTV_ENUM_DEAR // Enumerate DEAR (data event address register) events -, papi_ntv_enum_groups = PAPI_NTV_ENUM_GROUPS // Enumerate groups an event belongs to a la POWER4/5 -, papi_enum_all = PAPI_ENUM_ALL +, papiNtvEnumUmasks = PAPI_NTV_ENUM_UMASKS // all individual bits for given group +, papiNtvEnumUmaskCombos = PAPI_NTV_ENUM_UMASK_COMBOS // all combinations of mask bits for given group +, papiNtvEnumIarr = PAPI_NTV_ENUM_IARR // Enumerate events that support IAR (instruction address ranging) +, papiNtvEnumDarr = PAPI_NTV_ENUM_DARR // Enumerate events that support DAR (data address ranging) +, papiNtvEnumOpcm = PAPI_NTV_ENUM_OPCM // Enumerate events that support OPC (opcode matching) +, papiNtvEnumIear = PAPI_NTV_ENUM_IEAR // Enumerate IEAR (instruction event address register) events +, papiNtvEnumDear = PAPI_NTV_ENUM_DEAR // Enumerate DEAR (data event address register) events +, papiNtvEnumGroups = PAPI_NTV_ENUM_GROUPS // Enumerate groups an event belongs to a la POWER4/5 +, papiEnumAll = PAPI_ENUM_ALL hunk ./System/PAPI/Event.hsc 374 -newtype EventType = EventType { unEventType :: CUInt } deriving (Eq, Show, Storable) +type EventType = CUInt -- TODO: currenly unused by PAPI? hunk ./System/PAPI/Event.hsc 379 -, eventCount :: Integer hunk ./System/PAPI/Event.hsc 384 -, eventCode :: [Integer] -- unsigned -, eventName :: [String] +, eventCodeAndName :: [(Integer, String)] hunk ./System/PAPI/Event.hsc 386 -} +} deriving (Eq, Show) hunk ./System/PAPI/Event.hsc 393 - count <- liftM fromCInt $ #{peek PAPI_event_info_t, count} ptr + count <- liftM fromCUInt $ #{peek PAPI_event_info_t, count} ptr hunk ./System/PAPI/Event.hsc 402 - `ap2` (const $ return count) hunk ./System/PAPI/Event.hsc 407 - `ap2` (const $ return code) - `ap2` (const $ return name) + `ap2` (const $ return $ zip code name) hunk ./System/PAPI/Event.hsc 410 + nameArray = #{ptr PAPI_event_info_t, name} ptr + + poke ptr value = do + let (code, name) = unzip (take #{const PAPI_MAX_INFO_TERMS} + (eventCodeAndName value)) + #{poke PAPI_event_info_t, event_code} ptr $ eventEventCode value + #{poke PAPI_event_info_t, event_type} ptr $ eventEventType value + #{poke PAPI_event_info_t, count} ptr $ + (fromIntegral $ length $ eventCodeAndName value :: CInt) + pokeCString (#{ptr PAPI_event_info_t, symbol} ptr) + (eventSymbol value) #{const PAPI_HUGE_STR_LEN-1} + pokeCString (#{ptr PAPI_event_info_t, short_descr} ptr) + (eventShortDescr value) #{const PAPI_MIN_STR_LEN-1} + pokeCString (#{ptr PAPI_event_info_t, long_descr} ptr) + (eventLongDescr value) #{const PAPI_HUGE_STR_LEN-1} + pokeCString (#{ptr PAPI_event_info_t, derived} ptr) + (eventDerived value) #{const PAPI_MIN_STR_LEN-1} + pokeCString (#{ptr PAPI_event_info_t, postfix} ptr) + (eventLongDescr value) #{const PAPI_MIN_STR_LEN-1} + zipWithM_ (pokeElemOff codeArray) [0..] (map toCUInt code) + zipWithM_ (\i x -> pokeCString + (nameArray `plusPtr` (i * #{const PAPI_2MAX_STR_LEN})) + x #{const PAPI_2MAX_STR_LEN-1}) + [0..] name + pokeCString (#{ptr PAPI_event_info_t, note} ptr) + (eventNote value) #{const PAPI_HUGE_STR_LEN-1} + where codeArray = #{ptr PAPI_event_info_t, code} ptr hunk ./System/PAPI/EventSet.hsc 15 -module System.PAPI.EventSet where +module System.PAPI.EventSet ( + EventSet() +, createEventset +, cleanupEventset +, numEvents +, listEvents +, addEvent +, addEvents +, removeEvent +, removeEvents +) where hunk ./System/PAPI/EventSet.hsc 27 -import Control.Monad +import Control.Monad(liftM) hunk ./System/PAPI/EventSet.hsc 35 +#include "papiStdEventDefs.h" hunk ./System/PAPI/EventSet.hsc 37 -newtype EventSet = EventSet { unEventSet :: CInt } deriving (Eq, Show, Storable) +newtype EventSet = EventSet CInt deriving (Eq, Show, Storable) hunk ./System/PAPI/EventSet.hsc 40 - :: Ptr EventSet -> IO () + :: Ptr CInt -> IO () hunk ./System/PAPI/EventSet.hsc 46 - peek x + liftM EventSet $ peek x -- Use EventSet explicitly to avoid warning hunk ./System/PAPI/EventSet.hsc 49 - :: EventSet -> IO ReturnCode + :: EventSet -> IO PapiError hunk ./System/PAPI/EventSet.hsc 56 - :: EventSet -> IO ReturnCode + :: EventSet -> IO PapiError hunk ./System/PAPI/EventSet.hsc 63 - :: EventSet -> Ptr EventCode -> Ptr CInt -> IO ReturnCode + :: EventSet -> Ptr EventCode -> Ptr CInt -> IO PapiError hunk ./System/PAPI/EventSet.hsc 72 - :: EventSet -> EventCode -> IO ReturnCode + :: EventSet -> EventCode -> IO PapiError hunk ./System/PAPI/EventSet.hsc 79 - :: EventSet -> Ptr EventCode -> CInt -> IO ReturnCode + :: EventSet -> Ptr EventCode -> CInt -> IO PapiError hunk ./System/PAPI/EventSet.hsc 89 - :: EventSet -> EventCode -> IO ReturnCode + :: EventSet -> EventCode -> IO PapiError hunk ./System/PAPI/EventSet.hsc 96 - :: EventSet -> Ptr EventCode -> CInt -> IO ReturnCode + :: EventSet -> Ptr EventCode -> CInt -> IO PapiError hunk ./System/PAPI/HighLevel.hsc 15 -module System.PAPI.HighLevel where +module System.PAPI.HighLevel ( + numCounters +, flips, flops, ipc +, startCounters +, stopCounters +, readCounters +, accumCounters +, withCounters +) where hunk ./System/PAPI/HighLevel.hsc 41 - = Ptr Float -> Ptr Float -> Ptr CLLong -> Ptr Float -> IO ReturnCode + = Ptr Float -> Ptr Float -> Ptr CLLong -> Ptr Float -> IO PapiError hunk ./System/PAPI/HighLevel.hsc 64 -type CounterCall a = Ptr a -> CInt -> IO ReturnCode +type CounterCall a = Ptr a -> CInt -> IO PapiError hunk ./System/PAPI/Init.hsc 15 -module System.PAPI.Init where +module System.PAPI.Init( + Version(..) +, papiVersion +, papiVerCurrent +, Initialized(..) +, isInitialized +, libraryInit +, shutdown +) where hunk ./System/PAPI/Init.hsc 32 +-- Version related info hunk ./System/PAPI/Init.hsc 38 -data Initialized = - PAPI_NOT_INITED | PAPI_LOW_LEVEL_INITED | PAPI_HIGH_LEVEL_INITED +-- Initialization related stuff +data Initialized = PapiNotInited | PapiLowLevelInited | PapiHighLevelInited hunk ./System/PAPI/Init.hsc 41 + hunk ./System/PAPI/Init.hsc 47 - #{const PAPI_NOT_INITED} -> PAPI_NOT_INITED - #{const PAPI_LOW_LEVEL_INITED} -> PAPI_LOW_LEVEL_INITED - #{const PAPI_HIGH_LEVEL_INITED} -> PAPI_HIGH_LEVEL_INITED + #{const PAPI_NOT_INITED} -> PapiNotInited + #{const PAPI_LOW_LEVEL_INITED} -> PapiLowLevelInited + #{const PAPI_HIGH_LEVEL_INITED} -> PapiHighLevelInited hunk ./System/PAPI/Init.hsc 53 -foreign import ccall "PAPI_library_init" papi_library_init :: CInt -> IO ReturnCode +foreign import ccall "PAPI_library_init" papi_library_init :: CInt -> IO PapiError hunk ./System/PAPI/Options.hsc 15 -module System.PAPI.Options where +module System.PAPI.Options ( + getExecutableInfo +, getHardwareInfo +, getSubstrateInfo +, getSharedLibInfo +, getDmemInfo +, getMultiplex +, setMultiplex +, setDebug +, setDomain +, setGranularity +, numHwctrs + +, getOptAttach +, getOptDetach +, getOptDefMpxNs +, getOptDefItimerNs +, getOptItimer +, getOptMultiplex +, getOptPreload +, getOptDebug +, getOptClockrate +, getOptMaxCpus +, getOptMaxHwCtrs +, getOptDefDomain +, getOptDefGranularity +, getOptGranularity +, getOptShlibInfo +, getOptExeInfo +, getOptHwInfo +, getOptSubstrateInfo +, getDomainOption +, getOptLibVersion + +, setOptDetach +, setOptAttach +, setOptDefMpxNs +, setOptDefItimerNs +, setOptDefItimer +, setOptMultiplex +, setOptDebug +, setOptDefDomain +, setOptDomain +, setOptDefGranularity +, setOptGranularity +, setOptDataAddress +, setOptInstrAddress + +, DebugLevel() +, debugQuiet +, debugVerbEcont +, debugVerbEstop + +, Domain() +, domainUser +, domainKernel +, domainOther +, domainSupervisor +, domainAll +, domainMin +, domainMax + +, Granularity() +, granularityThead +, granularityMin +, granularityProc +, granularityProcG +, granularitySys +, granularitySysCpu +, granularityMax + +, ThreadId(..) + +, ExeInfo(..) +, AddressMap(..) +, HwInfo(..) +, Vendor(..) +, MhInfo(..) +, MhLevel(..) +, MhTLBInfo(..) +, MhCacheInfo(..) +, MhType(..) +, MhCacheType(..) +, MhWritePolicy(..) +, MhReplacementPolicy(..) +, SubstrateInfo(..) +, ShlibInfo(..) +, DmemInfo(..) +, ItimerOption(..) +, ItimerFlags(..) +, PreloadInfo(..) +, DebugHandler +, DebugOption(..) +, MultiplexOption(..) +, MultiplexFlags(..) + +) where hunk ./System/PAPI/Options.hsc 157 - :: Ptr DmemInfo -> IO ReturnCode + :: Ptr DmemInfo -> IO PapiError hunk ./System/PAPI/Options.hsc 165 - :: EventSet -> IO ReturnCode + :: EventSet -> IO PapiError hunk ./System/PAPI/Options.hsc 172 - :: EventSet -> IO ReturnCode + :: EventSet -> IO PapiError hunk ./System/PAPI/Options.hsc 178 - :: DebugLevel -> IO ReturnCode + :: DebugLevel -> IO PapiError hunk ./System/PAPI/Options.hsc 184 - :: Domain -> IO ReturnCode + :: Domain -> IO PapiError hunk ./System/PAPI/Options.hsc 190 - :: Granularity -> IO ReturnCode + :: Granularity -> IO PapiError hunk ./System/PAPI/Options.hsc 196 -foreign import ccall "PAPI_num_hwctrs" papi_num_hwctrs :: IO ReturnCode +foreign import ccall "PAPI_num_hwctrs" papi_num_hwctrs :: IO PapiError hunk ./System/PAPI/Options.hsc 205 - CInt -> Ptr Option -> IO ReturnCode + CInt -> Ptr Option -> IO PapiError hunk ./System/PAPI/Options.hsc 325 - CInt -> Ptr Option -> IO ReturnCode + CInt -> Ptr Option -> IO PapiError hunk ./System/PAPI/Options.hsc 477 -newtype DebugLevel = DebugLevel { unDebugLevel :: CInt } - deriving (Eq, Show, Storable) +newtype DebugLevel = DebugLevel CInt deriving (Eq, Show, Storable) hunk ./System/PAPI/Options.hsc 484 -newtype Domain = Domain { unDomain :: CInt } - deriving (Eq, Show, Storable) +newtype Domain = Domain CInt deriving (Eq, Show, Storable) hunk ./System/PAPI/Options.hsc 495 -newtype Granularity = Granularity { unGranularity :: CInt } - deriving (Eq, Show, Storable) +newtype Granularity = Granularity CInt deriving (Eq, Show, Storable) hunk ./System/PAPI/Options.hsc 585 - } + } deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 676 -newtype MhInfo = MhInfo [MhLevel] +newtype MhInfo = MhInfo [MhLevel] deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 699 - } + } deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 733 - } + } deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 759 - } + } deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 788 - } + } deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 795 -} +} deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 800 + deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 806 + deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 938 - (substrateVersion value) #{const PAPI_MAX_STR_LEN-1} + (substrateVersion value) #{const PAPI_MIN_STR_LEN-1} hunk ./System/PAPI/Options.hsc 940 - (substrateSupportVersion value) #{const PAPI_MAX_STR_LEN-1} + (substrateSupportVersion value) #{const PAPI_MIN_STR_LEN-1} hunk ./System/PAPI/Options.hsc 942 - (substrateKernelVersion value) #{const PAPI_MAX_STR_LEN-1} + (substrateKernelVersion value) #{const PAPI_MIN_STR_LEN-1} hunk ./System/PAPI/Options.hsc 1017 -newtype ShlibInfo = ShlibInfo [AddressMap] - +newtype ShlibInfo = ShlibInfo [AddressMap] deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 1086 -} +} deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 1140 -} +} deriving (Eq, Show) hunk ./System/PAPI/Options.hsc 1160 -} +} deriving (Eq, Show) hunk ./System/PAPI/Run.hsc 15 -module System.PAPI.Run where +module System.PAPI.Run ( + EventState(..) +, state +, start +, stop +, read +, accum +, readTs +, write +, reset +) where + +import Prelude hiding (read) hunk ./System/PAPI/Run.hsc 49 -foreign import ccall "PAPI_state" papi_state - :: EventSet -> Ptr EventState -> IO ReturnCode -state :: EventSet -> IO EventState -state eventSet = - alloca $ \ptr -> - papi_state eventSet ptr >>= papiThrow "Error in state: " >> peek ptr - hunk ./System/PAPI/Run.hsc 76 -foreign import ccall "PAPI_start" papi_start :: EventSet -> IO ReturnCode +foreign import ccall "PAPI_state" papi_state + :: EventSet -> Ptr EventState -> IO PapiError +state :: EventSet -> IO EventState +state eventSet = + alloca $ \ptr -> + papi_state eventSet ptr >>= papiThrow "Error in state: " >> peek ptr + +foreign import ccall "PAPI_start" papi_start :: EventSet -> IO PapiError hunk ./System/PAPI/Run.hsc 89 - :: EventSet -> Ptr CLLong -> IO ReturnCode + :: EventSet -> Ptr CLLong -> IO PapiError hunk ./System/PAPI/Run.hsc 97 - :: EventSet -> Ptr CLLong -> IO ReturnCode + :: EventSet -> Ptr CLLong -> IO PapiError hunk ./System/PAPI/Run.hsc 105 - :: EventSet -> Ptr CLLong -> IO ReturnCode + :: EventSet -> Ptr CLLong -> IO PapiError hunk ./System/PAPI/Run.hsc 113 - :: EventSet -> Ptr CLLong -> Ptr CLLong -> IO ReturnCode + :: EventSet -> Ptr CLLong -> Ptr CLLong -> IO PapiError hunk ./System/PAPI/Run.hsc 123 - :: EventSet -> Ptr CLLong -> IO ReturnCode + :: EventSet -> Ptr CLLong -> IO PapiError hunk ./System/PAPI/Run.hsc 129 -foreign import ccall "PAPI_reset" papi_reset :: EventSet -> IO ReturnCode +foreign import ccall "PAPI_reset" papi_reset :: EventSet -> IO PapiError hunk ./System/PAPI/Timer.hsc 15 -module System.PAPI.Timer where +module System.PAPI.Timer ( + getRealCyc +, getRealNsec +, getRealUsec +, getVirtCyc +, getVirtNsec +, getVirtUsec +) where hunk ./System/PAPI/Util.hsc 12 --- Binding for the PAPI library: common functions (may be integrated) +-- Binding for the PAPI library: private helper functions. +-- Users should not import hunk ./System/PAPI/Util.hsc 21 +data Void +type Addr = Ptr Void -- Equivalent of a void* + hunk ./System/PAPI/Util.hsc 31 +pokeCString :: CString -> String -> Int -> IO () +pokeCString dst value maxLen = + withCStringLen (take maxLen value) $ uncurry (copyArray dst) + +nullThrow :: String -> Ptr a -> IO (Ptr a) +nullThrow str ptr = if ptr == nullPtr then error str else return ptr + +-- Casting functions + +toMask :: (Num a) => Bool -> a -> a +toMask bool mask = if bool then mask else 0 + hunk ./System/PAPI/Util.hsc 49 -fromCInt :: CInt -> Integer -fromCInt x = toInteger x - hunk ./System/PAPI/Util.hsc 52 -fromCUInt :: CUInt -> Integer -fromCUInt x = toInteger x +fromCInt :: CInt -> Integer +fromCInt x = toInteger x hunk ./System/PAPI/Util.hsc 58 +fromCUInt :: CUInt -> Integer +fromCUInt x = toInteger x + hunk ./System/PAPI/Util.hsc 67 -toMask :: (Num a) => Bool -> a -> a -toMask bool mask = if bool then mask else 0 - -pokeCString :: CString -> String -> Int -> IO () -pokeCString dst value maxLen = - withCStringLen (take maxLen value) $ uncurry (copyArray dst) - --- NOTE: Keep this type hidden so no one can declare a Storable instance on it -data Void -type Addr = Ptr Void - hunk ./README 10 -Please report any bugs to . - -Documentation -============= -Documentation is minimal at the moment. In the mean time, -the original PAPI library documentation may prove useful. - -Usage -===== -The basic use of this library is demonstrated by the following example. +The source repository is at: + http://code.haskell.org/hpapi/ hunk ./README 13 - main = do - [l1,tlb,fp] <- withCounters [papi_l1_dcm, papi_tlb_dm, papi_fp_ins] - ioOperationToMeasure - printLn (l1, tlb, fp) +Please report any bugs to . hunk ./README 17 -Of course this package requires the PAPI libray and kernel modules +This package requires the PAPI C library and kernel modules hunk ./README 29 -Comparison with GHC's built-in PAPI -=================================== -GHC supports a build-in version of PAPI -(see http://hackage.haskell.org/trac/ghc/wiki/PAPI). -This system is different in a few ways. - -First, hpapi allows you to measure specific parts of a program -while GHCI's PAPI only does whole program measurement - -Second, since hpapi is a library you can have fine grained -and sophisticated control over how things are measured. -On the otherhand GHC's PAPI as part of the RTS gives you less -control, but on the plus side doesn't require any modification -to the program. +Usage +===== +The basic use of this library is demonstrated by the following example. hunk ./README 33 -Finally, GHC's PAPI splits appart the counts that come from -the garbage collector from those that come from the mutator, -while hpapi combines them. This is a limitation of hpapi -we hope to correct some time in the future. + main = do + [l1,tlb,fp] <- withCounters [papi_l1_dcm, papi_tlb_dm, papi_fp_ins] + ioOperationToMeasure + print (l1, tlb, fp) hunk ./README 38 -It remains to be seen whether it would be worth while -to unify these two systems. +Documentation +============= +Documentation is minimal at the moment. In the mean time, +the original PAPI library documentation may prove useful. hunk ./README 64 +Comparison with GHC's built-in PAPI +=================================== +GHC supports a built-in version of PAPI +(see http://hackage.haskell.org/trac/ghc/wiki/PAPI). +This system is different in a few ways. + +First, hpapi allows you to measure specific parts of a program +while GHCI's PAPI only does whole program measurement + +Second, since hpapi is a library you can have fine grained +and sophisticated control over how things are measured. +On the other hand GHC's PAPI as part of the RTS gives you less +control, but on the plus side doesn't require any modification +to the program. + +Finally, GHC's PAPI splits apart the counts that come from +the garbage collector from those that come from the mutator, +while hpapi combines them. This is a limitation of hpapi +we hope to correct some time in the future. + +It remains to be seen whether it would be worth while +to unify these two systems. + hunk ./System/PAPI.hs 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Error.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Event.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/EventSet.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/HighLevel.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Init.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Options.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Run.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Timer.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./System/PAPI/Util.hsc 7 --- Maintainer: Michael D. Adams +-- Maintainer: Michael D. Adams hunk ./hpapi.cabal 8 -author: Michael D. Adams -maintainer: Michael D. Adams +author: Michael D. Adams +maintainer: Michael D. Adams hunk ./hpapi.cabal 19 -extra-source-files: template-bit-hsc.h +extra-source-files: README + template-bit-hsc.h hunk ./hpapi.cabal 35 - extensions: ForeignFunctionInterface GeneralizedNewtypeDeriving EmptyDataDecls + extensions: ForeignFunctionInterface + GeneralizedNewtypeDeriving + EmptyDataDecls hunk ./README 1 -This is version 0.0.1 of hpapi. It provides a Haskell binding +This is version 0.0.1.0 of hpapi. It provides a Haskell binding hunk ./README 64 + - The PAPI C library is inconsistent on whether EventCode + is a signed int or an unsigned int. + This causes minor issues to be fixed. + hunk ./System/PAPI/EventSet.hsc 80 -addEvents :: EventSet -> [EventCode] -> IO Int +addEvents :: EventSet -> [EventCode] -> IO (Maybe Int) hunk ./System/PAPI/EventSet.hsc 82 - allocaArray len $ \events -> + withArrayLen eventcodes $ \len events -> hunk ./System/PAPI/EventSet.hsc 85 - >>= return . fromIntegral - where len = length eventcodes + >>= \x -> if x == 0 + then return Nothing + else return $ Just $ fromIntegral x hunk ./System/PAPI/EventSet.hsc 98 -removeEvents :: EventSet -> [EventCode] -> IO Int +removeEvents :: EventSet -> [EventCode] -> IO (Maybe Int) hunk ./System/PAPI/EventSet.hsc 100 - allocaArray len $ \events -> + withArrayLen eventcodes $ \len events -> hunk ./System/PAPI/EventSet.hsc 103 - >>= return . fromIntegral - where len = length eventcodes + >>= \x -> if x == 0 + then return Nothing + else return $ Just $ fromIntegral x hunk ./hpapi.cabal 2 -version: 0.0.0.20081111 +version: 0.0.1.0