Skip to content

Commit 4651a77

Browse files
committed
Add disk space stats.
1 parent e0e9367 commit 4651a77

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

rules_haskell_tests/tests/RunTests.hs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import GenModule (a)
2424
import IntegrationTesting
2525

2626
main :: IO ()
27-
main = hspec $ around_ printMemoryHook $ do
27+
main = hspec $ around_ printStatsHook $ do
2828

2929
describe "rules_haskell_tests" $ afterAll_ (shutdownBazel ".") $ do
3030
it "bazel test" $ do
@@ -184,38 +184,54 @@ buildAndTest path = describe path $ afterAll_ (shutdownBazel path) $ do
184184

185185
-- | Print memory information before and after each test
186186
-- Only perform the hook if RHT_PRINT_MEMORY is "true".
187-
printMemoryHook :: IO () -> IO ()
188-
printMemoryHook action = do
187+
printStatsHook :: IO () -> IO ()
188+
printStatsHook action = do
189189
rhtPrintMem <- lookupEnv "RHT_PRINT_MEMORY"
190190
case rhtPrintMem of
191191
Just "true" -> bracket_
192-
(printMemory "=== BEFORE ===")
193-
(printMemory "=== AFTER ===")
192+
(printStats "=== BEFORE ===")
193+
(printStats "=== AFTER ===")
194194
action
195195
_ -> action
196196

197197
topPath :: String
198198
topPath = "/usr/bin/top"
199199

200-
-- | Print information about the current memory state to debug intermittent failures
200+
dfPath :: String
201+
dfPath = "/bin/df"
202+
203+
-- | Print information about the computer state to debug intermittent failures
201204
-- Related to https://github.com/tweag/rules_haskell/issues/2089
202-
printMemory :: String -> IO ()
203-
printMemory msg = do
205+
printStats :: String -> IO ()
206+
printStats msg = do
204207
-- Do not attempt to run top, if it does not exist.
205208
topExists <- doesFileExist topPath
209+
dfExists <- doesFileExist dfPath
210+
if topExists || dfExists then putStrLn msg else pure()
206211
if topExists
207-
then _doPrintMemory msg
212+
then _printMemory
213+
else pure()
214+
if dfExists
215+
then _printDiskInfo
208216
else pure()
209217

210218
-- | Print information about the current memory state to debug intermittent failures
211219
-- Related to https://github.com/tweag/rules_haskell/issues/2089
212-
_doPrintMemory :: String -> IO ()
213-
_doPrintMemory msg = do
214-
putStrLn msg
220+
_printMemory :: IO ()
221+
_printMemory = do
215222
(exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode topPath ["-l", "1", "-s", "0", "-o", "mem", "-n", "15"] ""
216223
case exitCode of
217224
ExitSuccess -> putStrLn stdOut
218-
ExitFailure _ -> putStrLn ("=== printMemory failed ===\n" ++ stdErr)
225+
ExitFailure _ -> putStrLn ("=== _printMemory failed ===\n" ++ stdErr)
226+
227+
-- | Print information about the disk drives to debug intermittent failures
228+
-- Related to https://github.com/tweag/rules_haskell/issues/2089
229+
_printDiskInfo :: IO ()
230+
_printDiskInfo = do
231+
(exitCode, stdOut, stdErr) <- Process.readProcessWithExitCode dfPath ["-H"] ""
232+
case exitCode of
233+
ExitSuccess -> putStrLn stdOut
234+
ExitFailure _ -> putStrLn ("=== _printDiskInfo failed ===\n" ++ stdErr)
219235

220236
-- Generated dependencies for testing the ghcide support
221237
_ghciIDE :: Int

0 commit comments

Comments
 (0)