mirror of
https://github.com/facebook/Haxl.git
synced 2024-12-23 16:53:02 +03:00
b5a305b5c1
Summary: This collects the highest round in which a label adds a fetch, as well as number of fetches per label per datasource. It reports these, along with aggregated values with scuba sample of profiling data. Aggregation for number of rounds is the maximum round of label or any of label's children. Aggregation for number of fetches is sum. Reviewed By: simonmar Differential Revision: D3316018 fbshipit-source-id: 152690c7b8811d22f566437675c943f755029528
45 lines
1.2 KiB
Haskell
45 lines
1.2 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 <- profile <$> readIORef (profRef env)
|
|
assertEqual "has data" 3 $ HashMap.size profData
|
|
assertBool "foo allocates" $
|
|
case profileAllocs <$> HashMap.lookup "foo" profData of
|
|
Just x -> x > 0
|
|
Nothing -> False
|
|
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
|
|
]
|