mirror of
https://github.com/facebook/Haxl.git
synced 2024-12-24 17:23:03 +03:00
9737719b7f
Summary: Does three things: 1. Fix order of arguments to `updEntry` to update the existing entry, instead of replacing it with 2*new. 2. Subtract nested allocations from parent. 3. Call setAllocationCounter after recording profiling data, so profiling overhead doesn't count towards the parent or the allocation limit. Reviewed By: simonmar Differential Revision: D3235413 fbshipit-source-id: a9f287399516fc90600b15a1524592f9c3b0674b
43 lines
1.1 KiB
Haskell
43 lines
1.1 KiB
Haskell
{-# LANGUAGE NoImplicitPrelude #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
module ProfileTests where
|
|
|
|
import Haxl.Prelude
|
|
import Data.List
|
|
|
|
import Haxl.Core
|
|
|
|
import Test.HUnit
|
|
|
|
import Data.IORef
|
|
import qualified Data.HashMap.Strict as HashMap
|
|
import qualified Data.HashSet as HashSet
|
|
|
|
import TestUtils
|
|
|
|
mkProfilingEnv = do
|
|
env <- makeTestEnv
|
|
return env { flags = (flags env) { report = 4 } }
|
|
|
|
collectsdata :: Assertion
|
|
collectsdata = do
|
|
env <- mkProfilingEnv
|
|
_x <- runHaxl env $
|
|
withLabel "bar" $
|
|
withLabel "foo" $
|
|
if length (intersect ["a"::Text, "b"] ["c"]) > 1
|
|
then return 5
|
|
else return (4::Int)
|
|
profData <- readIORef (profRef env)
|
|
assertEqual "has data" 3 $ HashMap.size profData
|
|
assertEqual "foo allocates" (Just 4152) $
|
|
profileAllocs <$> HashMap.lookup "foo" profData
|
|
assertEqual "bar does not allocate" (Just 0) $
|
|
profileAllocs <$> HashMap.lookup "bar" profData
|
|
assertEqual "foo's parent" (Just ["bar"]) $
|
|
HashSet.toList . profileDeps <$> HashMap.lookup "foo" profData
|
|
|
|
tests = TestList
|
|
[ TestLabel "collectsdata" $ TestCase collectsdata
|
|
]
|