Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ActivitySource.cs
Go to the documentation of this file.
4
5namespace System.Diagnostics;
6
7public sealed class ActivitySource : IDisposable
8{
10
12
14
16
17 public string Name { get; }
18
19 public string? Version { get; }
20
21 public ActivitySource(string name, string? version = "")
22 {
23 if (name == null)
24 {
25 throw new ArgumentNullException("name");
26 }
27 Name = name;
28 Version = version;
29 s_activeSources.Add(this);
30 if (s_allListeners.Count > 0)
31 {
32 s_allListeners.EnumWithAction(delegate(ActivityListener listener, object source)
33 {
35 if (shouldListenTo != null)
36 {
39 {
40 activitySource.AddListener(listener);
41 }
42 }
43 }, this);
44 }
46 }
47
48 public bool HasListeners()
49 {
51 if (listeners != null)
52 {
53 return listeners.Count > 0;
54 }
55 return false;
56 }
57
58 public Activity? CreateActivity(string name, ActivityKind kind)
59 {
60 return CreateActivity(name, kind, default(ActivityContext), null, null, null, default(DateTimeOffset), startIt: false);
61 }
62
67
69 {
70 return CreateActivity(name, kind, default(ActivityContext), parentId, tags, links, default(DateTimeOffset), startIt: false, idFormat);
71 }
72
73 public Activity? StartActivity([CallerMemberName] string name = "", ActivityKind kind = ActivityKind.Internal)
74 {
75 return CreateActivity(name, kind, default(ActivityContext), null, null, null, default(DateTimeOffset));
76 }
77
82
84 {
85 return CreateActivity(name, kind, default(ActivityContext), parentId, tags, links, startTime);
86 }
87
92
94 {
96 if (listeners == null || listeners.Count == 0)
97 {
98 return null;
99 }
100 Activity result2 = null;
103 if (parentId != null)
104 {
108 if (activityCreationOptions.IdFormat == ActivityIdFormat.W3C)
109 {
111 }
113 {
115 if (sampleUsingParentId != null)
116 {
118 if (activitySamplingResult2 > result)
119 {
121 }
122 }
123 else if (data.IdFormat == ActivityIdFormat.W3C)
124 {
126 if (sample2 != null)
127 {
129 if (activitySamplingResult3 > result)
130 {
132 }
133 }
134 }
136 if (context == default(ActivityContext))
137 {
138 if (activityCreationOptions.GetContext() != default(ActivityContext))
139 {
140 context = activityCreationOptions.GetContext();
141 parentId = null;
142 }
143 else if (dataWithContext2.GetContext() != default(ActivityContext))
144 {
145 context = dataWithContext2.GetContext();
146 parentId = null;
147 }
148 }
151 if (samplingTags != null)
152 {
153 if (activityTagsCollection == null)
154 {
156 }
157 else
158 {
160 {
162 }
163 }
164 }
166 }
167 else
168 {
169 bool flag = context == default(ActivityContext) && Activity.Current != null;
170 ActivityCreationOptions<ActivityContext> data2 = new ActivityCreationOptions<ActivityContext>(this, name, flag ? Activity.Current.Context : context, kind, tags, links, idFormat);
172 {
174 if (sample != null)
175 {
177 if (activitySamplingResult > result)
178 {
179 result = activitySamplingResult;
180 }
181 }
182 }, ref data2, ref samplingResult, ref data2);
183 if (!flag)
184 {
185 context = data2.GetContext();
186 }
187 activityTagsCollection = data2.GetSamplingTags();
188 idFormat = data2.IdFormat;
189 }
190 if (samplingResult != 0)
191 {
193 }
194 return result2;
195 }
196
197 public void Dispose()
198 {
199 _listeners = null;
200 s_activeSources.Remove(this);
201 }
202
203 public static void AddActivityListener(ActivityListener listener)
204 {
205 if (listener == null)
206 {
207 throw new ArgumentNullException("listener");
208 }
209 if (!s_allListeners.AddIfNotExist(listener))
210 {
211 return;
212 }
213 s_activeSources.EnumWithAction(delegate(ActivitySource source, object obj)
214 {
216 if (shouldListenTo != null && shouldListenTo(source))
217 {
218 source.AddListener((ActivityListener)obj);
219 }
220 }, listener);
221 }
222
223 internal void AddListener(ActivityListener listener)
224 {
225 if (_listeners == null)
226 {
228 }
229 _listeners.AddIfNotExist(listener);
230 }
231
232 internal static void DetachListener(ActivityListener listener)
233 {
234 s_allListeners.Remove(listener);
235 s_activeSources.EnumWithAction(delegate(ActivitySource source, object obj)
236 {
237 source._listeners?.Remove((ActivityListener)obj);
238 }, listener);
239 }
240
242 {
244 if (listeners != null && listeners.Count > 0)
245 {
246 listeners.EnumWithAction(delegate(ActivityListener listener, object obj)
247 {
248 listener.ActivityStarted?.Invoke((Activity)obj);
249 }, activity);
250 }
251 }
252
254 {
256 if (listeners != null && listeners.Count > 0)
257 {
258 listeners.EnumWithAction(delegate(ActivityListener listener, object obj)
259 {
260 listener.ActivityStopped?.Invoke((Activity)obj);
261 }, activity);
262 }
263 }
264}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
Func< ActivitySource, bool >? ShouldListenTo
SampleActivity< ActivityContext >? Sample
SampleActivity< string >? SampleUsingParentId
Activity CreateActivity(string name, ActivityKind kind, ActivityContext context, string parentId, IEnumerable< KeyValuePair< string, object > > tags, IEnumerable< ActivityLink > links, DateTimeOffset startTime, bool startIt=true, ActivityIdFormat idFormat=ActivityIdFormat.Unknown)
Activity? StartActivity(ActivityKind kind, ActivityContext parentContext=default(ActivityContext), IEnumerable< KeyValuePair< string, object?> >? tags=null, IEnumerable< ActivityLink >? links=null, DateTimeOffset startTime=default(DateTimeOffset), [CallerMemberName] string name="")
delegate void Function< T, TParent >(T item, ref ActivityCreationOptions< TParent > data, ref ActivitySamplingResult samplingResult, ref ActivityCreationOptions< ActivityContext > dataWithContext)
void NotifyActivityStart(Activity activity)
static void AddActivityListener(ActivityListener listener)
Activity? StartActivity(string name, ActivityKind kind, ActivityContext parentContext, IEnumerable< KeyValuePair< string, object?> >? tags=null, IEnumerable< ActivityLink >? links=null, DateTimeOffset startTime=default(DateTimeOffset))
static readonly SynchronizedList< ActivityListener > s_allListeners
Activity? CreateActivity(string name, ActivityKind kind)
Activity? StartActivity([CallerMemberName] string name="", ActivityKind kind=ActivityKind.Internal)
void AddListener(ActivityListener listener)
static readonly SynchronizedList< ActivitySource > s_activeSources
static void DetachListener(ActivityListener listener)
void NotifyActivityStop(Activity activity)
ActivitySource(string name, string? version="")
Activity? CreateActivity(string name, ActivityKind kind, string parentId, IEnumerable< KeyValuePair< string, object?> >? tags=null, IEnumerable< ActivityLink >? links=null, ActivityIdFormat idFormat=ActivityIdFormat.Unknown)
Activity? CreateActivity(string name, ActivityKind kind, ActivityContext parentContext, IEnumerable< KeyValuePair< string, object?> >? tags=null, IEnumerable< ActivityLink >? links=null, ActivityIdFormat idFormat=ActivityIdFormat.Unknown)
Activity? StartActivity(string name, ActivityKind kind, string parentId, IEnumerable< KeyValuePair< string, object?> >? tags=null, IEnumerable< ActivityLink >? links=null, DateTimeOffset startTime=default(DateTimeOffset))
SynchronizedList< ActivityListener > _listeners
static Activity Create(ActivitySource source, string name, ActivityKind kind, string parentId, ActivityContext parentContext, IEnumerable< KeyValuePair< string, object > > tags, IEnumerable< ActivityLink > links, DateTimeOffset startTime, ActivityTagsCollection samplerTags, ActivitySamplingResult request, bool startIt, ActivityIdFormat idFormat)
Definition Activity.cs:978
static ? Activity Current
Definition Activity.cs:662
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static int CompareExchange(ref int location1, int value, int comparand)