status: In local mode, displays information about variance from configured numcopies levels.

This commit is contained in:
Joey Hess 2013-09-15 19:10:38 -04:00
parent 5c71dc1087
commit a3bbda5bed
4 changed files with 50 additions and 9 deletions

View file

@ -111,7 +111,7 @@ numCopies file = do
Just n -> return $ Just n Just n -> return $ Just n
Nothing -> readish <$> checkAttr "annex.numcopies" file Nothing -> readish <$> checkAttr "annex.numcopies" file
numCopiesCheck :: FilePath -> Key -> (Int -> Int -> Bool) -> Annex Bool numCopiesCheck :: FilePath -> Key -> (Int -> Int -> v) -> Annex v
numCopiesCheck file key vs = do numCopiesCheck file key vs = do
numcopiesattr <- numCopies file numcopiesattr <- numCopies file
needed <- getNumCopies numcopiesattr needed <- getNumCopies numcopiesattr

View file

@ -13,6 +13,7 @@ import "mtl" Control.Monad.State.Strict
import qualified Data.Map as M import qualified Data.Map as M
import Text.JSON import Text.JSON
import Data.Tuple import Data.Tuple
import Data.Ord
import System.PosixCompat.Files import System.PosixCompat.Files
import Common.Annex import Common.Annex
@ -49,10 +50,24 @@ data KeyData = KeyData
, backendsKeys :: M.Map String Integer , backendsKeys :: M.Map String Integer
} }
data NumCopiesStats = NumCopiesStats
{ numCopiesVarianceMap :: M.Map Variance Integer
}
newtype Variance = Variance Int
deriving (Eq, Ord)
instance Show Variance where
show (Variance n)
| n == 0 = "numcopies satisfied"
| n > 0 = "numcopies +" ++ show n
| otherwise = "numcopies " ++ show n
-- cached info that multiple Stats use -- cached info that multiple Stats use
data StatInfo = StatInfo data StatInfo = StatInfo
{ presentData :: Maybe KeyData { presentData :: Maybe KeyData
, referencedData :: Maybe KeyData , referencedData :: Maybe KeyData
, numCopiesStats :: Maybe NumCopiesStats
} }
-- a state monad for running Stats in -- a state monad for running Stats in
@ -82,7 +97,7 @@ globalStatus = do
then global_fast_stats then global_fast_stats
else global_fast_stats ++ global_slow_stats else global_fast_stats ++ global_slow_stats
showCustom "status" $ do showCustom "status" $ do
evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing) evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing Nothing)
return True return True
localStatus :: FilePath -> Annex () localStatus :: FilePath -> Annex ()
@ -123,6 +138,7 @@ local_stats =
, const local_annex_size , const local_annex_size
, const known_annex_keys , const known_annex_keys
, const known_annex_size , const known_annex_size
, const numcopies_stats
] ]
stat :: String -> (String -> StatState String) -> Stat stat :: String -> (String -> StatState String) -> Stat
@ -255,6 +271,14 @@ backend_usage = stat "backend usage" $ nojson $
reverse $ sort $ map swap $ M.toList $ reverse $ sort $ map swap $ M.toList $
M.unionWith (+) x y M.unionWith (+) x y
numcopies_stats :: Stat
numcopies_stats = stat "numcopies stats" $ nojson $
calc <$> (maybe M.empty numCopiesVarianceMap <$> cachedNumCopiesStats)
where
calc = multiLine
. map (\(variance, count) -> show variance ++ ": " ++ show count)
. reverse . sortBy (comparing snd) . M.toList
cachedPresentData :: StatState KeyData cachedPresentData :: StatState KeyData
cachedPresentData = do cachedPresentData = do
s <- get s <- get
@ -276,29 +300,37 @@ cachedReferencedData = do
put s { referencedData = Just v } put s { referencedData = Just v }
return v return v
-- currently only available for local status
cachedNumCopiesStats :: StatState (Maybe NumCopiesStats)
cachedNumCopiesStats = numCopiesStats <$> get
getLocalStatInfo :: FilePath -> Annex StatInfo getLocalStatInfo :: FilePath -> Annex StatInfo
getLocalStatInfo dir = do getLocalStatInfo dir = do
matcher <- Limit.getMatcher matcher <- Limit.getMatcher
(presentdata, referenceddata) <- (presentdata, referenceddata, numcopiesstats) <-
Command.Unused.withKeysFilesReferencedIn dir initial Command.Unused.withKeysFilesReferencedIn dir initial
(update matcher) (update matcher)
return $ StatInfo (Just presentdata) (Just referenceddata) return $ StatInfo (Just presentdata) (Just referenceddata) (Just numcopiesstats)
where where
initial = (emptyKeyData, emptyKeyData) initial = (emptyKeyData, emptyKeyData, emptyNumCopiesStats)
update matcher key file vs@(presentdata, referenceddata) = update matcher key file vs@(presentdata, referenceddata, numcopiesstats) =
ifM (matcher $ FileInfo file file) ifM (matcher $ FileInfo file file)
( (,) ( (,,)
<$> ifM (inAnnex key) <$> ifM (inAnnex key)
( return $ addKey key presentdata ( return $ addKey key presentdata
, return presentdata , return presentdata
) )
<*> pure (addKey key referenceddata) <*> pure (addKey key referenceddata)
<*> updateNumCopiesStats key file numcopiesstats
, return vs , return vs
) )
emptyKeyData :: KeyData emptyKeyData :: KeyData
emptyKeyData = KeyData 0 0 0 M.empty emptyKeyData = KeyData 0 0 0 M.empty
emptyNumCopiesStats :: NumCopiesStats
emptyNumCopiesStats = NumCopiesStats $ M.empty
foldKeys :: [Key] -> KeyData foldKeys :: [Key] -> KeyData
foldKeys = foldl' (flip addKey) emptyKeyData foldKeys = foldl' (flip addKey) emptyKeyData
@ -314,6 +346,13 @@ addKey key (KeyData count size unknownsize backends) =
!unknownsize' = maybe (unknownsize + 1) (const unknownsize) ks !unknownsize' = maybe (unknownsize + 1) (const unknownsize) ks
ks = keySize key ks = keySize key
updateNumCopiesStats :: Key -> FilePath -> NumCopiesStats -> Annex NumCopiesStats
updateNumCopiesStats key file stats = do
variance <- Variance <$> numCopiesCheck file key (-)
return $ stats { numCopiesVarianceMap = update (numCopiesVarianceMap stats) variance }
where
update m variance = M.insertWith' (+) variance 1 m
showSizeKeys :: KeyData -> String showSizeKeys :: KeyData -> String
showSizeKeys d = total ++ missingnote showSizeKeys d = total ++ missingnote
where where

