Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LabelInstructionInterpretter.cs
Go to the documentation of this file.
1
using
System.Collections.Concurrent
;
2
using
System.Collections.Generic
;
3
4
namespace
System.Diagnostics.Metrics
;
5
6
internal
class
LabelInstructionInterpretter
<
TObjectSequence
, TAggregator>
where
TObjectSequence
:
struct
,
IObjectSequence
,
IEquatable
<TObjectSequence>
where
TAggregator :
Aggregator
7
{
8
private
int
_expectedLabelCount
;
9
10
private
LabelInstruction
[]
_instructions
;
11
12
private
ConcurrentDictionary<TObjectSequence, TAggregator>
_valuesDict
;
13
14
private
Func<TObjectSequence, TAggregator>
_createAggregator
;
15
16
public
LabelInstructionInterpretter
(
int
expectedLabelCount
,
LabelInstruction
[]
instructions
,
ConcurrentDictionary<TObjectSequence, TAggregator>
valuesDict
,
Func<TAggregator>
createAggregator
)
17
{
18
_expectedLabelCount
=
expectedLabelCount
;
19
_instructions
=
instructions
;
20
_valuesDict
=
valuesDict
;
21
_createAggregator
= (
TObjectSequence
_
) =>
createAggregator
();
22
}
23
24
public
bool
GetAggregator
(
ReadOnlySpan
<
KeyValuePair<string, object>
>
labels
,
out
TAggregator
aggregator
)
25
{
26
aggregator
=
null
;
27
if
(
labels
.Length !=
_expectedLabelCount
)
28
{
29
return
false
;
30
}
31
TObjectSequence
val =
default
(
TObjectSequence
);
32
if
(val
is
ObjectSequenceMany
)
33
{
34
val = (
TObjectSequence
)(
object
)
new
ObjectSequenceMany
(
new
object
[
_expectedLabelCount
]);
35
}
36
Span<object>
span
= val.AsSpan();
37
for
(
int
i = 0; i <
_instructions
.Length; i++)
38
{
39
LabelInstruction
labelInstruction
=
_instructions
[i];
40
if
(
labelInstruction
.LabelName !=
labels
[
labelInstruction
.SourceIndex].Key)
41
{
42
return
false
;
43
}
44
span
[i] =
labels
[
labelInstruction
.SourceIndex].Value;
45
}
46
if
(!
_valuesDict
.
TryGetValue
(val,
out
aggregator
))
47
{
48
aggregator
=
_createAggregator
(val);
49
if
(
aggregator
==
null
)
50
{
51
return
true
;
52
}
53
aggregator
=
_valuesDict
.
GetOrAdd
(val,
aggregator
);
54
}
55
return
true
;
56
}
57
}
System.Collections.Concurrent.ConcurrentDictionary.TryGetValue
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
Definition
ConcurrentDictionary.cs:514
System.Collections.Concurrent.ConcurrentDictionary.GetOrAdd
TValue GetOrAdd(TKey key, Func< TKey, TValue > valueFactory)
Definition
ConcurrentDictionary.cs:895
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Diagnostics.Metrics.Aggregator
Definition
Aggregator.cs:4
System.Diagnostics.Metrics.LabelInstructionInterpretter._expectedLabelCount
int _expectedLabelCount
Definition
LabelInstructionInterpretter.cs:8
System.Diagnostics.Metrics.LabelInstructionInterpretter.LabelInstructionInterpretter
LabelInstructionInterpretter(int expectedLabelCount, LabelInstruction[] instructions, ConcurrentDictionary< TObjectSequence, TAggregator > valuesDict, Func< TAggregator > createAggregator)
Definition
LabelInstructionInterpretter.cs:16
System.Diagnostics.Metrics.LabelInstructionInterpretter.GetAggregator
bool GetAggregator(ReadOnlySpan< KeyValuePair< string, object > > labels, out TAggregator aggregator)
Definition
LabelInstructionInterpretter.cs:24
System.Diagnostics.Metrics.LabelInstructionInterpretter._instructions
LabelInstruction[] _instructions
Definition
LabelInstructionInterpretter.cs:10
System.Diagnostics.Metrics.LabelInstructionInterpretter._valuesDict
ConcurrentDictionary< TObjectSequence, TAggregator > _valuesDict
Definition
LabelInstructionInterpretter.cs:12
System.Diagnostics.Metrics.LabelInstructionInterpretter._createAggregator
Func< TObjectSequence, TAggregator > _createAggregator
Definition
LabelInstructionInterpretter.cs:14
System.Diagnostics.Metrics.LabelInstructionInterpretter
Definition
LabelInstructionInterpretter.cs:7
System.Diagnostics.Metrics.IObjectSequence
Definition
IObjectSequence.cs:4
System.IEquatable
Definition
IEquatable.cs:4
System.Collections.Concurrent
Definition
BlockingCollection.cs:8
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Diagnostics.Metrics
Definition
AggregationManager.cs:6
System.Diagnostics.Metrics.LabelInstruction
Definition
LabelInstruction.cs:4
System.Diagnostics.Metrics.ObjectSequenceMany
Definition
ObjectSequenceMany.cs:4
System.ReadOnlySpan
Definition
ReadOnlySpan.cs:14
source
System.Diagnostics.DiagnosticSource
System.Diagnostics.Metrics
LabelInstructionInterpretter.cs
Generated by
1.10.0