summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-26 16:15:43 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-26 16:18:01 -0400
commit52f9c68869fa8956db55980f0b36ba817f825ffb (patch)
treeb288b73ee5766a0048b1e2d593a0d0ec130044c0 /Types.hs
parent62f7653e39e95d3e9cd308810e487e3cdee84d52 (diff)
downloaddebug-me-52f9c68869fa8956db55980f0b36ba817f825ffb.tar.gz
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.
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs23
1 files changed, 21 insertions, 2 deletions
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