Add memoHits to sigma profiling framework.

Summary: Integrate counts of memoized computation access into the profiling framework. Every call to `cachedComputation` logs one hit, including the first one.

Reviewed By: simonmar

Differential Revision: D3430491

fbshipit-source-id: a799c0e603c7bc94813da9801d7f4931a011131d
This commit is contained in:
P. C. Shyamshankar 2016-06-15 03:29:48 -07:00 committed by Facebook Github Bot 6
parent 922717e736
commit 43f95ee605
2 changed files with 13 additions and 1 deletions

View File

@ -379,6 +379,12 @@ modifyProfileData env label allocs =
updCaller _ old =
old { profileAllocs = profileAllocs old - allocs }
incrementMemoHitCounterFor :: ProfileLabel -> Profile -> Profile
incrementMemoHitCounterFor lbl p =
p { profile = HashMap.adjust incrementMemoHitCounter lbl (profile p) }
incrementMemoHitCounter :: ProfileData -> ProfileData
incrementMemoHitCounter pd = pd { profileMemoHits = succ (profileMemoHits pd) }
-- -----------------------------------------------------------------------------
-- Exceptions
@ -919,6 +925,8 @@ cachedComputation
cachedComputation req haxl = GenHaxl $ \env ref -> do
cache <- readIORef (memoRef env)
ifProfiling (flags env) $
modifyIORef' (profRef env) (incrementMemoHitCounterFor (profLabel env))
case DataCache.lookup req cache of
Nothing -> do
memovar <- newIORef (MemoInProgress ref haxl)

View File

@ -49,6 +49,7 @@ module Haxl.Core.Types (
ProfileData(..),
emptyProfileData,
AllocCount,
MemoHitCount,
-- * Data fetching
DataSource(..),
@ -223,6 +224,7 @@ numFetches (Stats rs) = sum (map fetchesInRound rs)
type ProfileLabel = Text
type AllocCount = Int64
type MemoHitCount = Int64
data Profile = Profile
{ profileRound :: {-# UNPACK #-} !Round
@ -243,11 +245,13 @@ data ProfileData = ProfileData
-- ^ labels that this label depends on
, profileFetches :: Map Round (HashMap Text Int)
-- ^ map from round to {datasource name => fetch count}
, profileMemoHits :: {-# UNPACK #-} !MemoHitCount
-- ^ number of hits to memoized computation at this label
}
deriving Show
emptyProfileData :: ProfileData
emptyProfileData = ProfileData 0 HashSet.empty Map.empty
emptyProfileData = ProfileData 0 HashSet.empty Map.empty 0
-- ---------------------------------------------------------------------------
-- DataCache