Better timing measurement during invoice creation

This commit is contained in:
nicolas.dorier 2019-04-03 15:00:09 +09:00
parent 6b4b903669
commit 4853e15d8a
2 changed files with 39 additions and 7 deletions

View File

@ -200,9 +200,10 @@ namespace BTCPayServer.Controllers
entity.InternalTags.Add(AppService.GetAppInternalTag(app.Id));
}
logs.Write($"Saving invoice...");
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, _NetworkProvider);
logs.Write($"Invoice saved!");
using (logs.Measure("Saving invoice"))
{
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, _NetworkProvider);
}
_ = Task.Run(async () =>
{
try
@ -258,10 +259,11 @@ namespace BTCPayServer.Controllers
paymentMethod.Rate = rate.BidAsk.Bid;
paymentMethod.PreferOnion = this.Request.IsOnion();
logs.Write($"{logPrefix} Creating payment method details...");
var paymentDetails = await handler.CreatePaymentMethodDetails(supportedPaymentMethod, paymentMethod, store, network, preparePayment);
logs.Write($"{logPrefix} Payment method details created...");
paymentMethod.SetPaymentMethodDetails(paymentDetails);
using (logs.Measure($"{logPrefix} Payment method details creation"))
{
var paymentDetails = await handler.CreatePaymentMethodDetails(supportedPaymentMethod, paymentMethod, store, network, preparePayment);
paymentMethod.SetPaymentMethodDetails(paymentDetails);
}
Func<Money, Money, bool> compare = null;
CurrencyValue limitValue = null;

View File

@ -33,5 +33,35 @@ namespace BTCPayServer.Logging
return _InvoiceLogs.ToList();
}
}
internal IDisposable Measure(string logs)
{
return new Mesuring(this, logs);
}
class Mesuring : IDisposable
{
private readonly InvoiceLogs _logs;
private readonly string _msg;
private readonly DateTimeOffset _Before;
public Mesuring(InvoiceLogs logs, string msg)
{
_logs = logs;
_msg = msg;
_Before = DateTimeOffset.UtcNow;
}
public void Dispose()
{
var timespan = DateTimeOffset.UtcNow - _Before;
if (timespan.TotalSeconds >= 1.0)
{
_logs.Write($"{_msg} took {(int)timespan.TotalSeconds} seconds");
}
else
{
_logs.Write($"{_msg} took {(int)timespan.TotalMilliseconds} milliseconds");
}
}
}
}
}