Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AggregationManager.cs
Go to the documentation of this file.
5
7
8[UnsupportedOSPlatform("browser")]
9internal sealed class AggregationManager
10{
11 private static readonly QuantileAggregation s_defaultHistogramConfig = new QuantileAggregation(0.5, 0.95, 0.99);
12
14
16
18
20
22
23 private readonly MeterListener _listener;
24
25 private int _currentTimeSeries;
26
27 private int _currentHistograms;
28
29 private readonly int _maxTimeSeries;
30
31 private readonly int _maxHistograms;
32
34
36
38
40
42
44
46
48
49 private readonly Action _timeSeriesLimitReached;
50
51 private readonly Action _histogramLimitReached;
52
54
56 {
71 {
72 InstrumentPublished = delegate(Instrument instrument, MeterListener listener)
73 {
76 if (instrumentState != null)
77 {
80 }
81 },
82 MeasurementsCompleted = delegate(Instrument instrument, object cookie)
83 {
86 }
87 };
88 _listener.SetMeasurementEventCallback(delegate(Instrument i, double m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
89 {
90 ((InstrumentState)c).Update(m, l);
91 });
92 _listener.SetMeasurementEventCallback(delegate(Instrument i, float m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
93 {
94 ((InstrumentState)c).Update(m, l);
95 });
96 _listener.SetMeasurementEventCallback(delegate(Instrument i, long m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
97 {
98 ((InstrumentState)c).Update(m, l);
99 });
100 _listener.SetMeasurementEventCallback(delegate(Instrument i, int m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
101 {
102 ((InstrumentState)c).Update(m, l);
103 });
104 _listener.SetMeasurementEventCallback(delegate(Instrument i, short m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
105 {
106 ((InstrumentState)c).Update(m, l);
107 });
108 _listener.SetMeasurementEventCallback(delegate(Instrument i, byte m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
109 {
110 ((InstrumentState)c).Update((int)m, l);
111 });
112 _listener.SetMeasurementEventCallback(delegate(Instrument i, decimal m, ReadOnlySpan<KeyValuePair<string, object>> l, object c)
113 {
114 ((InstrumentState)c).Update((double)m, l);
115 });
116 }
117
118 public void Include(string meterName)
119 {
120 Include((Instrument i) => i.Meter.Name == meterName);
121 }
122
123 public void Include(string meterName, string instrumentName)
124 {
125 Include((Instrument i) => i.Meter.Name == meterName && i.Name == instrumentName);
126 }
127
129 {
130 lock (this)
131 {
133 }
134 }
135
137 {
138 lock (this)
139 {
141 return this;
142 }
143 }
144
145 public void Start()
146 {
148 {
150 });
151 _collectThread.IsBackground = true;
152 _collectThread.Name = "MetricsEventSource CollectWorker";
156 }
157
159 {
160 try
161 {
162 double num = -1.0;
163 lock (this)
164 {
166 }
169 while (!cancelToken.IsCancellationRequested)
170 {
172 double totalSeconds = (utcNow2 - utcNow).TotalSeconds;
173 double value = Math.Ceiling(totalSeconds / num) * num;
174 DateTime dateTime = utcNow.AddSeconds(value);
175 DateTime dateTime2 = arg.AddSeconds(num);
176 if (dateTime <= dateTime2)
177 {
179 }
181 if (!cancelToken.WaitHandle.WaitOne(timeout))
182 {
184 Collect();
186 arg = dateTime;
187 continue;
188 }
189 break;
190 }
191 }
192 catch (Exception obj)
193 {
195 }
196 }
197
198 public void Dispose()
199 {
200 _cts.Cancel();
201 if (_collectThread != null)
202 {
204 _collectThread = null;
205 }
207 }
208
213
215 {
217 {
218 lock (this)
219 {
221 {
223 {
225 if (value != null)
226 {
229 }
230 break;
231 }
232 }
233 }
234 }
235 return value;
236 }
237
239 {
241 if (aggregatorFactory == null)
242 {
243 return null;
244 }
245 Type type = aggregatorFactory.GetType().GenericTypeArguments[0];
246 Type type2 = typeof(InstrumentState<>).MakeGenericType(type);
248 }
249
251 {
252 Type type = instrument.GetType();
253 Type type2 = null;
254 type2 = (type.IsGenericType ? type.GetGenericTypeDefinition() : null);
255 if (type2 == typeof(Counter<>))
256 {
257 return delegate
258 {
259 lock (this)
260 {
261 return CheckTimeSeriesAllowed() ? new RateSumAggregator() : null;
262 }
263 };
264 }
266 {
267 return delegate
268 {
269 lock (this)
270 {
271 return CheckTimeSeriesAllowed() ? new RateAggregator() : null;
272 }
273 };
274 }
276 {
277 return delegate
278 {
279 lock (this)
280 {
281 return CheckTimeSeriesAllowed() ? new LastValue() : null;
282 }
283 };
284 }
285 if (type2 == typeof(Histogram<>))
286 {
287 return delegate
288 {
289 lock (this)
290 {
292 }
293 };
294 }
295 return null;
296 }
297
299 {
301 {
303 return true;
304 }
306 {
309 return false;
310 }
311 return false;
312 }
313
315 {
317 {
319 return true;
320 }
322 {
325 return false;
326 }
327 return false;
328 }
329
330 internal void Collect()
331 {
332 try
333 {
335 }
336 catch (Exception obj)
337 {
339 }
341 {
343 {
345 });
346 }
347 }
348}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool TryAdd(TKey key, TValue value)
void Add(TKey key, TValue value)
void RemoveInstrumentState(Instrument instrument, InstrumentState state)
readonly List< Predicate< Instrument > > _instrumentConfigFuncs
void Include(string meterName, string instrumentName)
AggregationManager(int maxTimeSeries, int maxHistograms, Action< Instrument, LabeledAggregationStatistics > collectMeasurement, Action< DateTime, DateTime > beginCollection, Action< DateTime, DateTime > endCollection, Action< Instrument > beginInstrumentMeasurements, Action< Instrument > endInstrumentMeasurements, Action< Instrument > instrumentPublished, Action initialInstrumentEnumerationComplete, Action< Exception > collectionError, Action timeSeriesLimitReached, Action histogramLimitReached, Action< Exception > observableInstrumentCallbackError)
AggregationManager SetCollectionPeriod(TimeSpan collectionPeriod)
void Include(Predicate< Instrument > instrumentFilter)
readonly Action< Instrument > _instrumentPublished
void CollectWorker(CancellationToken cancelToken)
readonly ConcurrentDictionary< Instrument, InstrumentState > _instrumentStates
Func< Aggregator > GetAggregatorFactory(Instrument instrument)
static readonly QuantileAggregation s_defaultHistogramConfig
readonly Action< Instrument > _beginInstrumentMeasurements
readonly Action< DateTime, DateTime > _endCollection
readonly Action< DateTime, DateTime > _beginCollection
InstrumentState GetInstrumentState(Instrument instrument)
InstrumentState BuildInstrumentState(Instrument instrument)
readonly Action< Instrument, LabeledAggregationStatistics > _collectMeasurement
readonly Action< Exception > _observableInstrumentCallbackError
readonly Action< Instrument > _endInstrumentMeasurements
void EnableMeasurementEvents(Instrument instrument, object? state=null)
static double Ceiling(double a)
bool Join(int millisecondsTimeout)
void Start(object? parameter)
Definition Thread.cs:574
delegate void ThreadStart()
static unsafe DateTime UtcNow
Definition DateTime.cs:142
double TotalSeconds
Definition TimeSpan.cs:64