From d64cb4a72855f863b33057920ef9f6fc3c234dc5 Mon Sep 17 00:00:00 2001
From: Victor Lu <75279620+victlu@users.noreply.github.com>
Date: Mon, 10 May 2021 10:27:30 -0700
Subject: [PATCH] Sync .NET API with updates
---
.../Counter.cs | 30 +++---
.../Histogram.cs | 30 +++---
.../Instrument.cs | 4 +-
.../InstrumentT.cs | 6 +-
.../Measurement.cs | 2 +-
src/System.Diagnostics.Metrics.Temp/Meter.cs | 100 +++++++++---------
.../MeterListener.cs | 11 +-
.../ObservableCounter.cs | 6 +-
.../ObservableGauge.cs | 6 +-
.../ObservableInstrument.cs | 6 +-
.../ObservableUpDownCounter.cs | 4 +-
11 files changed, 100 insertions(+), 105 deletions(-)
diff --git a/src/System.Diagnostics.Metrics.Temp/Counter.cs b/src/System.Diagnostics.Metrics.Temp/Counter.cs
index 9e611cc6348..7e02531fd74 100644
--- a/src/System.Diagnostics.Metrics.Temp/Counter.cs
+++ b/src/System.Diagnostics.Metrics.Temp/Counter.cs
@@ -26,10 +26,10 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public sealed class Counter : Instrument
- where T : unmanaged
+ where T : struct
{
- internal Counter(Meter meter, string name, string? description, string? unit)
- : base(meter, name, description, unit)
+ internal Counter(Meter meter, string name, string? unit, string? description)
+ : base(meter, name, unit, description)
{
this.Publish();
}
@@ -37,62 +37,62 @@ internal Counter(Meter meter, string name, string? description, string? unit)
///
/// TBD.
///
- public void Add(T measurement)
+ public void Add(T delta)
{
- this.RecordMeasurement(measurement);
+ this.RecordMeasurement(delta);
}
///
/// TBD.
///
public void Add(
- T measurement,
+ T delta,
KeyValuePair tag1)
{
- this.RecordMeasurement(measurement, tag1);
+ this.RecordMeasurement(delta, tag1);
}
///
/// TBD.
///
public void Add(
- T measurement,
+ T delta,
KeyValuePair tag1,
KeyValuePair tag2)
{
- this.RecordMeasurement(measurement, tag1, tag2);
+ this.RecordMeasurement(delta, tag1, tag2);
}
///
/// TBD.
///
public void Add(
- T measurement,
+ T delta,
KeyValuePair tag1,
KeyValuePair tag2,
KeyValuePair tag3)
{
- this.RecordMeasurement(measurement, tag1, tag2, tag3);
+ this.RecordMeasurement(delta, tag1, tag2, tag3);
}
///
/// TBD.
///
public void Add(
- T measurement,
+ T delta,
ReadOnlySpan> tags)
{
- this.RecordMeasurement(measurement, tags);
+ this.RecordMeasurement(delta, tags);
}
///
/// TBD.
///
public void Add(
- T measurement,
+ T delta,
params KeyValuePair[] tags)
{
- this.RecordMeasurement(measurement, tags);
+ this.RecordMeasurement(delta, tags);
}
}
}
diff --git a/src/System.Diagnostics.Metrics.Temp/Histogram.cs b/src/System.Diagnostics.Metrics.Temp/Histogram.cs
index daac125a833..a68104edc09 100644
--- a/src/System.Diagnostics.Metrics.Temp/Histogram.cs
+++ b/src/System.Diagnostics.Metrics.Temp/Histogram.cs
@@ -27,10 +27,10 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public sealed class Histogram : Instrument
- where T : unmanaged
+ where T : struct
{
- internal Histogram(Meter meter, string name, string? description, string? unit)
- : base(meter, name, description, unit)
+ internal Histogram(Meter meter, string name, string? unit, string? description)
+ : base(meter, name, unit, description)
{
this.Publish();
}
@@ -38,62 +38,62 @@ internal Histogram(Meter meter, string name, string? description, string? unit)
///
/// TBD.
///
- public void Record(T measurement)
+ public void Record(T value)
{
- this.RecordMeasurement(measurement);
+ this.RecordMeasurement(value);
}
///
/// TBD.
///
public void Record(
- T measurement,
+ T value,
KeyValuePair tag1)
{
- this.RecordMeasurement(measurement, tag1);
+ this.RecordMeasurement(value, tag1);
}
///
/// TBD.
///
public void Record(
- T measurement,
+ T value,
KeyValuePair tag1,
KeyValuePair tag2)
{
- this.RecordMeasurement(measurement, tag1, tag2);
+ this.RecordMeasurement(value, tag1, tag2);
}
///
/// TBD.
///
public void Record(
- T measurement,
+ T value,
KeyValuePair tag1,
KeyValuePair tag2,
KeyValuePair tag3)
{
- this.RecordMeasurement(measurement, tag1, tag2, tag3);
+ this.RecordMeasurement(value, tag1, tag2, tag3);
}
///
/// TBD.
///
public void Record(
- T measurement,
+ T value,
ReadOnlySpan> tags)
{
- this.RecordMeasurement(measurement, tags);
+ this.RecordMeasurement(value, tags);
}
///
/// TBD.
///
public void Record(
- T measurement,
+ T value,
params KeyValuePair[] tags)
{
- this.RecordMeasurement(measurement, tags);
+ this.RecordMeasurement(value, tags);
}
}
}
diff --git a/src/System.Diagnostics.Metrics.Temp/Instrument.cs b/src/System.Diagnostics.Metrics.Temp/Instrument.cs
index 1662bd02fba..5e3b5c531e9 100644
--- a/src/System.Diagnostics.Metrics.Temp/Instrument.cs
+++ b/src/System.Diagnostics.Metrics.Temp/Instrument.cs
@@ -34,12 +34,12 @@ public abstract class Instrument
/// Initializes a new instance of the class.
/// Protected constructor to initialize the common instrument properties.
///
- protected Instrument(Meter meter, string name, string? description, string? unit)
+ protected Instrument(Meter meter, string name, string? unit, string? description)
{
this.Meter = meter;
this.Name = name;
- this.Description = description;
this.Unit = unit;
+ this.Description = description;
}
///
diff --git a/src/System.Diagnostics.Metrics.Temp/InstrumentT.cs b/src/System.Diagnostics.Metrics.Temp/InstrumentT.cs
index dd9f7b6a07a..6976a91e3dd 100644
--- a/src/System.Diagnostics.Metrics.Temp/InstrumentT.cs
+++ b/src/System.Diagnostics.Metrics.Temp/InstrumentT.cs
@@ -27,14 +27,14 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public abstract class Instrument : Instrument
- where T : unmanaged
+ where T : struct
{
///
/// Initializes a new instance of the class.
/// Protected constructor to create the instrument with the common properties.
///
- protected Instrument(Meter meter, string name, string? description, string? unit)
- : base(meter, name, description, unit)
+ protected Instrument(Meter meter, string name, string? unit, string? description)
+ : base(meter, name, unit, description)
{
}
diff --git a/src/System.Diagnostics.Metrics.Temp/Measurement.cs b/src/System.Diagnostics.Metrics.Temp/Measurement.cs
index 1d04c6bd3b8..27a97efdcfe 100644
--- a/src/System.Diagnostics.Metrics.Temp/Measurement.cs
+++ b/src/System.Diagnostics.Metrics.Temp/Measurement.cs
@@ -27,7 +27,7 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public struct Measurement
- where T : unmanaged
+ where T : struct
{
///
/// Initializes a new instance of the struct.
diff --git a/src/System.Diagnostics.Metrics.Temp/Meter.cs b/src/System.Diagnostics.Metrics.Temp/Meter.cs
index 31229425446..a5c8b821fac 100644
--- a/src/System.Diagnostics.Metrics.Temp/Meter.cs
+++ b/src/System.Diagnostics.Metrics.Temp/Meter.cs
@@ -61,11 +61,11 @@ public Meter(string name, string? version)
/// TBD.
public Counter CreateCounter(
string name,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
- return new Counter(this, name, description, unit);
+ return new Counter(this, name, unit, description);
}
///
@@ -74,11 +74,11 @@ public Counter CreateCounter(
/// TBD.
public Histogram CreateHistogram(
string name,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
- return new Histogram(this, name, description, unit);
+ return new Histogram(this, name, unit, description);
}
///
@@ -88,9 +88,9 @@ public Histogram CreateHistogram(
public ObservableCounter CreateObservableCounter(
string name,
Func observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableCounter(
this,
@@ -99,8 +99,8 @@ public ObservableCounter CreateObservableCounter(
{
new Measurement(observeValue()),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -110,9 +110,9 @@ public ObservableCounter CreateObservableCounter(
public ObservableCounter CreateObservableCounter(
string name,
Func> observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableCounter(
this,
@@ -121,8 +121,8 @@ public ObservableCounter CreateObservableCounter(
{
observeValue(),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -132,11 +132,11 @@ public ObservableCounter CreateObservableCounter(
public ObservableCounter CreateObservableCounter(
string name,
Func>> observeValues,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
- return new ObservableCounter(this, name, observeValues, description, unit);
+ return new ObservableCounter(this, name, observeValues, unit, description);
}
///
@@ -146,9 +146,9 @@ public ObservableCounter CreateObservableCounter(
public ObservableGauge CreateObservableGauge(
string name,
Func observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableGauge(
this,
@@ -157,8 +157,8 @@ public ObservableGauge CreateObservableGauge(
{
new Measurement(observeValue()),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -168,9 +168,9 @@ public ObservableGauge CreateObservableGauge(
public ObservableGauge CreateObservableGauge(
string name,
Func> observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableGauge(
this,
@@ -179,8 +179,8 @@ public ObservableGauge CreateObservableGauge(
{
observeValue(),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -190,11 +190,11 @@ public ObservableGauge CreateObservableGauge(
public ObservableGauge CreateObservableGauge(
string name,
Func>> observeValues,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
- return new ObservableGauge(this, name, observeValues, description, unit);
+ return new ObservableGauge(this, name, observeValues, unit, description);
}
///
@@ -204,9 +204,9 @@ public ObservableGauge CreateObservableGauge(
public ObservableUpDownCounter CreateObservableUpDownCounter(
string name,
Func observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableUpDownCounter(
this,
@@ -215,8 +215,8 @@ public ObservableUpDownCounter CreateObservableUpDownCounter(
{
new Measurement(observeValue()),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -226,9 +226,9 @@ public ObservableUpDownCounter CreateObservableUpDownCounter(
public ObservableUpDownCounter CreateObservableUpDownCounter(
string name,
Func> observeValue,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
return new ObservableUpDownCounter(
this,
@@ -237,8 +237,8 @@ public ObservableUpDownCounter CreateObservableUpDownCounter(
{
observeValue(),
},
- description,
- unit);
+ unit,
+ description);
}
///
@@ -248,11 +248,11 @@ public ObservableUpDownCounter CreateObservableUpDownCounter(
public ObservableUpDownCounter CreateObservableUpDownCounter(
string name,
Func>> observeValues,
- string? description = null,
- string? unit = null)
- where T : unmanaged
+ string? unit = null,
+ string? description = null)
+ where T : struct
{
- return new ObservableUpDownCounter(this, name, observeValues, description, unit);
+ return new ObservableUpDownCounter(this, name, observeValues, unit, description);
}
///
diff --git a/src/System.Diagnostics.Metrics.Temp/MeterListener.cs b/src/System.Diagnostics.Metrics.Temp/MeterListener.cs
index 5d4efc1c10a..b33a54c1c91 100644
--- a/src/System.Diagnostics.Metrics.Temp/MeterListener.cs
+++ b/src/System.Diagnostics.Metrics.Temp/MeterListener.cs
@@ -31,7 +31,8 @@ public delegate void MeasurementCallback(
Instrument instrument,
T measurement,
ReadOnlySpan> tags,
- object? state);
+ object? state)
+ where T : struct;
///
/// The listener class can be used to listen to observable and non-observable instrument
@@ -94,6 +95,7 @@ public void EnableMeasurementEvents(Instrument instrument, object? state = null)
///
/// TBD.
public void SetMeasurementEventCallback(MeasurementCallback? measurementCallback)
+ where T : struct
{
this.Callbacks.TryAdd(typeof(T), (object?)measurementCallback);
}
@@ -105,13 +107,6 @@ public void Start()
{
}
- ///
- /// TBD.
- ///
- public void Stop()
- {
- }
-
///
/// Call all Observable instruments to get the recorded measurements reported to the
/// callbacks enabled by SetMeasurementEventCallback_T.
diff --git a/src/System.Diagnostics.Metrics.Temp/ObservableCounter.cs b/src/System.Diagnostics.Metrics.Temp/ObservableCounter.cs
index 29af86729c2..19c4bf806f0 100644
--- a/src/System.Diagnostics.Metrics.Temp/ObservableCounter.cs
+++ b/src/System.Diagnostics.Metrics.Temp/ObservableCounter.cs
@@ -27,12 +27,12 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public sealed class ObservableCounter : ObservableInstrument
- where T : unmanaged
+ where T : struct
{
private Func>> observeValues;
- internal ObservableCounter(Meter meter, string name, Func>> observeValues, string? description, string? unit)
- : base(meter, name, description, unit)
+ internal ObservableCounter(Meter meter, string name, Func>> observeValues, string? unit, string? description)
+ : base(meter, name, unit, description)
{
this.observeValues = observeValues;
this.Publish();
diff --git a/src/System.Diagnostics.Metrics.Temp/ObservableGauge.cs b/src/System.Diagnostics.Metrics.Temp/ObservableGauge.cs
index 6418655622e..94eca5c393e 100644
--- a/src/System.Diagnostics.Metrics.Temp/ObservableGauge.cs
+++ b/src/System.Diagnostics.Metrics.Temp/ObservableGauge.cs
@@ -27,12 +27,12 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public sealed class ObservableGauge : ObservableInstrument
- where T : unmanaged
+ where T : struct
{
private Func>> observeValues;
- internal ObservableGauge(Meter meter, string name, Func>> observeValues, string? description, string? unit)
- : base(meter, name, description, unit)
+ internal ObservableGauge(Meter meter, string name, Func>> observeValues, string? unit, string? description)
+ : base(meter, name, unit, description)
{
this.observeValues = observeValues;
this.Publish();
diff --git a/src/System.Diagnostics.Metrics.Temp/ObservableInstrument.cs b/src/System.Diagnostics.Metrics.Temp/ObservableInstrument.cs
index c8070f6da22..5ff3908afcb 100644
--- a/src/System.Diagnostics.Metrics.Temp/ObservableInstrument.cs
+++ b/src/System.Diagnostics.Metrics.Temp/ObservableInstrument.cs
@@ -26,7 +26,7 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public abstract class ObservableInstrument : Instrument
- where T : unmanaged
+ where T : struct
{
///
/// Initializes a new instance of the class.
@@ -35,8 +35,8 @@ public abstract class ObservableInstrument : Instrument
protected ObservableInstrument(
Meter meter,
string name,
- string? description,
- string? unit)
+ string? unit,
+ string? description)
: base(meter, name, description, unit)
{
}
diff --git a/src/System.Diagnostics.Metrics.Temp/ObservableUpDownCounter.cs b/src/System.Diagnostics.Metrics.Temp/ObservableUpDownCounter.cs
index d0ac83931fa..bf74eef8f8e 100644
--- a/src/System.Diagnostics.Metrics.Temp/ObservableUpDownCounter.cs
+++ b/src/System.Diagnostics.Metrics.Temp/ObservableUpDownCounter.cs
@@ -27,12 +27,12 @@ namespace System.Diagnostics.Metrics
///
/// TBD.
public sealed class ObservableUpDownCounter : ObservableInstrument
- where T : unmanaged
+ where T : struct
{
private Func>> observeValues;
internal ObservableUpDownCounter(Meter meter, string name, Func>> observeValues, string? description, string? unit)
- : base(meter, name, description, unit)
+ : base(meter, name, unit, description)
{
this.observeValues = observeValues;
this.Publish();