2011-05-17 01:18:34 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2011-2014 Joey Hess <id@joeyh.name>
|
2011-05-17 01:18:34 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2013-04-13 22:12:02 +00:00
|
|
|
{-# LANGUAGE BangPatterns #-}
|
2012-03-11 21:15:58 +00:00
|
|
|
|
2013-11-07 16:45:59 +00:00
|
|
|
module Command.Info where
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2012-10-24 18:43:32 +00:00
|
|
|
import "mtl" Control.Monad.State.Strict
|
2015-04-12 16:49:11 +00:00
|
|
|
import qualified Data.Map.Strict as M
|
2011-11-20 18:12:48 +00:00
|
|
|
import Text.JSON
|
2012-10-03 21:04:52 +00:00
|
|
|
import Data.Tuple
|
2013-09-15 23:10:38 +00:00
|
|
|
import Data.Ord
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-05-17 01:18:34 +00:00
|
|
|
import qualified Command.Unused
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
2011-11-14 23:27:00 +00:00
|
|
|
import qualified Annex
|
2014-10-21 17:44:17 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Types.Remote as Remote
|
2011-05-17 01:18:34 +00:00
|
|
|
import Command
|
2011-07-06 00:36:43 +00:00
|
|
|
import Utility.DataUnits
|
2012-03-22 21:09:54 +00:00
|
|
|
import Utility.DiskFree
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2014-10-21 17:24:15 +00:00
|
|
|
import Annex.Link
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Key
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.UUID
|
2011-11-14 20:14:17 +00:00
|
|
|
import Logs.Trust
|
2015-01-13 22:11:03 +00:00
|
|
|
import Logs.Location
|
2014-01-21 22:08:56 +00:00
|
|
|
import Config.NumCopies
|
2011-09-30 07:20:24 +00:00
|
|
|
import Remote
|
2012-03-22 01:55:02 +00:00
|
|
|
import Config
|
2012-04-29 21:48:07 +00:00
|
|
|
import Utility.Percentage
|
2012-07-01 20:59:54 +00:00
|
|
|
import Logs.Transfer
|
2012-10-03 21:04:52 +00:00
|
|
|
import Types.TrustLevel
|
2013-05-25 03:07:26 +00:00
|
|
|
import Types.FileMatcher
|
2013-03-11 05:22:56 +00:00
|
|
|
import qualified Limit
|
2011-05-17 01:18:34 +00:00
|
|
|
|
|
|
|
-- a named computation that produces a statistic
|
2011-09-20 22:57:05 +00:00
|
|
|
type Stat = StatState (Maybe (String, StatState String))
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
-- data about a set of keys
|
|
|
|
data KeyData = KeyData
|
|
|
|
{ countKeys :: Integer
|
|
|
|
, sizeKeys :: Integer
|
|
|
|
, unknownSizeKeys :: Integer
|
|
|
|
, backendsKeys :: M.Map String Integer
|
|
|
|
}
|
|
|
|
|
2013-09-15 23:10:38 +00:00
|
|
|
data NumCopiesStats = NumCopiesStats
|
2013-10-07 08:06:10 +00:00
|
|
|
{ numCopiesVarianceMap :: M.Map Variance Integer
|
2013-09-15 23:10:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 08:06:10 +00:00
|
|
|
newtype Variance = Variance Int
|
|
|
|
deriving (Eq, Ord)
|
2013-09-15 23:10:38 +00:00
|
|
|
|
2013-10-07 08:06:10 +00:00
|
|
|
instance Show Variance where
|
|
|
|
show (Variance n)
|
|
|
|
| n >= 0 = "numcopies +" ++ show n
|
|
|
|
| otherwise = "numcopies " ++ show n
|
2013-09-15 23:10:38 +00:00
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
-- cached info that multiple Stats use
|
2011-05-17 01:18:34 +00:00
|
|
|
data StatInfo = StatInfo
|
2012-03-11 21:15:58 +00:00
|
|
|
{ presentData :: Maybe KeyData
|
|
|
|
, referencedData :: Maybe KeyData
|
2015-04-12 16:49:11 +00:00
|
|
|
, repoData :: M.Map UUID KeyData
|
2013-09-15 23:10:38 +00:00
|
|
|
, numCopiesStats :: Maybe NumCopiesStats
|
2011-05-17 01:18:34 +00:00
|
|
|
}
|
2015-01-13 22:11:03 +00:00
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
emptyStatInfo :: StatInfo
|
2015-01-13 22:11:03 +00:00
|
|
|
emptyStatInfo = StatInfo Nothing Nothing M.empty Nothing
|
2011-05-17 01:18:34 +00:00
|
|
|
|
|
|
|
-- a state monad for running Stats in
|
|
|
|
type StatState = StateT StatInfo Annex
|
|
|
|
|
2014-10-14 18:20:10 +00:00
|
|
|
cmd :: [Command]
|
2015-04-12 18:08:40 +00:00
|
|
|
cmd = [noCommit $ dontCheck repoExists $ withOptions (jsonOption : bytesOption : annexedMatchingOptions) $
|
2014-10-21 17:44:17 +00:00
|
|
|
command "info" (paramOptional $ paramRepeating paramItem) seek SectionQuery
|
2014-10-21 17:24:15 +00:00
|
|
|
"shows information about the specified item or the repository as a whole"]
|
2011-05-17 01:18:34 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek :: CommandSeek
|
|
|
|
seek = withWords start
|
2013-03-11 05:22:56 +00:00
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
start :: [String] -> CommandStart
|
2013-03-11 05:22:56 +00:00
|
|
|
start [] = do
|
2013-11-07 16:45:59 +00:00
|
|
|
globalInfo
|
2013-03-11 05:22:56 +00:00
|
|
|
stop
|
|
|
|
start ps = do
|
2014-10-21 17:24:15 +00:00
|
|
|
mapM_ itemInfo ps
|
2013-03-11 05:22:56 +00:00
|
|
|
stop
|
|
|
|
|
2013-11-07 16:45:59 +00:00
|
|
|
globalInfo :: Annex ()
|
|
|
|
globalInfo = do
|
2013-09-15 23:17:56 +00:00
|
|
|
stats <- selStats global_fast_stats global_slow_stats
|
2013-11-07 16:45:59 +00:00
|
|
|
showCustom "info" $ do
|
2014-10-21 17:24:15 +00:00
|
|
|
evalStateT (mapM_ showStat stats) emptyStatInfo
|
2013-03-11 05:22:56 +00:00
|
|
|
return True
|
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
itemInfo :: String -> Annex ()
|
|
|
|
itemInfo p = ifM (isdir p)
|
|
|
|
( dirInfo p
|
2014-10-21 17:44:17 +00:00
|
|
|
, do
|
|
|
|
v <- Remote.byName' p
|
|
|
|
case v of
|
|
|
|
Right r -> remoteInfo r
|
2015-01-13 22:11:03 +00:00
|
|
|
Left _ -> do
|
|
|
|
v' <- Remote.nameToUUID' p
|
|
|
|
case v' of
|
|
|
|
Right u -> uuidInfo u
|
|
|
|
Left _ -> maybe noinfo (fileInfo p)
|
|
|
|
=<< isAnnexLink p
|
2014-10-21 17:24:15 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
2015-01-13 22:11:03 +00:00
|
|
|
noinfo = error $ p ++ " is not a directory or an annexed file or a remote or a uuid"
|
2014-10-21 17:24:15 +00:00
|
|
|
|
|
|
|
dirInfo :: FilePath -> Annex ()
|
|
|
|
dirInfo dir = showCustom (unwords ["info", dir]) $ do
|
|
|
|
stats <- selStats (tostats dir_fast_stats) (tostats dir_slow_stats)
|
|
|
|
evalStateT (mapM_ showStat stats) =<< getDirStatInfo dir
|
2013-03-11 05:22:56 +00:00
|
|
|
return True
|
2013-09-15 23:17:56 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
tostats = map (\s -> s dir)
|
2013-09-15 23:17:56 +00:00
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
fileInfo :: FilePath -> Key -> Annex ()
|
|
|
|
fileInfo file k = showCustom (unwords ["info", file]) $ do
|
|
|
|
evalStateT (mapM_ showStat (file_stats file k)) emptyStatInfo
|
|
|
|
return True
|
|
|
|
|
2014-10-21 17:44:17 +00:00
|
|
|
remoteInfo :: Remote -> Annex ()
|
|
|
|
remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do
|
2014-10-21 18:36:09 +00:00
|
|
|
info <- map (\(k, v) -> simpleStat k (pure v)) <$> Remote.getInfo r
|
2015-01-13 22:11:03 +00:00
|
|
|
l <- selStats (remote_fast_stats r ++ info) (uuid_slow_stats (Remote.uuid r))
|
|
|
|
evalStateT (mapM_ showStat l) emptyStatInfo
|
|
|
|
return True
|
|
|
|
|
|
|
|
uuidInfo :: UUID -> Annex ()
|
|
|
|
uuidInfo u = showCustom (unwords ["info", fromUUID u]) $ do
|
|
|
|
l <- selStats [] ((uuid_slow_stats u))
|
|
|
|
evalStateT (mapM_ showStat l) emptyStatInfo
|
2014-10-21 17:44:17 +00:00
|
|
|
return True
|
|
|
|
|
2013-09-15 23:17:56 +00:00
|
|
|
selStats :: [Stat] -> [Stat] -> Annex [Stat]
|
|
|
|
selStats fast_stats slow_stats = do
|
|
|
|
fast <- Annex.getState Annex.fast
|
|
|
|
return $ if fast
|
|
|
|
then fast_stats
|
|
|
|
else fast_stats ++ slow_stats
|
2011-05-17 01:18:34 +00:00
|
|
|
|
|
|
|
{- Order is significant. Less expensive operations, and operations
|
|
|
|
- that share data go together.
|
|
|
|
-}
|
2013-03-11 05:22:56 +00:00
|
|
|
global_fast_stats :: [Stat]
|
|
|
|
global_fast_stats =
|
2013-10-02 00:50:46 +00:00
|
|
|
[ repository_mode
|
2015-04-12 16:49:11 +00:00
|
|
|
, repo_list Trusted
|
|
|
|
, repo_list SemiTrusted
|
|
|
|
, repo_list UnTrusted
|
2012-07-01 20:59:54 +00:00
|
|
|
, transfer_list
|
2012-04-23 14:37:05 +00:00
|
|
|
, disk_size
|
2011-11-14 23:27:00 +00:00
|
|
|
]
|
2013-03-11 05:22:56 +00:00
|
|
|
global_slow_stats :: [Stat]
|
|
|
|
global_slow_stats =
|
2011-11-14 23:27:00 +00:00
|
|
|
[ tmp_size
|
2011-05-17 02:01:50 +00:00
|
|
|
, bad_data_size
|
2011-09-20 22:13:08 +00:00
|
|
|
, local_annex_keys
|
2011-05-17 02:19:15 +00:00
|
|
|
, local_annex_size
|
2013-10-28 19:04:38 +00:00
|
|
|
, known_annex_files
|
2012-02-06 18:19:44 +00:00
|
|
|
, known_annex_size
|
2012-03-12 20:18:14 +00:00
|
|
|
, bloom_info
|
2011-05-17 01:18:34 +00:00
|
|
|
, backend_usage
|
|
|
|
]
|
2014-10-21 17:24:15 +00:00
|
|
|
dir_fast_stats :: [FilePath -> Stat]
|
|
|
|
dir_fast_stats =
|
2014-10-21 17:44:17 +00:00
|
|
|
[ dir_name
|
2013-03-11 05:22:56 +00:00
|
|
|
, const local_annex_keys
|
|
|
|
, const local_annex_size
|
2013-10-28 19:04:38 +00:00
|
|
|
, const known_annex_files
|
2013-03-11 05:22:56 +00:00
|
|
|
, const known_annex_size
|
2013-09-15 23:17:56 +00:00
|
|
|
]
|
2014-10-21 17:24:15 +00:00
|
|
|
dir_slow_stats :: [FilePath -> Stat]
|
|
|
|
dir_slow_stats =
|
2013-09-15 23:17:56 +00:00
|
|
|
[ const numcopies_stats
|
2015-04-12 16:49:11 +00:00
|
|
|
, const reposizes_stats
|
2013-03-11 05:22:56 +00:00
|
|
|
]
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
file_stats :: FilePath -> Key -> [Stat]
|
|
|
|
file_stats f k =
|
2014-10-21 17:44:17 +00:00
|
|
|
[ file_name f
|
2014-10-21 17:24:15 +00:00
|
|
|
, key_size k
|
|
|
|
, key_name k
|
|
|
|
]
|
|
|
|
|
2015-01-13 22:11:03 +00:00
|
|
|
remote_fast_stats :: Remote -> [Stat]
|
|
|
|
remote_fast_stats r = map (\s -> s r)
|
2014-10-21 18:36:09 +00:00
|
|
|
[ remote_name
|
|
|
|
, remote_description
|
|
|
|
, remote_uuid
|
2015-04-05 17:51:01 +00:00
|
|
|
, remote_trust
|
2014-10-21 18:36:09 +00:00
|
|
|
, remote_cost
|
|
|
|
, remote_type
|
2014-10-21 17:44:17 +00:00
|
|
|
]
|
|
|
|
|
2015-01-13 22:11:03 +00:00
|
|
|
uuid_slow_stats :: UUID -> [Stat]
|
|
|
|
uuid_slow_stats u = map (\s -> s u)
|
|
|
|
[ remote_annex_keys
|
|
|
|
, remote_annex_size
|
|
|
|
]
|
|
|
|
|
2011-11-20 18:12:48 +00:00
|
|
|
stat :: String -> (String -> StatState String) -> Stat
|
|
|
|
stat desc a = return $ Just (desc, a desc)
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2014-10-21 18:36:09 +00:00
|
|
|
-- The json simply contains the same string that is displayed.
|
|
|
|
simpleStat :: String -> StatState String -> Stat
|
|
|
|
simpleStat desc getval = stat desc $ json id getval
|
|
|
|
|
2011-05-17 02:01:50 +00:00
|
|
|
nostat :: Stat
|
2011-07-15 16:47:14 +00:00
|
|
|
nostat = return Nothing
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2011-11-20 18:12:48 +00:00
|
|
|
json :: JSON j => (j -> String) -> StatState j -> String -> StatState String
|
|
|
|
json serialize a desc = do
|
|
|
|
j <- a
|
|
|
|
lift $ maybeShowJSON [(desc, j)]
|
|
|
|
return $ serialize j
|
|
|
|
|
|
|
|
nojson :: StatState String -> String -> StatState String
|
|
|
|
nojson a _ = a
|
|
|
|
|
2011-05-17 02:01:50 +00:00
|
|
|
showStat :: Stat -> StatState ()
|
2012-04-22 03:32:33 +00:00
|
|
|
showStat s = maybe noop calc =<< s
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
calc (desc, a) = do
|
|
|
|
(lift . showHeader) desc
|
|
|
|
lift . showRaw =<< a
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2012-12-13 17:48:07 +00:00
|
|
|
repository_mode :: Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
repository_mode = simpleStat "repository mode" $ lift $
|
2012-12-13 17:48:07 +00:00
|
|
|
ifM isDirect
|
2015-04-09 16:28:26 +00:00
|
|
|
( return "direct"
|
|
|
|
, ifM (fromRepo Git.repoIsLocalBare)
|
|
|
|
( return "bare"
|
|
|
|
, return "indirect"
|
|
|
|
)
|
|
|
|
)
|
2012-12-13 17:48:07 +00:00
|
|
|
|
2015-04-12 16:49:11 +00:00
|
|
|
repo_list :: TrustLevel -> Stat
|
|
|
|
repo_list level = stat n $ nojson $ lift $ do
|
2014-10-28 20:03:57 +00:00
|
|
|
us <- filter (/= NoUUID) . M.keys
|
|
|
|
<$> (M.union <$> uuidMap <*> remoteMap Remote.name)
|
2011-11-15 04:33:54 +00:00
|
|
|
rs <- fst <$> trustPartition level us
|
|
|
|
s <- prettyPrintUUIDs n rs
|
2011-12-15 22:11:42 +00:00
|
|
|
return $ if null s then "0" else show (length rs) ++ "\n" ++ beginning s
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
n = showTrustLevel level ++ " repositories"
|
2012-03-12 20:18:14 +00:00
|
|
|
|
2014-10-21 17:44:17 +00:00
|
|
|
dir_name :: FilePath -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
dir_name dir = simpleStat "directory" $ pure dir
|
2014-10-21 17:44:17 +00:00
|
|
|
|
|
|
|
file_name :: FilePath -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
file_name file = simpleStat "file" $ pure file
|
2014-10-21 17:44:17 +00:00
|
|
|
|
|
|
|
remote_name :: Remote -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
remote_name r = simpleStat "remote" $ pure (Remote.name r)
|
2014-10-21 17:44:17 +00:00
|
|
|
|
|
|
|
remote_description :: Remote -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
remote_description r = simpleStat "description" $ lift $
|
2014-10-21 17:44:17 +00:00
|
|
|
Remote.prettyUUID (Remote.uuid r)
|
|
|
|
|
|
|
|
remote_uuid :: Remote -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
remote_uuid r = simpleStat "uuid" $ pure $
|
2014-10-21 17:44:17 +00:00
|
|
|
fromUUID $ Remote.uuid r
|
2013-03-11 05:22:56 +00:00
|
|
|
|
2015-04-05 17:51:01 +00:00
|
|
|
remote_trust :: Remote -> Stat
|
|
|
|
remote_trust r = simpleStat "trust" $ lift $
|
|
|
|
showTrustLevel <$> lookupTrust (Remote.uuid r)
|
|
|
|
|
2014-10-21 17:44:17 +00:00
|
|
|
remote_cost :: Remote -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
remote_cost r = simpleStat "cost" $ pure $
|
2014-10-21 17:44:17 +00:00
|
|
|
show $ Remote.cost r
|
2014-10-21 17:24:15 +00:00
|
|
|
|
2014-10-21 18:36:09 +00:00
|
|
|
remote_type :: Remote -> Stat
|
|
|
|
remote_type r = simpleStat "type" $ pure $
|
|
|
|
Remote.typename $ Remote.remotetype r
|
|
|
|
|
2013-10-28 19:04:38 +00:00
|
|
|
local_annex_keys :: Stat
|
|
|
|
local_annex_keys = stat "local annex keys" $ json show $
|
|
|
|
countKeys <$> cachedPresentData
|
|
|
|
|
2011-05-17 01:18:34 +00:00
|
|
|
local_annex_size :: Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
local_annex_size = simpleStat "local annex size" $
|
2015-04-12 18:08:40 +00:00
|
|
|
lift . showSizeKeys =<< cachedPresentData
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2015-01-13 22:11:03 +00:00
|
|
|
remote_annex_keys :: UUID -> Stat
|
|
|
|
remote_annex_keys u = stat "remote annex keys" $ json show $
|
|
|
|
countKeys <$> cachedRemoteData u
|
|
|
|
|
|
|
|
remote_annex_size :: UUID -> Stat
|
|
|
|
remote_annex_size u = simpleStat "remote annex size" $
|
2015-04-12 18:08:40 +00:00
|
|
|
lift . showSizeKeys =<< cachedRemoteData u
|
2015-01-13 22:11:03 +00:00
|
|
|
|
2013-10-28 19:04:38 +00:00
|
|
|
known_annex_files :: Stat
|
|
|
|
known_annex_files = stat "annexed files in working tree" $ json show $
|
|
|
|
countKeys <$> cachedReferencedData
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2012-03-22 03:23:23 +00:00
|
|
|
known_annex_size :: Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
known_annex_size = simpleStat "size of annexed files in working tree" $
|
2015-04-12 18:08:40 +00:00
|
|
|
lift . showSizeKeys =<< cachedReferencedData
|
2012-03-22 03:23:23 +00:00
|
|
|
|
|
|
|
tmp_size :: Stat
|
2014-02-26 20:52:56 +00:00
|
|
|
tmp_size = staleSize "temporary object directory size" gitAnnexTmpObjectDir
|
2012-03-22 03:23:23 +00:00
|
|
|
|
|
|
|
bad_data_size :: Stat
|
|
|
|
bad_data_size = staleSize "bad keys size" gitAnnexBadDir
|
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
key_size :: Key -> Stat
|
2015-04-12 18:08:40 +00:00
|
|
|
key_size k = simpleStat "size" $ lift $ showSizeKeys $ foldKeys [k]
|
2014-10-21 17:24:15 +00:00
|
|
|
|
|
|
|
key_name :: Key -> Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
key_name k = simpleStat "key" $ pure $ key2file k
|
2014-10-21 17:24:15 +00:00
|
|
|
|
2012-03-12 20:18:14 +00:00
|
|
|
bloom_info :: Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
bloom_info = simpleStat "bloom filter size" $ do
|
2012-03-12 20:18:14 +00:00
|
|
|
localkeys <- countKeys <$> cachedPresentData
|
|
|
|
capacity <- fromIntegral <$> lift Command.Unused.bloomCapacity
|
|
|
|
let note = aside $
|
|
|
|
if localkeys >= capacity
|
|
|
|
then "appears too small for this repository; adjust annex.bloomcapacity"
|
2012-04-29 21:48:07 +00:00
|
|
|
else showPercentage 1 (percentage capacity localkeys) ++ " full"
|
2012-03-12 20:18:14 +00:00
|
|
|
|
|
|
|
-- Two bloom filters are used at the same time, so double the size
|
|
|
|
-- of one.
|
2015-04-12 18:08:40 +00:00
|
|
|
sizer <- lift mkSizer
|
|
|
|
size <- sizer memoryUnits False . (* 2) . fromIntegral . fst <$>
|
2012-03-12 20:18:14 +00:00
|
|
|
lift Command.Unused.bloomBitsHashes
|
|
|
|
|
|
|
|
return $ size ++ note
|
|
|
|
|
2012-07-01 20:59:54 +00:00
|
|
|
transfer_list :: Stat
|
|
|
|
transfer_list = stat "transfers in progress" $ nojson $ lift $ do
|
|
|
|
uuidmap <- Remote.remoteMap id
|
|
|
|
ts <- getTransfers
|
2013-09-25 07:09:06 +00:00
|
|
|
return $ if null ts
|
|
|
|
then "none"
|
|
|
|
else multiLine $
|
|
|
|
map (uncurry $ line uuidmap) $ sort ts
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
line uuidmap t i = unwords
|
|
|
|
[ showLcDirection (transferDirection t) ++ "ing"
|
|
|
|
, fromMaybe (key2file $ transferKey t) (associatedFile i)
|
|
|
|
, if transferDirection t == Upload then "to" else "from"
|
|
|
|
, maybe (fromUUID $ transferUUID t) Remote.name $
|
|
|
|
M.lookup (transferUUID t) uuidmap
|
|
|
|
]
|
2012-07-01 20:59:54 +00:00
|
|
|
|
2012-03-22 01:55:02 +00:00
|
|
|
disk_size :: Stat
|
2014-10-21 18:36:09 +00:00
|
|
|
disk_size = simpleStat "available local disk space" $ lift $
|
2012-03-22 21:09:54 +00:00
|
|
|
calcfree
|
2013-01-01 17:52:47 +00:00
|
|
|
<$> (annexDiskReserve <$> Annex.getGitConfig)
|
2012-03-22 21:09:54 +00:00
|
|
|
<*> inRepo (getDiskFree . gitAnnexDir)
|
2015-04-12 18:08:40 +00:00
|
|
|
<*> mkSizer
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-04-12 18:08:40 +00:00
|
|
|
calcfree reserve (Just have) sizer = unwords
|
|
|
|
[ sizer storageUnits False $ nonneg $ have - reserve
|
|
|
|
, "(+" ++ sizer storageUnits False reserve
|
2012-11-12 05:05:04 +00:00
|
|
|
, "reserved)"
|
|
|
|
]
|
2015-04-12 18:08:40 +00:00
|
|
|
calcfree _ _ _ = "unknown"
|
2012-11-12 05:05:04 +00:00
|
|
|
|
|
|
|
nonneg x
|
|
|
|
| x >= 0 = x
|
|
|
|
| otherwise = 0
|
2012-03-22 01:55:02 +00:00
|
|
|
|
2011-05-17 01:18:34 +00:00
|
|
|
backend_usage :: Stat
|
2011-11-20 18:12:48 +00:00
|
|
|
backend_usage = stat "backend usage" $ nojson $
|
2012-03-11 21:15:58 +00:00
|
|
|
calc
|
|
|
|
<$> (backendsKeys <$> cachedReferencedData)
|
|
|
|
<*> (backendsKeys <$> cachedPresentData)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
calc x y = multiLine $
|
|
|
|
map (\(n, b) -> b ++ ": " ++ show n) $
|
2014-10-09 19:35:19 +00:00
|
|
|
sortBy (flip compare) $ map swap $ M.toList $
|
2012-11-12 05:05:04 +00:00
|
|
|
M.unionWith (+) x y
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2013-09-15 23:10:38 +00:00
|
|
|
numcopies_stats :: Stat
|
2013-10-07 08:06:10 +00:00
|
|
|
numcopies_stats = stat "numcopies stats" $ nojson $
|
|
|
|
calc <$> (maybe M.empty numCopiesVarianceMap <$> cachedNumCopiesStats)
|
2013-09-15 23:10:38 +00:00
|
|
|
where
|
2013-10-07 08:06:10 +00:00
|
|
|
calc = multiLine
|
|
|
|
. map (\(variance, count) -> show variance ++ ": " ++ show count)
|
2014-10-09 19:35:19 +00:00
|
|
|
. sortBy (flip (comparing snd)) . M.toList
|
2013-09-15 23:10:38 +00:00
|
|
|
|
2015-04-12 16:49:11 +00:00
|
|
|
reposizes_stats :: Stat
|
|
|
|
reposizes_stats = stat "repositories containing these files" $ nojson $
|
2015-04-12 18:08:40 +00:00
|
|
|
calc
|
|
|
|
<$> lift uuidDescriptions
|
|
|
|
<*> lift mkSizer
|
|
|
|
<*> cachedRepoData
|
2015-04-12 16:49:11 +00:00
|
|
|
where
|
2015-04-12 18:08:40 +00:00
|
|
|
calc descm sizer = multiLine
|
2015-04-12 16:49:11 +00:00
|
|
|
. format
|
2015-04-12 18:08:40 +00:00
|
|
|
. map (\(u, d) -> line descm sizer u d)
|
2015-04-12 16:49:11 +00:00
|
|
|
. sortBy (flip (comparing (sizeKeys . snd))) . M.toList
|
2015-04-12 18:08:40 +00:00
|
|
|
line descm sizer u d = (sz, fromUUID u ++ " -- " ++ desc)
|
2015-04-12 16:49:11 +00:00
|
|
|
where
|
2015-04-12 18:08:40 +00:00
|
|
|
sz = sizer storageUnits True (sizeKeys d)
|
2015-04-12 16:49:11 +00:00
|
|
|
desc = fromMaybe "" (M.lookup u descm)
|
|
|
|
format l = map (\(c1, c2) -> lpad maxc1 c1 ++ ": " ++ c2 ) l
|
|
|
|
where
|
|
|
|
maxc1 = maximum (map (length . fst) l)
|
|
|
|
lpad n s = (replicate (n - length s) ' ') ++ s
|
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
cachedPresentData :: StatState KeyData
|
|
|
|
cachedPresentData = do
|
2011-05-17 01:18:34 +00:00
|
|
|
s <- get
|
2012-03-11 21:15:58 +00:00
|
|
|
case presentData s of
|
2011-05-17 01:18:34 +00:00
|
|
|
Just v -> return v
|
|
|
|
Nothing -> do
|
2014-03-07 16:43:56 +00:00
|
|
|
v <- foldKeys <$> lift (getKeysPresent InRepository)
|
2012-03-11 21:15:58 +00:00
|
|
|
put s { presentData = Just v }
|
|
|
|
return v
|
2011-05-17 01:18:34 +00:00
|
|
|
|
2015-01-13 22:11:03 +00:00
|
|
|
cachedRemoteData :: UUID -> StatState KeyData
|
|
|
|
cachedRemoteData u = do
|
|
|
|
s <- get
|
2015-04-12 16:49:11 +00:00
|
|
|
case M.lookup u (repoData s) of
|
2015-01-13 22:11:03 +00:00
|
|
|
Just v -> return v
|
|
|
|
Nothing -> do
|
|
|
|
v <- foldKeys <$> lift (loggedKeysFor u)
|
2015-04-12 16:49:11 +00:00
|
|
|
put s { repoData = M.insert u v (repoData s) }
|
2015-01-13 22:11:03 +00:00
|
|
|
return v
|
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
cachedReferencedData :: StatState KeyData
|
|
|
|
cachedReferencedData = do
|
2011-05-17 01:18:34 +00:00
|
|
|
s <- get
|
2012-03-11 21:15:58 +00:00
|
|
|
case referencedData s of
|
2011-05-17 01:18:34 +00:00
|
|
|
Just v -> return v
|
|
|
|
Nothing -> do
|
2012-03-11 21:15:58 +00:00
|
|
|
!v <- lift $ Command.Unused.withKeysReferenced
|
|
|
|
emptyKeyData addKey
|
|
|
|
put s { referencedData = Just v }
|
|
|
|
return v
|
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
-- currently only available for directory info
|
2013-09-15 23:10:38 +00:00
|
|
|
cachedNumCopiesStats :: StatState (Maybe NumCopiesStats)
|
|
|
|
cachedNumCopiesStats = numCopiesStats <$> get
|
|
|
|
|
2015-04-12 16:49:11 +00:00
|
|
|
-- currently only available for directory info
|
|
|
|
cachedRepoData :: StatState (M.Map UUID KeyData)
|
|
|
|
cachedRepoData = repoData <$> get
|
|
|
|
|
2014-10-21 17:24:15 +00:00
|
|
|
getDirStatInfo :: FilePath -> Annex StatInfo
|
|
|
|
getDirStatInfo dir = do
|
2013-09-15 23:17:56 +00:00
|
|
|
fast <- Annex.getState Annex.fast
|
2013-03-11 05:22:56 +00:00
|
|
|
matcher <- Limit.getMatcher
|
2015-04-12 16:49:11 +00:00
|
|
|
(presentdata, referenceddata, numcopiesstats, repodata) <-
|
2013-03-11 05:22:56 +00:00
|
|
|
Command.Unused.withKeysFilesReferencedIn dir initial
|
2013-09-15 23:17:56 +00:00
|
|
|
(update matcher fast)
|
2015-04-12 16:49:11 +00:00
|
|
|
return $ StatInfo (Just presentdata) (Just referenceddata) repodata (Just numcopiesstats)
|
2013-03-11 05:22:56 +00:00
|
|
|
where
|
2015-04-12 16:49:11 +00:00
|
|
|
initial = (emptyKeyData, emptyKeyData, emptyNumCopiesStats, M.empty)
|
|
|
|
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats, repodata) =
|
2014-01-18 18:51:55 +00:00
|
|
|
ifM (matcher $ MatchingFile $ FileInfo file file)
|
2013-10-07 06:48:39 +00:00
|
|
|
( do
|
|
|
|
!presentdata' <- ifM (inAnnex key)
|
2013-03-11 05:22:56 +00:00
|
|
|
( return $ addKey key presentdata
|
|
|
|
, return presentdata
|
|
|
|
)
|
2013-10-07 06:48:39 +00:00
|
|
|
let !referenceddata' = addKey key referenceddata
|
2015-04-12 16:49:11 +00:00
|
|
|
(!numcopiesstats', !repodata') <- if fast
|
|
|
|
then return (numcopiesstats, repodata)
|
|
|
|
else do
|
|
|
|
locs <- Remote.keyLocations key
|
|
|
|
nc <- updateNumCopiesStats file numcopiesstats locs
|
|
|
|
return (nc, updateRepoData key locs repodata)
|
|
|
|
return $! (presentdata', referenceddata', numcopiesstats', repodata')
|
2013-03-11 05:22:56 +00:00
|
|
|
, return vs
|
|
|
|
)
|
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
emptyKeyData :: KeyData
|
|
|
|
emptyKeyData = KeyData 0 0 0 M.empty
|
2011-09-20 22:57:05 +00:00
|
|
|
|
2013-09-15 23:10:38 +00:00
|
|
|
emptyNumCopiesStats :: NumCopiesStats
|
2013-10-07 08:06:10 +00:00
|
|
|
emptyNumCopiesStats = NumCopiesStats M.empty
|
2013-09-15 23:10:38 +00:00
|
|
|
|
2012-03-11 21:15:58 +00:00
|
|
|
foldKeys :: [Key] -> KeyData
|
|
|
|
foldKeys = foldl' (flip addKey) emptyKeyData
|
|
|
|
|
|
|
|
addKey :: Key -> KeyData -> KeyData
|
|
|
|
addKey key (KeyData count size unknownsize backends) =
|
|
|
|
KeyData count' size' unknownsize' backends'
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
{- All calculations strict to avoid thunks when repeatedly
|
|
|
|
- applied to many keys. -}
|
|
|
|
!count' = count + 1
|
2015-04-12 16:49:11 +00:00
|
|
|
!backends' = M.insertWith (+) (keyBackendName key) 1 backends
|
2012-11-12 05:05:04 +00:00
|
|
|
!size' = maybe size (+ size) ks
|
|
|
|
!unknownsize' = maybe (unknownsize + 1) (const unknownsize) ks
|
|
|
|
ks = keySize key
|
2012-03-11 21:15:58 +00:00
|
|
|
|
2015-04-12 16:49:11 +00:00
|
|
|
updateRepoData :: Key -> [UUID] -> M.Map UUID KeyData -> M.Map UUID KeyData
|
|
|
|
updateRepoData key locs m = m'
|
|
|
|
where
|
|
|
|
!m' = M.unionWith (\_old new -> new) m $
|
|
|
|
M.fromList $ zip locs (map update locs)
|
|
|
|
update loc = addKey key (fromMaybe emptyKeyData $ M.lookup loc m)
|
|
|
|
|
|
|
|
updateNumCopiesStats :: FilePath -> NumCopiesStats -> [UUID] -> Annex NumCopiesStats
|
|
|
|
updateNumCopiesStats file (NumCopiesStats m) locs = do
|
|
|
|
have <- trustExclude UnTrusted locs
|
|
|
|
!variance <- Variance <$> numCopiesCheck' file (-) have
|
|
|
|
let !m' = M.insertWith (+) variance 1 m
|
2013-10-07 08:06:10 +00:00
|
|
|
let !ret = NumCopiesStats m'
|
2013-10-07 06:48:39 +00:00
|
|
|
return ret
|
2013-09-15 23:10:38 +00:00
|
|
|
|
2015-04-12 18:08:40 +00:00
|
|
|
showSizeKeys :: KeyData -> Annex String
|
|
|
|
showSizeKeys d = do
|
|
|
|
sizer <- mkSizer
|
|
|
|
return $ total sizer ++ missingnote
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2015-04-12 18:08:40 +00:00
|
|
|
total sizer = sizer storageUnits False $ sizeKeys d
|
2012-11-12 05:05:04 +00:00
|
|
|
missingnote
|
|
|
|
| unknownSizeKeys d == 0 = ""
|
|
|
|
| otherwise = aside $
|
|
|
|
"+ " ++ show (unknownSizeKeys d) ++
|
2013-10-28 19:04:38 +00:00
|
|
|
" unknown size"
|
2011-05-17 02:01:50 +00:00
|
|
|
|
|
|
|
staleSize :: String -> (Git.Repo -> FilePath) -> Stat
|
2013-10-10 21:27:00 +00:00
|
|
|
staleSize label dirspec = go =<< lift (dirKeys dirspec)
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
go [] = nostat
|
|
|
|
go keys = onsize =<< sum <$> keysizes keys
|
|
|
|
onsize 0 = nostat
|
|
|
|
onsize size = stat label $
|
2015-04-12 18:08:40 +00:00
|
|
|
json (++ aside "clean up with git-annex unused") $ do
|
|
|
|
sizer <- lift mkSizer
|
|
|
|
return $ sizer storageUnits False size
|
2013-10-13 17:30:24 +00:00
|
|
|
keysizes keys = do
|
2012-11-12 05:05:04 +00:00
|
|
|
dir <- lift $ fromRepo dirspec
|
2013-10-13 17:30:24 +00:00
|
|
|
liftIO $ forM keys $ \k -> catchDefaultIO 0 $
|
2015-01-20 20:58:48 +00:00
|
|
|
getFileSize (dir </> keyFile k)
|
2011-05-17 02:49:41 +00:00
|
|
|
|
|
|
|
aside :: String -> String
|
2011-09-30 07:05:10 +00:00
|
|
|
aside s = " (" ++ s ++ ")"
|
2012-10-02 17:45:30 +00:00
|
|
|
|
|
|
|
multiLine :: [String] -> String
|
|
|
|
multiLine = concatMap (\l -> "\n\t" ++ l)
|
2015-04-12 18:08:40 +00:00
|
|
|
|
|
|
|
mkSizer :: Annex ([Unit] -> Bool -> ByteSize -> String)
|
|
|
|
mkSizer = ifM (getOptionFlag bytesOption)
|
|
|
|
( return (const $ const show)
|
|
|
|
, return roughSize
|
|
|
|
)
|
|
|
|
|
|
|
|
bytesOption :: Option
|
|
|
|
bytesOption = flagOption [] "bytes" "display file sizes in bytes"
|