From 83ad1f3c95a7eac5f85f37da914d85fa7ce4cd23 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 2 Nov 2009 11:45:29 +0100 Subject: [PATCH] hspace: show tiered-alloc stats in the output This is a first attempt to get a readable output of tiered allocation stats in hspace's output. Not very nice, but it should be somewhat parseable. --- Ganeti/HTools/Instance.hs | 6 ++++++ Ganeti/HTools/Types.hs | 2 +- hspace.hs | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Ganeti/HTools/Instance.hs b/Ganeti/HTools/Instance.hs index 72b27dadc..752ab7e1f 100644 --- a/Ganeti/HTools/Instance.hs +++ b/Ganeti/HTools/Instance.hs @@ -36,6 +36,7 @@ module Ganeti.HTools.Instance , setPri , setSec , setBoth + , specOf , shrinkByType ) where @@ -152,3 +153,8 @@ shrinkByType inst T.FailCPU = let v = vcpus inst - unitCpu then T.Bad "out of vcpus" else T.Ok inst { vcpus = v } shrinkByType _ f = T.Bad $ "Unhandled failure mode " ++ show f + +-- | Return the spec of an instance. +specOf :: Instance -> T.RSpec +specOf Instance { mem = m, dsk = d, vcpus = c } = + T.RSpec { T.rspecCpu = c, T.rspecMem = m, T.rspecDsk = d } diff --git a/Ganeti/HTools/Types.hs b/Ganeti/HTools/Types.hs index ba0cf7dba..1151cec88 100644 --- a/Ganeti/HTools/Types.hs +++ b/Ganeti/HTools/Types.hs @@ -68,7 +68,7 @@ data RSpec = RSpec { rspecCpu :: Int -- ^ Requested VCPUs , rspecMem :: Int -- ^ Requested memory , rspecDsk :: Int -- ^ Requested disk - } deriving (Show) + } deriving (Show, Eq) -- | The dynamic resource specs of a machine (i.e. load or load -- capacity, as opposed to size). diff --git a/hspace.hs b/hspace.hs index 7b01fbefd..ad9b788f1 100644 --- a/hspace.hs +++ b/hspace.hs @@ -293,18 +293,27 @@ main = do let tresu = tieredAlloc nl il (iofspec tspec) req_nodes [] (_, trl_nl, trl_ixes) <- exitifbad tresu let fin_trl_ixes = reverse trl_ixes + ix_byspec = groupBy ((==) `on` Instance.specOf) fin_trl_ixes + spec_map = map (\ixs -> (Instance.specOf $ head ixs, length ixs)) + ix_byspec::[(RSpec, Int)] + spec_map' = map (\(idx, (spec, cnt)) -> + printf "%dx%dx%dx%d=%d" idx (rspecCpu spec) + (rspecMem spec) (rspecDsk spec) cnt) + $ zip ([1..]::[Int]) spec_map::[String] when (verbose > 1) $ do hPutStrLn stderr "Tiered allocation map" hPutStr stderr . unlines . map ((:) ' ' . intercalate " ") $ formatTable (map (printInstance trl_nl) fin_trl_ixes) [False, False, False, True, True, True] + when (optShowNodes opts) $ do hPutStrLn stderr "" hPutStrLn stderr "Tiered allocation status:" hPutStrLn stderr $ Cluster.printNodes trl_nl - printKeys $ printStats PTiered (Cluster.totalResources trl_nl)) + printKeys $ printStats PTiered (Cluster.totalResources trl_nl) + printKeys [("TSPEC", intercalate " " spec_map')]) -- Run the standard (avg-mode) allocation -- GitLab