Include the number of times a label is entered in the ProfileData

Summary:
We have the number of times memoization hit under a label, but not the number
of times the label itself is entered. Let us collect this stat as well, which
can help us find hot functions and compute memoization hit rate.

Reviewed By: karen

Differential Revision: D19377120

fbshipit-source-id: 33046301badca5c32df20b06c77c863636562612
This commit is contained in:
Zejun Wu 2020-01-13 16:34:22 -08:00 committed by Facebook Github Bot
parent fd69fa08f6
commit 65b9ab8595
3 changed files with 15 additions and 5 deletions

View File

@ -57,6 +57,7 @@ module Haxl.Core (
, ProfileData(..)
, emptyProfileData
, AllocCount
, LabelHitCount
, MemoHitCount
-- ** Tracing flags

View File

@ -89,10 +89,15 @@ modifyProfileData env label allocs =
newEntry =
emptyProfileData
{ profileAllocs = allocs
, profileDeps = HashSet.singleton caller }
, profileDeps = HashSet.singleton caller
, profileLabelHits = 1
}
updEntry _ old =
old { profileAllocs = profileAllocs old + allocs
, profileDeps = HashSet.insert caller (profileDeps old) }
old
{ profileAllocs = profileAllocs old + allocs
, profileDeps = HashSet.insert caller (profileDeps old)
, profileLabelHits = profileLabelHits old + 1
}
-- subtract allocs from caller, so they are not double counted
-- we don't know the caller's caller, but it will get set on
-- the way back out, so an empty hashset is fine for now

View File

@ -34,6 +34,7 @@ module Haxl.Core.Stats
, ProfileData(..)
, emptyProfileData
, AllocCount
, LabelHitCount
, MemoHitCount
-- * Allocation
@ -161,6 +162,7 @@ numFetches (Stats rs) = sum [ fetchBatchSize | FetchStats{..} <- rs ]
type ProfileLabel = Text
type AllocCount = Int64
type LabelHitCount = Int64
type MemoHitCount = Int64
newtype Profile = Profile
@ -178,10 +180,12 @@ data ProfileData = ProfileData
-- ^ labels that this label depends on
, profileFetches :: HashMap Text Int
-- ^ map from datasource name => fetch count
, profileLabelHits :: {-# UNPACK #-} !LabelHitCount
-- ^ number of hits at this label
, profileMemoHits :: {-# UNPACK #-} !MemoHitCount
-- ^ number of hits to memoized computation at this label
-- ^ number of hits to memoized computation at this label
}
deriving Show
emptyProfileData :: ProfileData
emptyProfileData = ProfileData 0 HashSet.empty HashMap.empty 0
emptyProfileData = ProfileData 0 HashSet.empty HashMap.empty 0 0