-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Removing more generics for #392 * Fixing the formatting issue * Removed Unsafe everywhere * Fixing method order and file name in the header Co-authored-by: Sergey Kanzhelev <S.Kanzhelev@live.com>
- Loading branch information
1 parent
bc684ff
commit 48dbba3
Showing
32 changed files
with
935 additions
and
610 deletions.
There are no files selected for viewing
94 changes: 0 additions & 94 deletions
94
src/OpenTelemetry/Metrics/Aggregators/CounterSumAggregator.cs
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
src/OpenTelemetry/Metrics/Aggregators/DoubleCounterSumAggregator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// <copyright file="DoubleCounterSumAggregator.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using OpenTelemetry.Metrics.Export; | ||
|
||
namespace OpenTelemetry.Metrics.Aggregators | ||
{ | ||
/// <summary> | ||
/// Basic aggregator which calculates a Sum from individual measurements. | ||
/// </summary> | ||
public class DoubleCounterSumAggregator : Aggregator<double> | ||
{ | ||
private double sum; | ||
private double checkPoint; | ||
|
||
public override void Checkpoint() | ||
{ | ||
// checkpoints the current running sum into checkpoint, and starts counting again. | ||
this.checkPoint = Interlocked.Exchange(ref this.sum, 0.0); | ||
} | ||
|
||
public override MetricData<double> ToMetricData() | ||
{ | ||
return new SumData<double> | ||
{ | ||
Sum = this.checkPoint, | ||
Timestamp = DateTime.UtcNow, | ||
}; | ||
} | ||
|
||
public override AggregationType GetAggregationType() | ||
{ | ||
return AggregationType.DoubleSum; | ||
} | ||
|
||
public override void Update(double value) | ||
{ | ||
// Adds value to the running total in a thread safe manner. | ||
double initialTotal, computedTotal; | ||
do | ||
{ | ||
initialTotal = this.sum; | ||
computedTotal = initialTotal + value; | ||
} | ||
while (initialTotal != Interlocked.CompareExchange(ref this.sum, computedTotal, initialTotal)); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/OpenTelemetry/Metrics/Aggregators/DoubleLastValueAggregator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// <copyright file="DoubleLastValueAggregator.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Threading; | ||
using OpenTelemetry.Metrics.Export; | ||
|
||
namespace OpenTelemetry.Metrics.Aggregators | ||
{ | ||
/// <summary> | ||
/// Simple aggregator that only keeps the last value. | ||
/// </summary> | ||
public class DoubleLastValueAggregator : Aggregator<double> | ||
{ | ||
private double value; | ||
private double checkpoint; | ||
|
||
public override void Checkpoint() | ||
{ | ||
Interlocked.Exchange(ref this.checkpoint, this.value); | ||
} | ||
|
||
public override MetricData<double> ToMetricData() | ||
{ | ||
return new SumData<double> | ||
{ | ||
Sum = this.checkpoint, | ||
Timestamp = DateTime.UtcNow, | ||
}; | ||
} | ||
|
||
public override AggregationType GetAggregationType() | ||
{ | ||
return AggregationType.DoubleSum; | ||
} | ||
|
||
public override void Update(double newValue) | ||
{ | ||
Interlocked.Exchange(ref this.value, newValue); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/OpenTelemetry/Metrics/Aggregators/DoubleMeasureMinMaxSumCountAggregator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// <copyright file="DoubleMeasureMinMaxSumCountAggregator.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Threading; | ||
using OpenTelemetry.Metrics.Export; | ||
|
||
namespace OpenTelemetry.Metrics.Aggregators | ||
{ | ||
/// <summary> | ||
/// Aggregator which calculates summary (Min,Max,Sum,Count) from measures. | ||
/// </summary> | ||
public class DoubleMeasureMinMaxSumCountAggregator : Aggregator<double> | ||
{ | ||
private DoubleSummary summary = new DoubleSummary(); | ||
private DoubleSummary checkPoint = new DoubleSummary(); | ||
private object updateLock = new object(); | ||
|
||
public override void Checkpoint() | ||
{ | ||
this.checkPoint = Interlocked.Exchange(ref this.summary, new DoubleSummary()); | ||
} | ||
|
||
public override AggregationType GetAggregationType() | ||
{ | ||
return AggregationType.Summary; | ||
} | ||
|
||
public override MetricData<double> ToMetricData() | ||
{ | ||
return new SummaryData<double> | ||
{ | ||
Count = this.checkPoint.Count, | ||
Sum = this.checkPoint.Sum, | ||
Min = this.checkPoint.Min, | ||
Max = this.checkPoint.Max, | ||
Timestamp = DateTime.UtcNow, | ||
}; | ||
} | ||
|
||
public override void Update(double value) | ||
{ | ||
lock (this.updateLock) | ||
{ | ||
this.summary.Count++; | ||
this.summary.Sum += value; | ||
this.summary.Max = Math.Max(this.summary.Max, value); | ||
this.summary.Min = Math.Min(this.summary.Min, value); | ||
} | ||
} | ||
|
||
private class DoubleSummary | ||
{ | ||
public long Count; | ||
public double Min; | ||
public double Max; | ||
public double Sum; | ||
|
||
public DoubleSummary() | ||
{ | ||
this.Min = double.MaxValue; | ||
this.Max = double.MinValue; | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/OpenTelemetry/Metrics/Aggregators/Int64CounterSumAggregator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <copyright file="Int64CounterSumAggregator.cs" company="OpenTelemetry Authors"> | ||
// Copyright 2018, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using OpenTelemetry.Metrics.Export; | ||
|
||
namespace OpenTelemetry.Metrics.Aggregators | ||
{ | ||
/// <summary> | ||
/// Basic aggregator which calculates a Sum from individual measurements. | ||
/// </summary> | ||
public class Int64CounterSumAggregator : Aggregator<long> | ||
{ | ||
private long sum; | ||
private long checkPoint; | ||
|
||
public override void Checkpoint() | ||
{ | ||
// checkpoints the current running sum into checkpoint, and starts counting again. | ||
this.checkPoint = Interlocked.Exchange(ref this.sum, 0); | ||
} | ||
|
||
public override MetricData<long> ToMetricData() | ||
{ | ||
return new SumData<long> | ||
{ | ||
Sum = this.checkPoint, | ||
Timestamp = DateTime.UtcNow, | ||
}; | ||
} | ||
|
||
public override AggregationType GetAggregationType() | ||
{ | ||
return AggregationType.LongSum; | ||
} | ||
|
||
public override void Update(long value) | ||
{ | ||
// Adds value to the running total in a thread safe manner. | ||
Interlocked.Add(ref this.sum, value); | ||
} | ||
} | ||
} |
Oops, something went wrong.