mirror of
https://github.com/facebook/Haxl.git
synced 2024-12-23 08:43:16 +03:00
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:
parent
922717e736
commit
43f95ee605
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user