Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created June 9, 2012 11:50
Show Gist options
  • Save guillaumebort/2900670 to your computer and use it in GitHub Desktop.
Save guillaumebort/2900670 to your computer and use it in GitHub Desktop.
Track response time of simple Action
import play.api._
import play.api.mvc._
object Global extends GlobalSettings {
def ResponseTime[A](action: Action[A]): Action[A] = Action(action.parser) { request =>
val start = System.currentTimeMillis
val result = action(request)
println( request + " -> " + (System.currentTimeMillis - start) + " ms.")
result
}
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
super.onRouteRequest(request).map {
case action: Action[_] => ResponseTime(action)
case other => other
}
}
}
@diegovar
Copy link

Will this work with Async Actions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment