Properly measure request time using Time.monotonic

This commit is contained in:
Serdar Dogruyol 2019-03-20 01:02:42 -07:00 committed by GitHub
commit 5267555322
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,10 +5,9 @@ module Kemal
end
def call(context : HTTP::Server::Context)
time = Time.now
call_next(context)
elapsed_text = elapsed_text(Time.now - time)
@io << time << ' ' << context.response.status_code << ' ' << context.request.method << ' ' << context.request.resource << ' ' << elapsed_text << '\n'
elapsed_time = Time.measure { call_next(context) }
elapsed_text = elapsed_text(elapsed_time)
@io << Time.now << ' ' << context.response.status_code << ' ' << context.request.method << ' ' << context.request.resource << ' ' << elapsed_text << '\n'
context
end