Commit 163ed855 authored by Yiannis Tsiouris's avatar Yiannis Tsiouris

Make Stats type more module-specific

parent 0a8089a2
...@@ -7,15 +7,17 @@ import Control.Distributed.Process (Process, ProcessId, NodeId, ...@@ -7,15 +7,17 @@ import Control.Distributed.Process (Process, ProcessId, NodeId,
match, receiveWait) match, receiveWait)
import Credit (credit, is_one) import Credit (credit, is_one)
import qualified Sequential as Sq (Generator, orbit) import qualified Sequential as Sq (Generator, orbit)
import Table (Stats, Vertex, freq_from_stat, import Table (Vertex, freq_from_stat,
freq_to_stat, sum_freqs) freq_to_stat, sum_freqs)
import Worker (credit_retd_from_stat, import Worker (WorkerStats,
credit_retd_from_stat,
init_idle_from_stat, init_idle_from_stat,
max_idle_from_stat, max_idle_from_stat,
min_atomic_credit_from_stat, min_atomic_credit_from_stat,
tail_idle_from_stat, tail_idle_from_stat,
verts_recvd_from_stat) verts_recvd_from_stat)
type MasterStats = [(String, String)]
data MaybeHosts = Seq Int data MaybeHosts = Seq Int
| Par HostInfo | Par HostInfo
data HostInfo = JustOne (Int, -- Number of processes data HostInfo = JustOne (Int, -- Number of processes
...@@ -91,22 +93,14 @@ type ParConf = ([Sq.Generator], ProcessId, [ProcessId], Int, Int, Bool) ...@@ -91,22 +93,14 @@ type ParConf = ([Sq.Generator], ProcessId, [ProcessId], Int, Int, Bool)
-- The function returns a pair consisting of the computed orbit and -- The function returns a pair consisting of the computed orbit and
-- a list of statistics, the first element of which reports overall statistics, -- a list of statistics, the first element of which reports overall statistics,
-- and all remaining elements report statistics of some worker. -- and all remaining elements report statistics of some worker.
orbit :: [Vertex -> Vertex] -> [Vertex] -> MaybeHosts -> ([Vertex], [Stats]) orbit :: [Vertex -> Vertex] -> [Vertex] -> MaybeHosts -> ([Vertex], [MasterStats])
orbit gs xs (Seq tablesize) = Sq.orbit gs xs tablesize orbit gs xs (Seq tablesize) = Sq.orbit gs xs tablesize
orbit gs xs (Par hostInfo) = par_orbit gs xs hostInfo orbit gs xs (Par hostInfo) = par_orbit gs xs hostInfo
-- FIXME Write the proper par_orbit -- FIXME Write the proper par_orbit
par_orbit :: [Vertex -> Vertex] -> [Vertex] -> HostInfo -> ([Vertex], [Stats]) par_orbit :: [Vertex -> Vertex] -> [Vertex] -> HostInfo -> ([Vertex], [MasterStats])
par_orbit gs xs hosts = ([42], [[("xxx", "xxx")]]) par_orbit gs xs hosts = ([42], [[("xxx", "xxx")]])
-- collect_credit collects leftover credit from idle workers until -- collect_credit collects leftover credit from idle workers until
-- the credit adds up to 1. -- the credit adds up to 1.
collect_credit :: [Int] -> Process () collect_credit :: [Int] -> Process ()
...@@ -119,12 +113,12 @@ collect_credit crdt = ...@@ -119,12 +113,12 @@ collect_credit crdt =
] ]
-- collect_orbit collects partial orbits and stats from N workers. -- collect_orbit collects partial orbits and stats from N workers.
collect_orbit :: Int -> Int -> Process ([Vertex], [Stats]) collect_orbit :: Int -> Int -> Process ([Vertex], [MasterStats])
collect_orbit elapsedTime n = do collect_orbit elapsedTime n = do
(orbit, stats) <- do_collect_orbit n [] [] (orbit, stats) <- do_collect_orbit n [] []
return (concat orbit, master_stats elapsedTime stats : stats) return (concat orbit, master_stats elapsedTime stats : stats)
do_collect_orbit :: Int -> [[Vertex]] -> [Stats] -> Process ([[Vertex]], [Stats]) do_collect_orbit :: Int -> [[Vertex]] -> [WorkerStats] -> Process ([[Vertex]], [WorkerStats])
do_collect_orbit 0 partOrbits workerStats = return (partOrbits, workerStats) do_collect_orbit 0 partOrbits workerStats = return (partOrbits, workerStats)
do_collect_orbit n partOrbits workerStats = do do_collect_orbit n partOrbits workerStats = do
receiveWait [ receiveWait [
...@@ -165,8 +159,9 @@ clear_spawn_img_comp :: ParConf -> ParConf ...@@ -165,8 +159,9 @@ clear_spawn_img_comp :: ParConf -> ParConf
clear_spawn_img_comp (gs, mst, wks, gts, tmt, spawmImgComp) = (gs, mst, wks, gts, tmt, False) clear_spawn_img_comp (gs, mst, wks, gts, tmt, spawmImgComp) = (gs, mst, wks, gts, tmt, False)
-- produce readable statistics -- produce readable statistics
master_stats :: Int -> [Stats] -> Stats master_stats :: Int -> [WorkerStats] -> MasterStats
master_stats elapsedTime workerStats = ("wall_time", show elapsedTime) master_stats elapsedTime workerStats =
("wall_time", show elapsedTime)
: ("vertices_recvd", show vertsRecvd) : ("vertices_recvd", show vertsRecvd)
: ("credit_retd", show creditRetd) : ("credit_retd", show creditRetd)
: ("min_atomic_credit", show minAtomicCredit) : ("min_atomic_credit", show minAtomicCredit)
......
...@@ -10,13 +10,13 @@ module Sequential( -- Types ...@@ -10,13 +10,13 @@ module Sequential( -- Types
import Data.Dequeue (BankersDequeue, fromList, popFront, pushBack) import Data.Dequeue (BankersDequeue, fromList, popFront, pushBack)
import Data.Hashable (hash) import Data.Hashable (hash)
import Table (Freq, Stats, Vertex, VTable, import Table (Freq, Vertex, VTable, freq_to_stat, get_freq,
freq_to_stat, get_freq, insert, is_member, new, insert, is_member, new, to_list)
to_list)
import Utils (now) import Utils (now)
type Generator = Vertex -> Vertex type Generator = Vertex -> Vertex
type SeqConf = ([Generator], Int) type SeqConf = ([Generator], Int)
type SeqStats = [(String, String)]
-- DATA -- DATA
-- Static Machine Configuration: -- Static Machine Configuration:
...@@ -32,7 +32,7 @@ type SeqConf = ([Generator], Int) ...@@ -32,7 +32,7 @@ type SeqConf = ([Generator], Int)
-- where the hash table is of size TableSize. -- where the hash table is of size TableSize.
-- The function returns a pair consisting of the computed orbit and a singleton -- The function returns a pair consisting of the computed orbit and a singleton
-- list of statistics (mainly runtime and fill degree of the table). -- list of statistics (mainly runtime and fill degree of the table).
orbit :: [Generator] -> [Vertex] -> Int -> ([Vertex], [Stats]) orbit :: [Generator] -> [Vertex] -> Int -> ([Vertex], [SeqStats])
orbit gs xs tableSize = (orbit, [stat]) orbit gs xs tableSize = (orbit, [stat])
where -- assemble static configuration where -- assemble static configuration
staticMachConf = mk_static_mach_conf gs tableSize staticMachConf = mk_static_mach_conf gs tableSize
...@@ -99,7 +99,9 @@ get_table_size :: SeqConf -> Int ...@@ -99,7 +99,9 @@ get_table_size :: SeqConf -> Int
get_table_size staticMachConf = snd staticMachConf get_table_size staticMachConf = snd staticMachConf
-- produce readable statistics -- produce readable statistics
seq_stats :: Int -> Freq -> Int -> Stats seq_stats :: Int -> Freq -> Int -> SeqStats
seq_stats elapsedTime frequency vertsRecvd = seq_stats elapsedTime frequency vertsRecvd =
("wall_time", show elapsedTime) : ("vertices_recvd", show vertsRecvd) : freq_to_stat frequency ("wall_time", show elapsedTime)
: ("vertices_recvd", show vertsRecvd)
: freq_to_stat frequency
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
-- --
module Table( -- Types module Table( -- Types
Freq Freq
, Stats
, VTable , VTable
, Vertex , Vertex
-- Functions -- Functions
...@@ -30,7 +29,7 @@ import Data.Array (Array, elems, listArray, (!), (//)) ...@@ -30,7 +29,7 @@ import Data.Array (Array, elems, listArray, (!), (//))
type Freq = [Int] type Freq = [Int]
type Vertex = Int type Vertex = Int
type VTable = Array Int [Vertex] type VTable = Array Int [Vertex]
type Stats = [(String, String)] type TableStats = [(String, String)]
-- Note: Hash tables have a fixed number of slots but each slot can store -- Note: Hash tables have a fixed number of slots but each slot can store
-- a list of vertices. The functions is_member/3 and insert/3 -- a list of vertices. The functions is_member/3 and insert/3
...@@ -106,22 +105,20 @@ sum_freqs fs = foldl (flip sum_freqs2) [] fs ...@@ -106,22 +105,20 @@ sum_freqs fs = foldl (flip sum_freqs2) [] fs
-- freq_to_stat produces a readable statistics from a table fill frequency; -- freq_to_stat produces a readable statistics from a table fill frequency;
-- the input frequency F is itself part of the statistics -- the input frequency F is itself part of the statistics
freq_to_stat :: Freq -> Stats freq_to_stat :: Freq -> TableStats
freq_to_stat frequency = [ ("freq", show frequency) freq_to_stat frequency =
[ ("freq", show frequency)
, ("size", show $ freq_to_vertices frequency) , ("size", show $ freq_to_vertices frequency)
, ("slots", show $ freq_to_slots frequency) , ("slots", show $ freq_to_slots frequency)
, ("nonempty_slots", , ("nonempty_slots", show $ freq_to_nonempty_slots frequency)
show $ freq_to_nonempty_slots frequency)
, ("fill_deg", show $ fill_deg frequency) , ("fill_deg", show $ fill_deg frequency)
, ("max_freq", show $ max_freq frequency) , ("max_freq", show $ max_freq frequency)
, ("avg_freq", show $ avg_freq frequency) , ("avg_freq", show $ avg_freq frequency)
, ("nonempty_avg_freq", , ("nonempty_avg_freq", show $ avg_nonempty_freq frequency) ]
show $ avg_nonempty_freq frequency)
]
-- freq_from_stat extracts a table fill frequency from a statistics Stat -- freq_from_stat extracts a table fill frequency from a statistics Stat
-- (assuming Stat was produced by freq_to_stat/1, otherwise returns []); -- (assuming Stat was produced by freq_to_stat/1, otherwise returns []);
freq_from_stat :: Stats -> Freq freq_from_stat :: TableStats -> Freq
freq_from_stat stat = freq_from_stat stat =
case "freq" `lookup` stat of case "freq" `lookup` stat of
Just val -> read val :: [Int] Just val -> read val :: [Int]
......
...@@ -10,23 +10,28 @@ module Worker( --init ...@@ -10,23 +10,28 @@ module Worker( --init
, init_idle_from_stat , init_idle_from_stat
, tail_idle_from_stat , tail_idle_from_stat
, max_idle_from_stat , max_idle_from_stat
, WorkerStats
) where ) where
import Control.Distributed.Process (NodeId) import Control.Distributed.Process (NodeId)
import Table (Freq, Stats, freq_to_stat) import Table (Freq, freq_to_stat)
import Utils (now) import Utils (now)
type WorkerStats = [(String, String)]
-- counters/timers record -- counters/timers record
data Ct = Ct { data Ct = Ct { verts_recvd :: Int -- #vertices received by this server so far
verts_recvd :: Int -- #vertices received by this server so far , credit_retd :: Int -- #times server has returned credit to
, credit_retd :: Int -- #times server has returned credit to master -- master
, min_atomic_credit :: Int -- minimal atomic credit received so far , min_atomic_credit :: Int -- minimal atomic credit received so far
, last_event :: Int -- time stamp [ms] of most recent event , last_event :: Int -- time stamp [ms] of most recent event
, init_idle :: Int -- idle time [ms] between init recv first vertex , init_idle :: Int -- idle time [ms] between init recv first
, tail_idle :: Int -- idle time [ms] between send last vertex and dump -- vertex
, tail_idle :: Int -- idle time [ms] between send last vertex
-- and dump
, max_idle :: Int -- max idle [ms] time between vertices , max_idle :: Int -- max idle [ms] time between vertices
} }
defaultCt :: Ct defaultCt :: Ct
defaultCt = Ct { verts_recvd = 0 defaultCt = Ct { verts_recvd = 0
...@@ -39,8 +44,9 @@ defaultCt = Ct { verts_recvd = 0 ...@@ -39,8 +44,9 @@ defaultCt = Ct { verts_recvd = 0
} }
-- produce readable statistics -- produce readable statistics
worker_stats :: NodeId -> Freq -> Ct -> Stats worker_stats :: NodeId -> Freq -> Ct -> WorkerStats
worker_stats node frequency statData = ("node", show node) worker_stats node frequency statData =
("node", show node)
: ("vertices_recvd", show $ verts_recvd statData) : ("vertices_recvd", show $ verts_recvd statData)
: ("credit_retd", show $ credit_retd statData) : ("credit_retd", show $ credit_retd statData)
: ("min_atomic_credit", show $ min_atomic_credit statData) : ("min_atomic_credit", show $ min_atomic_credit statData)
...@@ -49,39 +55,38 @@ worker_stats node frequency statData = ("node", show node) ...@@ -49,39 +55,38 @@ worker_stats node frequency statData = ("node", show node)
: ("tail_idle_time", show $ tail_idle statData) : ("tail_idle_time", show $ tail_idle statData)
: freq_to_stat frequency : freq_to_stat frequency
verts_recvd_from_stat :: Stats -> Int verts_recvd_from_stat :: WorkerStats -> Int
verts_recvd_from_stat stat = verts_recvd_from_stat stat =
case "vertices_recvd" `lookup` stat of case "vertices_recvd" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
credit_retd_from_stat :: Stats -> Int credit_retd_from_stat :: WorkerStats -> Int
credit_retd_from_stat stat = credit_retd_from_stat stat =
case "credit_retd" `lookup` stat of case "credit_retd" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
min_atomic_credit_from_stat :: Stats -> Int min_atomic_credit_from_stat :: WorkerStats -> Int
min_atomic_credit_from_stat stat = min_atomic_credit_from_stat stat =
case "min_atomic_credit" `lookup` stat of case "min_atomic_credit" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
init_idle_from_stat :: Stats -> Int init_idle_from_stat :: WorkerStats -> Int
init_idle_from_stat stat = init_idle_from_stat stat =
case "init_idle_time" `lookup` stat of case "init_idle_time" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
tail_idle_from_stat :: Stats -> Int tail_idle_from_stat :: WorkerStats -> Int
tail_idle_from_stat stat = tail_idle_from_stat stat =
case "tail_idle_time" `lookup` stat of case "tail_idle_time" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
max_idle_from_stat :: Stats -> Int max_idle_from_stat :: WorkerStats -> Int
max_idle_from_stat stat = max_idle_from_stat stat =
case "max_idle_time" `lookup` stat of case "max_idle_time" `lookup` stat of
Just val -> read val :: Int Just val -> read val :: Int
Nothing -> 0 -- instead of false Nothing -> 0 -- instead of false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment