Created
August 29, 2012 21:00
-
-
Save RayRoestenburg/3518897 to your computer and use it in GitHub Desktop.
Timingdiagnostics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class TimeDataRequest(id:Long) | |
/** | |
* A Diagnostics that records timing based on the Id of the message | |
*/ | |
trait TimingDiagnostics extends Diagnostics[(Long,Long),TimeDataRequest] { | |
private var map = Map[Long, Long]() | |
var timeBefore:Long = 0 | |
def diagnoseBefore:Receive = { | |
case m:HasId => | |
timeBefore = now | |
case _ => | |
} | |
def diagnoseAfter:Receive = { | |
case m:HasId => | |
map = map + (m.id -> (now - timeBefore)) | |
case _ => | |
} | |
def collect(req:TimeDataRequest) = map.get(req.id).map( (req.id, _)) | |
} | |
trait HasId { | |
def id:Long | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment