add info about any temp files and bad content files
This commit is contained in:
parent
13b9e5986c
commit
1e3da8efb0
1 changed files with 39 additions and 11 deletions
|
@ -18,17 +18,18 @@ import qualified BackendClass
|
||||||
import qualified RemoteClass
|
import qualified RemoteClass
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import qualified Command.Unused
|
import qualified Command.Unused
|
||||||
|
import qualified GitRepo as Git
|
||||||
import Command
|
import Command
|
||||||
import Types
|
import Types
|
||||||
import DataUnits
|
import DataUnits
|
||||||
import Content
|
import Content
|
||||||
import Key
|
import Key
|
||||||
|
import Locations
|
||||||
|
|
||||||
-- a named computation that produces a statistic
|
-- a named computation that produces a statistic
|
||||||
type Stat = (String, StatState String)
|
type Stat = StatState (Maybe (String, StatState String))
|
||||||
|
|
||||||
-- cached info that multiple Stats may need
|
-- cached info that multiple Stats may need
|
||||||
type SizeList a = ([a], Int)
|
|
||||||
data StatInfo = StatInfo
|
data StatInfo = StatInfo
|
||||||
{ keysPresentCache :: (Maybe (SizeList Key))
|
{ keysPresentCache :: (Maybe (SizeList Key))
|
||||||
, keysReferencedCache :: (Maybe (SizeList Key))
|
, keysReferencedCache :: (Maybe (SizeList Key))
|
||||||
|
@ -37,6 +38,11 @@ data StatInfo = StatInfo
|
||||||
-- a state monad for running Stats in
|
-- a state monad for running Stats in
|
||||||
type StatState = StateT StatInfo Annex
|
type StatState = StateT StatInfo Annex
|
||||||
|
|
||||||
|
type SizeList a = ([a], Int)
|
||||||
|
|
||||||
|
sizeList :: [a] -> SizeList a
|
||||||
|
sizeList l = (l, length l)
|
||||||
|
|
||||||
command :: [Command]
|
command :: [Command]
|
||||||
command = [repoCommand "status" (paramNothing) seek
|
command = [repoCommand "status" (paramNothing) seek
|
||||||
"shows status information about the annex"]
|
"shows status information about the annex"]
|
||||||
|
@ -53,6 +59,8 @@ faststats =
|
||||||
, supported_remote_types
|
, supported_remote_types
|
||||||
, local_annex_keys
|
, local_annex_keys
|
||||||
, local_annex_size
|
, local_annex_size
|
||||||
|
, tmp_size
|
||||||
|
, bad_data_size
|
||||||
]
|
]
|
||||||
slowstats :: [Stat]
|
slowstats :: [Stat]
|
||||||
slowstats =
|
slowstats =
|
||||||
|
@ -69,14 +77,19 @@ start = do
|
||||||
stop
|
stop
|
||||||
|
|
||||||
stat :: String -> StatState String -> Stat
|
stat :: String -> StatState String -> Stat
|
||||||
stat desc a = (desc, a)
|
stat desc a = return $ Just (desc, a)
|
||||||
|
|
||||||
|
nostat :: Stat
|
||||||
|
nostat = return $ Nothing
|
||||||
|
|
||||||
showStat :: Stat -> StatState ()
|
showStat :: Stat -> StatState ()
|
||||||
showStat (desc, a) = do
|
showStat s = calc =<< s
|
||||||
liftIO $ putStr $ desc ++ ": "
|
where
|
||||||
liftIO $ hFlush stdout
|
calc (Just (desc, a)) = do
|
||||||
liftIO . putStrLn =<< a
|
liftIO $ putStr $ desc ++ ": "
|
||||||
|
liftIO $ hFlush stdout
|
||||||
|
liftIO . putStrLn =<< a
|
||||||
|
calc Nothing = return ()
|
||||||
|
|
||||||
supported_backends :: Stat
|
supported_backends :: Stat
|
||||||
supported_backends = stat "supported backends" $
|
supported_backends = stat "supported backends" $
|
||||||
|
@ -103,6 +116,12 @@ total_annex_keys :: Stat
|
||||||
total_annex_keys = stat "total annex keys" $
|
total_annex_keys = stat "total annex keys" $
|
||||||
return . show . snd =<< cachedKeysReferenced
|
return . show . snd =<< cachedKeysReferenced
|
||||||
|
|
||||||
|
tmp_size :: Stat
|
||||||
|
tmp_size = staleSize "temporary directory size" gitAnnexTmpDir
|
||||||
|
|
||||||
|
bad_data_size :: Stat
|
||||||
|
bad_data_size = staleSize "bad keys size" gitAnnexBadDir
|
||||||
|
|
||||||
backend_usage :: Stat
|
backend_usage :: Stat
|
||||||
backend_usage = stat "backend usage" $
|
backend_usage = stat "backend usage" $
|
||||||
return . usage =<< cachedKeysReferenced
|
return . usage =<< cachedKeysReferenced
|
||||||
|
@ -115,6 +134,7 @@ backend_usage = stat "backend usage" $
|
||||||
pp c [] = c
|
pp c [] = c
|
||||||
pp c ((n, b):xs) = "\n\t" ++ b ++ ": " ++ show n ++ pp c xs
|
pp c ((n, b):xs) = "\n\t" ++ b ++ ": " ++ show n ++ pp c xs
|
||||||
|
|
||||||
|
|
||||||
cachedKeysPresent :: StatState (SizeList Key)
|
cachedKeysPresent :: StatState (SizeList Key)
|
||||||
cachedKeysPresent = do
|
cachedKeysPresent = do
|
||||||
s <- get
|
s <- get
|
||||||
|
@ -122,7 +142,7 @@ cachedKeysPresent = do
|
||||||
Just v -> return v
|
Just v -> return v
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
keys <- lift $ getKeysPresent
|
keys <- lift $ getKeysPresent
|
||||||
let v = (keys, length keys)
|
let v = sizeList keys
|
||||||
put s { keysPresentCache = Just v }
|
put s { keysPresentCache = Just v }
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -135,8 +155,7 @@ cachedKeysReferenced = do
|
||||||
keys <- lift $ Command.Unused.getKeysReferenced
|
keys <- lift $ Command.Unused.getKeysReferenced
|
||||||
-- A given key may be referenced repeatedly.
|
-- A given key may be referenced repeatedly.
|
||||||
-- nub does not seem too slow (yet)..
|
-- nub does not seem too slow (yet)..
|
||||||
let uniques = nub keys
|
let v = sizeList $ nub keys
|
||||||
let v = (uniques, length uniques)
|
|
||||||
put s { keysReferencedCache = Just v }
|
put s { keysReferencedCache = Just v }
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -149,3 +168,12 @@ keySizeSum (keys, len) = do
|
||||||
if missing > 0
|
if missing > 0
|
||||||
then " (but " ++ show missing ++ " keys have unknown size)"
|
then " (but " ++ show missing ++ " keys have unknown size)"
|
||||||
else ""
|
else ""
|
||||||
|
|
||||||
|
staleSize :: String -> (Git.Repo -> FilePath) -> Stat
|
||||||
|
staleSize label dirspec = do
|
||||||
|
keys <- lift (Command.Unused.staleKeys dirspec)
|
||||||
|
if null keys
|
||||||
|
then nostat
|
||||||
|
else stat label $ do
|
||||||
|
s <- keySizeSum $ sizeList keys
|
||||||
|
return $ s ++ " (clean up with git-annex unused)"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue