From cb758277b3fa2d74551c45340b8ff0539713078c Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 18 Mar 2025 22:32:16 +0100 Subject: Arith statistics collection from C --- src/Data/Array/Mixed/Internal/Arith.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Data') diff --git a/src/Data/Array/Mixed/Internal/Arith.hs b/src/Data/Array/Mixed/Internal/Arith.hs index 9c560d6..27ebb64 100644 --- a/src/Data/Array/Mixed/Internal/Arith.hs +++ b/src/Data/Array/Mixed/Internal/Arith.hs @@ -27,6 +27,7 @@ import Foreign.Storable (Storable(sizeOf), peek, poke) import GHC.TypeLits import GHC.TypeNats qualified as TypeNats import Language.Haskell.TH +import System.IO (hFlush, stdout) import System.IO.Unsafe import Data.Array.Mixed.Internal.Arith.Foreign @@ -603,6 +604,19 @@ $(fmap concat . forM typesList $ \arithtype -> do ,do body <- [| \sn -> vectorDotprodInnerOp sn id id $mul_op (scaleFromSVStrided $c_scale_op) $c_red_op $c_op |] return $ FunD name [Clause [] (NormalB body) []]]) +foreign import ccall unsafe "oxarrays_stats_enable" c_stats_enable :: Int32 -> IO () +foreign import ccall unsafe "oxarrays_stats_print_all" c_stats_print_all :: IO () + +statisticsEnable :: Bool -> IO () +statisticsEnable b = c_stats_enable (if b then 1 else 0) + +-- | Consumes the log: one particular event will only ever be printed once, +-- even if statisticsPrintAll is called multiple times. +statisticsPrintAll :: IO () +statisticsPrintAll = do + hFlush stdout -- lower the chance of overlapping output + c_stats_print_all + -- This branch is ostensibly a runtime branch, but will (hopefully) be -- constant-folded away by GHC. intWidBranch1 :: forall i n. (FiniteBits i, Storable i) -- cgit v1.2.3-70-g09d2