-
Notifications
You must be signed in to change notification settings - Fork 208
use Stopwatch for ElapsedMilliseconds #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,20 +53,19 @@ public async Task Invoke(HttpContext httpContext) | |
{ | ||
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext)); | ||
|
||
var start = Stopwatch.GetTimestamp(); | ||
var stopwatch = Stopwatch.StartNew(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this is less cryptic for people scanning (and I also agree that the math is v error prone wrt overflow and/or getting int64 vs double conversions wrong), this line does allocate so I went the other way in my helpers in https://github.com/jet/propulsion/blob/master/src/Propulsion/Internal.fs#L9-L18 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 the shift to |
||
|
||
var collector = _diagnosticContext.BeginCollection(); | ||
try | ||
{ | ||
await _next(httpContext); | ||
var elapsedMs = GetElapsedMilliseconds(start, Stopwatch.GetTimestamp()); | ||
var statusCode = httpContext.Response.StatusCode; | ||
LogCompletion(httpContext, collector, statusCode, elapsedMs, null); | ||
LogCompletion(httpContext, collector, statusCode, stopwatch.ElapsedMilliseconds, null); | ||
} | ||
catch (Exception ex) | ||
// Never caught, because `LogCompletion()` returns false. This ensures e.g. the developer exception page is still | ||
// shown, although it does also mean we see a duplicate "unhandled exception" event from ASP.NET Core. | ||
when (LogCompletion(httpContext, collector, 500, GetElapsedMilliseconds(start, Stopwatch.GetTimestamp()), ex)) | ||
when (LogCompletion(httpContext, collector, 500, stopwatch.ElapsedMilliseconds, ex)) | ||
{ | ||
} | ||
finally | ||
|
@@ -97,11 +96,6 @@ bool LogCompletion(HttpContext httpContext, DiagnosticContextCollector collector | |
return false; | ||
} | ||
|
||
static double GetElapsedMilliseconds(long start, long stop) | ||
{ | ||
return (stop - start) * 1000 / (double)Stopwatch.Frequency; | ||
} | ||
|
||
static string GetPath(HttpContext httpContext, bool includeQueryInRequestPath) | ||
{ | ||
/* | ||
|