packages feed

tasty-papi 0.1.0.1 → 0.1.1.0

raw patch · 3 files changed

+34/−12 lines, 3 files

Files

Changelog.md view
@@ -0,0 +1,10 @@+* Changes in 0.1.1.0++  - Human readable error messages not just bare error codes++  - Fixed header in CSV output+++* Version 0.1++  Initial release
Test/Tasty/PAPI.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE ForeignFunctionInterface   #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE LambdaCase                 #-}+{-# LANGUAGE MultiWayIf                 #-} {-# LANGUAGE TypeApplications           #-} {- | Module:      Test.Tasty.PAPI@@ -22,7 +23,7 @@ === How to use  Library uses standard approach for benchmarks. So example benchmarks-looks similar to one using @criterion@, @gauge@ or @test-bench@:+looks similar to one using @criterion@, @gauge@ or @tasty-bench@:  > module Main where > import Test.Tasty.PAPI@@ -248,11 +249,18 @@ -- foreign import capi unsafe "papi.h PAPI_reset" --   papi_reset :: CInt -> IO CInt +foreign import capi unsafe "papi.h PAPI_strerror"+  papi_strerror :: CInt -> IO CString+ -- Call PAPI function and return error code-call :: IO CInt -> IO ()-call f = f >>= \case+call :: String -> IO CInt -> IO ()+call msg f = f >>= \case   n | n == papi_OK -> pure ()-    | otherwise    -> error $ "PAPI call failed: " ++ show n+    | otherwise    -> do+        c_str <- papi_strerror n+        str   <- if | c_str == nullPtr -> pure "UNKNOWN ERROR"+                    | otherwise        -> peekCString c_str+        error $ printf "PAPI: %s: %s [%s]" msg str (show n)  -- Create event set for use with PAPI withPapiEventSet :: (EventSet -> IO a) -> IO a@@ -264,13 +272,13 @@   where     ini = alloca $ \p_evt -> do       poke p_evt (EventSet papi_NULL)-      call $ papi_create_eventset p_evt+      call "Failed to create eventset" $ papi_create_eventset p_evt       peek p_evt     fini evt = do-      call $ papi_cleanup_eventset evt+      call "Failed to cleanup eventset" $ papi_cleanup_eventset evt       alloca $ \p_evt -> do         poke p_evt evt-        call $ papi_destroy_eventset p_evt+        call "Failed to destroy eventset" $ papi_destroy_eventset p_evt  -- | Supported hardware counters -- @@ -541,7 +549,8 @@   run opts (Benchmarkable io) _     | 1 == n_threads = do         withPapiEventSet $ \evt -> do-          forM_ counters $ call . papi_add_event evt . toCounter+          forM_ counters $ \c -> do+            call ("Failed to add counter " ++ show c) $ papi_add_event evt $ toCounter c           allocaArray (length counters) $ \vals -> do             -- Evaluate benchmark once in order to ensure that all             -- parameters are evaluated. Consider benchmarks@@ -559,9 +568,9 @@             performMajorGC             n1 <- getAllocationCounter             -- Perform measurement-            call $ papi_start evt+            call "Failed to start measurements" $ papi_start evt             io-            call $ papi_stop evt vals+            call "Failed to stop measurements" $ papi_stop evt vals             n2 <- getAllocationCounter             let n_alloc = fromIntegral $ n1-n2             -- Read data@@ -683,7 +692,7 @@                         ++ "' corresponds to two or more benchmarks. Please disambiguate them."       withFile path WriteMode $ \h -> do         hSetBuffering h LineBuffering-        hPutStrLn h $ intercalate "," $ "ALLOC" : (show <$> counters)+        hPutStrLn h $ intercalate "," $ "benchmark" : "ALLOC" : (show <$> counters)         csvOutput h $ IM.intersectionWith (,) namesMap smap       pure $ \_ -> isSuccessful smap 
tasty-papi.cabal view
@@ -1,5 +1,5 @@ name:          tasty-papi-version:       0.1.0.1+version:       0.1.1.0 cabal-version: 1.18 license:       BSD3 license-file:  LICENSE@@ -38,6 +38,9 @@                   , stm   extra-libraries: papi   Exposed-modules: Test.Tasty.PAPI++  if(os(darwin) || os(windows))+    buildable: False  test-suite tasty-papi-run   default-language: Haskell2010