intel-powermon (empty) → 0
raw patch · 2 files changed
+47/−0 lines, 2 filesdep +basedep +posix-timerdep +streaming
Dependencies added: base, posix-timer, streaming, unix
Files
- intel-powermon.cabal +24/−0
- intel-powermon.hs +23/−0
+ intel-powermon.cabal view
@@ -0,0 +1,24 @@+cabal-version: 2.2+name: intel-powermon+version: 0+synopsis: Poll modern Intel/AMD CPU power consumption on Linux via RAPL.+license: AGPL-3.0-only+author: Sergey Alirzaev+maintainer: zl29ah@gmail.com+build-type: Simple++Source-repository head+ type: git+ location: https://github.com/l29ah/intel-powermon.git++common stuff+ ghc-options: -W -fno-warn-tabs -O2 -Werror=missing-fields -threaded -rtsopts "-with-rtsopts -N -qg"+ build-depends: base >= 4.9 && < 5,+ streaming ^>= 0.2.3.0,+ unix ^>= 2.7.2.2,+ posix-timer ^>= 0.3.0.1,+ default-language: Haskell2010++executable intel-powermon+ import: stuff+ main-is: intel-powermon.hs
+ intel-powermon.hs view
@@ -0,0 +1,23 @@+import Control.Concurrent+import Foreign.C.Types+import qualified Streaming.Prelude as S+import System.IO+import System.Posix.Clock+import System.Posix.Signals+import System.Posix.Timer++toJoules :: String -> Double+toJoules = (/ 1e6) . (read :: String -> Double)++every :: CTime -> IO () -> IO ()+every seconds action = do+ timer <- createTimer monotonicClock $ Just (realTimeAlarm, 0)+ installHandler realTimeAlarm (Catch action) Nothing+ configureTimer timer False (mkTimeSpec seconds 0) (mkTimeSpec seconds 0)+ pure ()++main = do+ hSetBuffering stdout LineBuffering+ ujstrs <- newChan+ every 1 $ readFile "/sys/class/powercap/intel-rapl:0/energy_uj" >>= writeChan ujstrs+ S.print $ S.drop 2 $ S.scan (\(prev, _) new -> (new, new - prev)) (0, 0) snd $ S.map toJoules $ S.repeatM $ readChan ujstrs