From 52f9c68869fa8956db55980f0b36ba817f825ffb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 26 Apr 2017 16:15:43 -0400 Subject: include elapsedTime in Activity Time is relative, so the debug-me proof chain doesn't prove when things happened, but it's still useful to have some idea of how long things took to happen. This makes --replay work with logs gotten by --download. Log still includes loggedTimestamp. This is a bit redundant, and is unused now, but it's useful for log files to record when messages were received. This commit was sponsored by Riku Voipio. --- Types.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 04855f4..c202f14 100644 --- a/Types.hs +++ b/Types.hs @@ -16,6 +16,8 @@ import Val import Memory import Serialization +import Data.Time.Clock.POSIX + -- | Things that the developer sees. data Seen = Seen { seenData :: Val @@ -48,7 +50,8 @@ instance DataSize a => DataSize (Message a) where dataSize (ControlMessage c) = dataSize c -- | An activity (either Entered or Seen) with a pointer --- to a previous Activity. +-- to a previous Activity, and the amount of time elapsed since the +-- previous Activity. -- -- The Signature is over both the data in the activity, and its pointer. -- @@ -57,13 +60,15 @@ instance DataSize a => DataSize (Message a) where data Activity a = Activity { activity :: a , prevActivity :: Maybe Hash + , elapsedTime :: Maybe ElapsedTime , activitySignature :: Signature } deriving (Show, Generic) instance DataSize a => DataSize (Activity a) where dataSize a = dataSize (activity a) - + maybe 0 dataSize (prevActivity a) + + maybe 0 dataSize (prevActivity a) + + maybe 0 dataSize (elapsedTime a) + dataSize (activitySignature a) -- | A control message, which can be sent asynchronously. @@ -136,11 +141,25 @@ newtype GpgSig = GpgSig Val instance DataSize GpgSig where dataSize (GpgSig s) = dataSize s +-- | Elapsed time in seconds. +newtype ElapsedTime = ElapsedTime Double + deriving (Show, Generic, Eq) + +mkElapsedTime :: POSIXTime -> POSIXTime -> ElapsedTime +mkElapsedTime start end = ElapsedTime $ fromRational $ toRational (end - start) + +instance DataSize ElapsedTime where + dataSize _ = 16 -- 128 bit Double + data LogMessage = User (Message Seen) | Developer (Message Entered) deriving (Show, Generic) +instance Binary ElapsedTime +instance ToJSON ElapsedTime +instance FromJSON ElapsedTime + instance DataSize LogMessage where dataSize (User a) = dataSize a dataSize (Developer a) = dataSize a -- cgit v1.2.3