@@ -75,6 +75,7 @@ import Data.Bifunctor (Bifunctor (..))
7575import qualified Data.ByteString as BS
7676import Data.Constraint (Dict (.. ))
7777import Data.Kind (Type )
78+ import Data.Map.Strict (Map )
7879import qualified Data.Map.Strict as Map
7980import Data.Maybe (catMaybes , fromJust )
8081import Data.Set (Set )
@@ -471,7 +472,7 @@ instance ( Show (Class.TableConfig h)
471472 Lookups :: C k v blob
472473 => V. Vector k -> Var h (WrapTableHandle h IO k v blob )
473474 -> Act h (V. Vector (R. LookupResult v (WrapBlobRef h IO blob )))
474- RangeLookup :: C k v blob
475+ RangeLookup :: ( C k v blob , Ord k )
475476 => R. Range k -> Var h (WrapTableHandle h IO k v blob )
476477 -> Act h (V. Vector (R. QueryResult k v (WrapBlobRef h IO blob )))
477478 -- Cursor
@@ -677,7 +678,7 @@ instance ( Eq (Class.TableConfig h)
677678 where
678679 auxStats :: (Val h a , Model. Model ) -> (Val h a , ModelState h )
679680 auxStats (result, state') =
680- (result, ModelState state' $ updateStats action result stats)
681+ (result, ModelState state' $ updateStats action lookUp result stats)
681682
682683 usedVars :: LockstepAction (ModelState h ) a -> [AnyGVar (ModelOp (ModelState h ))]
683684 usedVars = \ case
@@ -1299,18 +1300,21 @@ instance InterpretOp Op (ModelValue (ModelState h)) where
12991300data Stats = Stats {
13001301 -- === Tags
13011302 -- | Unique types at which tables were created
1302- newTableTypes :: Set String
1303+ newTableTypes :: Set String
13031304 -- | Names for which snapshots exist
1304- , snapshotted :: Set R. SnapshotName
1305- -- === Final tags
1305+ , snapshotted :: Set R. SnapshotName
1306+ -- === Final tags (per action sequence, across all tables)
13061307 -- | Number of succesful lookups and their results
1307- , numLookupsResults :: (Int , Int , Int ) -- (NotFound, Found, FoundWithBlob)
1308+ , numLookupsResults :: (Int , Int , Int ) -- (NotFound, Found, FoundWithBlob)
13081309 -- | Number of succesful updates
1309- , numUpdates :: (Int , Int , Int ) -- (Insert, InsertWithBlob, Delete)
1310+ , numUpdates :: (Int , Int , Int ) -- (Insert, InsertWithBlob, Delete)
13101311 -- | Actions that succeeded
1311- , successActions :: [String ]
1312+ , successActions :: [String ]
13121313 -- | Actions that failed with an error
1313- , failActions :: [String ]
1314+ , failActions :: [String ]
1315+ -- === Final tags (per action sequence, per table)
1316+ -- | Number of actions per table (succesful or failing)
1317+ , numActionsPerTable :: ! (Map Model. TableHandleID Int )
13141318 }
13151319 deriving stock Show
13161320
@@ -1324,6 +1328,7 @@ initStats = Stats {
13241328 , numUpdates = (0 , 0 , 0 )
13251329 , successActions = []
13261330 , failActions = []
1331+ , numActionsPerTable = Map. empty
13271332 }
13281333
13291334updateStats ::
@@ -1334,10 +1339,11 @@ updateStats ::
13341339 , Typeable h
13351340 )
13361341 => LockstepAction (ModelState h ) a
1342+ -> ModelLookUp (ModelState h )
13371343 -> Val h a
13381344 -> Stats
13391345 -> Stats
1340- updateStats action result =
1346+ updateStats action lookUp result =
13411347 -- === Tags
13421348 updNewTableTypes
13431349 . updSnapshotted
@@ -1346,6 +1352,7 @@ updateStats action result =
13461352 . updNumUpdates
13471353 . updSuccessActions
13481354 . updFailActions
1355+ . updNumActionsPerTable
13491356 where
13501357 -- === Tags
13511358
@@ -1415,6 +1422,65 @@ updateStats action result =
14151422 }
14161423 _ -> stats
14171424
1425+ updNumActionsPerTable :: Stats -> Stats
1426+ updNumActionsPerTable stats = case action of
1427+ New {}
1428+ | MEither (Right (MTableHandle table)) <- result -> initCount table
1429+ | otherwise -> stats
1430+ Open {}
1431+ | MEither (Right (MTableHandle table)) <- result -> initCount table
1432+ | otherwise -> stats
1433+ Duplicate {}
1434+ | MEither (Right (MTableHandle table)) <- result -> initCount table
1435+ | otherwise -> stats
1436+
1437+ -- Note that for the other actions we don't count success vs failure.
1438+ -- We don't need that level of detail. We just want to see the
1439+ -- distribution. Success / failure is detailed elsewhere.
1440+ Lookups _ tableVar -> updateCount tableVar
1441+ RangeLookup _ tableVar -> updateCount tableVar
1442+ NewCursor _ tableVar -> updateCount tableVar
1443+ Updates _ tableVar -> updateCount tableVar
1444+ Inserts _ tableVar -> updateCount tableVar
1445+ Deletes _ tableVar -> updateCount tableVar
1446+ -- Note that we don't remove tracking map entries for tables that get
1447+ -- closed. We want to know actions per table of all tables used, not
1448+ -- just those that were still open at the end of the sequence of
1449+ -- actions. We do also count Close itself as an action.
1450+ Close tableVar -> updateCount tableVar
1451+
1452+ -- The others are not counted as table actions. We list them here
1453+ -- explicitly so we don't miss any new ones we might add later.
1454+ CloseCursor {} -> stats
1455+ ReadCursor {} -> stats
1456+ RetrieveBlobs {} -> stats
1457+ Snapshot {} -> stats
1458+ DeleteSnapshot {} -> stats
1459+ ListSnapshots {} -> stats
1460+ where
1461+ -- Init to 0 so we get an accurate count of tables with no actions.
1462+ initCount :: forall k v blob . Model. TableHandle k v blob -> Stats
1463+ initCount table =
1464+ let tid = Model. tableHandleID table
1465+ in stats {
1466+ numActionsPerTable = Map. insert tid 0 (numActionsPerTable stats)
1467+ }
1468+
1469+ -- Note that batches (of inserts lookups etc) count as one action.
1470+ updateCount :: forall k v blob .
1471+ Var h (WrapTableHandle h IO k v blob )
1472+ -> Stats
1473+ updateCount tableVar =
1474+ let tid = getTableHandleId (lookUp tableVar)
1475+ in stats {
1476+ numActionsPerTable = Map. insertWith (+) tid 1
1477+ (numActionsPerTable stats)
1478+ }
1479+
1480+ getTableHandleId :: ModelValue (ModelState h ) (WrapTableHandle h IO k v blob )
1481+ -> Model. TableHandleID
1482+ getTableHandleId (MTableHandle th) = Model. tableHandleID th
1483+
14181484-- | Tags for every step
14191485data Tag =
14201486 -- | (At least) two types of tables were created (i.e., 'New') in the same
@@ -1523,6 +1589,10 @@ data FinalTag =
15231589 | ActionFail String
15241590 -- | Total number of flushes
15251591 | NumFlushes String -- TODO: implement
1592+ -- | Number of table handles created (new, open or duplicate)
1593+ | NumTables String
1594+ -- | Number of actions on each table
1595+ | NumTableActions String
15261596 -- | Total /logical/ size of a table
15271597 | TableSize String -- TODO: implement
15281598 deriving stock Show
@@ -1534,6 +1604,8 @@ tagFinalState' (getModel -> ModelState _ finalStats) = concat [
15341604 , tagNumUpdates
15351605 , tagSuccessActions
15361606 , tagFailActions
1607+ , tagNumTables
1608+ , tagNumTableActions
15371609 ]
15381610 where
15391611 tagNumLookupsResults = [
@@ -1558,6 +1630,16 @@ tagFinalState' (getModel -> ModelState _ finalStats) = concat [
15581630 [ (" Actions that failed" , [ActionFail c])
15591631 | c <- failActions finalStats ]
15601632
1633+ tagNumTables =
1634+ [ (" Number of tables" , [NumTables (showPowersOf 2 n)])
1635+ | let n = Map. size (numActionsPerTable finalStats)
1636+ ]
1637+
1638+ tagNumTableActions =
1639+ [ (" Number of actions per table" , [ NumTableActions (showPowersOf 2 n) ])
1640+ | n <- Map. elems (numActionsPerTable finalStats)
1641+ ]
1642+
15611643{- ------------------------------------------------------------------------------
15621644 Utils
15631645-------------------------------------------------------------------------------}
0 commit comments