Don't allocate a stopwatch if it isn't going to be used. (#2608)
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
parent
a2a8061ccf
commit
770a367b39
|
|
@ -130,7 +130,9 @@ namespace OpenTelemetry
|
|||
|
||||
var triggers = new WaitHandle[] { this.dataExportedNotification, this.shutdownTrigger };
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
// There is a chance that the export thread finished processing all the data from the queue,
|
||||
// and signaled before we enter wait here, use polling to prevent being blocked indefinitely.
|
||||
|
|
@ -138,7 +140,7 @@ namespace OpenTelemetry
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -83,11 +83,13 @@ namespace OpenTelemetry
|
|||
protected override bool OnForceFlush(int timeoutMilliseconds)
|
||||
{
|
||||
var result = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
for (var cur = this.head; cur != null; cur = cur.Next)
|
||||
{
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
result = cur.Value.ForceFlush(Timeout.Infinite) && result;
|
||||
}
|
||||
|
|
@ -107,11 +109,13 @@ namespace OpenTelemetry
|
|||
protected override bool OnShutdown(int timeoutMilliseconds)
|
||||
{
|
||||
var result = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
for (var cur = this.head; cur != null; cur = cur.Next)
|
||||
{
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
result = cur.Value.Shutdown(Timeout.Infinite) && result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,11 +75,13 @@ namespace OpenTelemetry.Metrics
|
|||
protected override bool OnCollect(int timeoutMilliseconds = Timeout.Infinite)
|
||||
{
|
||||
var result = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
for (var cur = this.head; cur != null; cur = cur.Next)
|
||||
{
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
result = cur.Value.Collect(Timeout.Infinite) && result;
|
||||
}
|
||||
|
|
@ -99,11 +101,13 @@ namespace OpenTelemetry.Metrics
|
|||
protected override bool OnShutdown(int timeoutMilliseconds)
|
||||
{
|
||||
var result = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
for (var cur = this.head; cur != null; cur = cur.Next)
|
||||
{
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
result = cur.Value.Shutdown(Timeout.Infinite) && result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -207,12 +207,14 @@ namespace OpenTelemetry.Metrics
|
|||
/// </remarks>
|
||||
protected virtual bool OnCollect(int timeoutMilliseconds)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sw = timeoutMilliseconds == Timeout.Infinite
|
||||
? null
|
||||
: Stopwatch.StartNew();
|
||||
|
||||
var collectMetric = this.ParentProvider.GetMetricCollect();
|
||||
var metrics = collectMetric();
|
||||
|
||||
if (timeoutMilliseconds == Timeout.Infinite)
|
||||
if (sw == null)
|
||||
{
|
||||
return this.ProcessMetrics(metrics, Timeout.Infinite);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue