Skip to content

Commit c3e3728

Browse files
Warn when productivity is low (#2005)
* Warn when productivity is low * Stylish * Use logger * Lint * Add Kore.Log.WarnIfLowProductivity * Refactoring: factor out calculations for clarity Co-authored-by: ana-pantilie <ana.pantilie95@gmail.com>
1 parent f5589a0 commit c3e3728

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

kore/app/exec/Main.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ import Kore.Log
127127
import Kore.Log.ErrorException
128128
( errorException
129129
)
130+
import Kore.Log.WarnIfLowProductivity
131+
( warnIfLowProductivity
132+
)
130133
import qualified Kore.ModelChecker.Bounded as Bounded
131134
( CheckResult (..)
132135
)
@@ -573,7 +576,7 @@ mainWithOptions execOptions = do
573576
exitCode <-
574577
withBugReport Main.exeName bugReport $ \tmpDir -> do
575578
writeOptionsAndKoreFiles tmpDir execOptions
576-
go
579+
go <* warnIfLowProductivity
577580
& handle handleWithConfiguration
578581
& handle handleSomeException
579582
& runKoreLog tmpDir koreLogOptions

kore/app/repl/Main.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ import Kore.Log
5656
import Kore.Log.KoreLogOptions
5757
( parseKoreLogOptions
5858
)
59+
import Kore.Log.WarnIfLowProductivity
60+
( warnIfLowProductivity
61+
)
5962
import Kore.Repl.Data
6063
import Kore.Step.SMT.Lemma
6164
import Kore.Syntax.Module
@@ -271,6 +274,7 @@ mainWithOptions
271274
mainModuleName
272275
koreLogOptions
273276

277+
warnIfLowProductivity
274278
pure ExitSuccess
275279
exitWith exitCode
276280
where

kore/src/Kore/Log/Registry.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ import Kore.Log.InfoReachability
9595
import Kore.Log.WarnFunctionWithoutEvaluators
9696
( WarnFunctionWithoutEvaluators
9797
)
98+
import Kore.Log.WarnIfLowProductivity
99+
( WarnIfLowProductivity
100+
)
98101
import Kore.Log.WarnStuckProofState
99102
( WarnStuckProofState
100103
)
@@ -148,6 +151,7 @@ entryHelpDocs :: [Pretty.Doc ()]
148151
, mk $ Proxy @WarnFunctionWithoutEvaluators
149152
, mk $ Proxy @WarnSymbolSMTRepresentation
150153
, mk $ Proxy @WarnStuckProofState
154+
, mk $ Proxy @WarnIfLowProductivity
151155
, mk $ Proxy @DebugEvaluateCondition
152156
, mk $ Proxy @ErrorException
153157
, mk $ Proxy @ErrorRewriteLoop
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{- |
2+
Copyright : (c) Runtime Verification, 2020
3+
License : NCSA
4+
5+
-}
6+
7+
module Kore.Log.WarnIfLowProductivity
8+
( WarnIfLowProductivity (..)
9+
, warnIfLowProductivity
10+
)where
11+
12+
import Prelude.Kore
13+
14+
import Log
15+
import Numeric.Natural
16+
import Pretty
17+
( Pretty
18+
)
19+
import qualified Pretty
20+
import Stats
21+
22+
newtype WarnIfLowProductivity =
23+
WarnIfLowProductivity { productivityPercent :: Natural }
24+
deriving Show
25+
26+
instance Pretty WarnIfLowProductivity where
27+
pretty (WarnIfLowProductivity productivityPercent) =
28+
Pretty.hsep
29+
[ "Warning! Poor performance: productivity dropped to aprox."
30+
, Pretty.pretty productivityPercent <> "%"
31+
]
32+
33+
instance Entry WarnIfLowProductivity where
34+
entrySeverity _ = Warning
35+
helpDoc _ = "warn when productivty (MUT time / Total time) drops below 90%"
36+
37+
warnIfLowProductivity :: MonadLog log => MonadIO log => log ()
38+
warnIfLowProductivity = do
39+
Stats { gc_cpu_ns, cpu_ns } <- liftIO getStats
40+
let gcTimeOver10Percent = gc_cpu_ns * 10 > cpu_ns
41+
gcPercentage = gc_cpu_ns * 100 `div` cpu_ns
42+
productivity = 100 - gcPercentage & fromIntegral
43+
when gcTimeOver10Percent . logEntry
44+
$ WarnIfLowProductivity productivity

0 commit comments

Comments
 (0)