2
debian/changelog vendored
View file

@ -11,6 +11,8 @@ git-annex (4.20130912) UNRELEASED; urgency=low
* sync: Don't fail if the directory it is run in gets removed by the * sync: Don't fail if the directory it is run in gets removed by the
sync. sync.
* addurl: Fix quvi audodetection, broken in last release. * addurl: Fix quvi audodetection, broken in last release.
* status: In local mode, displays information about variance from configured
numcopies levels.
-- Joey Hess <joeyh@debian.org> Thu, 12 Sep 2013 12:14:46 -0400 -- Joey Hess <joeyh@debian.org> Thu, 12 Sep 2013 12:14:46 -0400

View file

@ -577,7 +577,7 @@ subdirectories).
To only show the data that can be gathered quickly, use `--fast`. To only show the data that can be gathered quickly, use `--fast`.
When a directory is specified, shows only an abbreviated status When a directory is specified, shows a differently formatted status
display for that directory. In this mode, all of the file matching display for that directory. In this mode, all of the file matching
options can be used to filter the files that will be included in options can be used to filter the files that will be included in
the status. the status.
@ -586,7 +586,7 @@ subdirectories).
would first like to see how much disk space that will use. would first like to see how much disk space that will use.
Then run: Then run:
git annex status . --not --in here git annex status --fast . --not --in here
* `map` * `map`