Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HttpTelemetry.cs
Go to the documentation of this file.
4
5namespace System.Net.Http;
6
7[EventSource(Name = "System.Net.Http")]
8internal sealed class HttpTelemetry : EventSource
9{
10 public static readonly HttpTelemetry Log = new HttpTelemetry();
11
12 private long _startedRequests;
13
14 private long _stoppedRequests;
15
16 private long _failedRequests;
17
19
21
23
25
27
29
31
33
35
37
39
40 [Event(1, Level = EventLevel.Informational)]
41 private void RequestStart(string scheme, string host, int port, string pathAndQuery, byte versionMajor, byte versionMinor, HttpVersionPolicy versionPolicy)
42 {
44 WriteEvent(1, scheme, host, port, pathAndQuery, versionMajor, versionMinor, versionPolicy);
45 }
46
47 [NonEvent]
48 public void RequestStart(HttpRequestMessage request)
49 {
50 RequestStart(request.RequestUri.Scheme, request.RequestUri.IdnHost, request.RequestUri.Port, request.RequestUri.PathAndQuery, (byte)request.Version.Major, (byte)request.Version.Minor, request.VersionPolicy);
51 }
52
53 [Event(2, Level = EventLevel.Informational)]
54 public void RequestStop()
55 {
57 WriteEvent(2);
58 }
59
60 [Event(3, Level = EventLevel.Error)]
61 public void RequestFailed()
62 {
64 WriteEvent(3);
65 }
66
67 [Event(4, Level = EventLevel.Informational)]
68 private void ConnectionEstablished(byte versionMajor, byte versionMinor)
69 {
70 WriteEvent(4, versionMajor, versionMinor);
71 }
72
73 [Event(5, Level = EventLevel.Informational)]
74 private void ConnectionClosed(byte versionMajor, byte versionMinor)
75 {
76 WriteEvent(5, versionMajor, versionMinor);
77 }
78
79 [Event(6, Level = EventLevel.Informational)]
80 private void RequestLeftQueue(double timeOnQueueMilliseconds, byte versionMajor, byte versionMinor)
81 {
82 WriteEvent(6, timeOnQueueMilliseconds, versionMajor, versionMinor);
83 }
84
85 [Event(7, Level = EventLevel.Informational)]
86 public void RequestHeadersStart()
87 {
88 WriteEvent(7);
89 }
90
91 [Event(8, Level = EventLevel.Informational)]
92 public void RequestHeadersStop()
93 {
94 WriteEvent(8);
95 }
96
97 [Event(9, Level = EventLevel.Informational)]
98 public void RequestContentStart()
99 {
100 WriteEvent(9);
101 }
102
103 [Event(10, Level = EventLevel.Informational)]
104 public void RequestContentStop(long contentLength)
105 {
106 WriteEvent(10, contentLength);
107 }
108
109 [Event(11, Level = EventLevel.Informational)]
111 {
112 WriteEvent(11);
113 }
114
115 [Event(12, Level = EventLevel.Informational)]
117 {
118 WriteEvent(12);
119 }
120
121 [Event(13, Level = EventLevel.Informational)]
123 {
124 WriteEvent(13);
125 }
126
127 [Event(14, Level = EventLevel.Informational)]
129 {
130 WriteEvent(14);
131 }
132
133 [NonEvent]
139
140 [NonEvent]
142 {
144 ConnectionClosed(1, 1);
145 }
146
147 [NonEvent]
153
154 [NonEvent]
156 {
158 ConnectionClosed(2, 0);
159 }
160
161 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
162 [NonEvent]
163 private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3, string arg4, byte arg5, byte arg6, HttpVersionPolicy arg7)
164 {
165 //The blocks IL_004b, IL_004e, IL_0060, IL_01e3 are reachable both inside and outside the pinned region starting at IL_0048. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement.
166 if (!IsEnabled())
167 {
168 return;
169 }
170 if (arg1 == null)
171 {
172 arg1 = "";
173 }
174 if (arg2 == null)
175 {
176 arg2 = "";
177 }
178 if (arg4 == null)
179 {
180 arg4 = "";
181 }
182 fixed (char* ptr5 = arg1)
183 {
184 char* intPtr;
185 EventData* intPtr2;
186 nint num;
187 nint num2;
188 nint num3;
189 nint num4;
190 nint num5;
191 nint num6;
192 if (arg2 == null)
193 {
194 char* ptr;
195 intPtr = (ptr = null);
196 fixed (char* ptr2 = arg4)
197 {
198 char* ptr3 = ptr2;
199 EventData* ptr4 = stackalloc EventData[7];
200 intPtr2 = ptr4;
201 *intPtr2 = new EventData
202 {
203 DataPointer = (IntPtr)ptr5,
204 Size = (arg1.Length + 1) * 2
205 };
206 num = (nint)(ptr4 + 1);
207 *(EventData*)num = new EventData
208 {
209 DataPointer = (IntPtr)ptr,
210 Size = (arg2.Length + 1) * 2
211 };
212 num2 = (nint)(ptr4 + 2);
213 *(EventData*)num2 = new EventData
214 {
215 DataPointer = (IntPtr)(&arg3),
216 Size = 4
217 };
218 num3 = (nint)(ptr4 + 3);
219 *(EventData*)num3 = new EventData
220 {
221 DataPointer = (IntPtr)ptr3,
222 Size = (arg4.Length + 1) * 2
223 };
224 num4 = (nint)(ptr4 + 4);
225 *(EventData*)num4 = new EventData
226 {
227 DataPointer = (IntPtr)(&arg5),
228 Size = 1
229 };
230 num5 = (nint)(ptr4 + 5);
231 *(EventData*)num5 = new EventData
232 {
233 DataPointer = (IntPtr)(&arg6),
234 Size = 1
235 };
236 num6 = (nint)(ptr4 + 6);
237 *(EventData*)num6 = new EventData
238 {
239 DataPointer = (IntPtr)(&arg7),
240 Size = 4
241 };
242 WriteEventCore(eventId, 7, ptr4);
243 }
244 return;
245 }
246 fixed (char* ptr6 = &arg2.GetPinnableReference())
247 {
248 char* ptr;
249 intPtr = (ptr = ptr6);
250 fixed (char* ptr2 = arg4)
251 {
252 char* ptr3 = ptr2;
253 EventData* ptr4 = stackalloc EventData[7];
254 intPtr2 = ptr4;
255 *intPtr2 = new EventData
256 {
257 DataPointer = (IntPtr)ptr5,
258 Size = (arg1.Length + 1) * 2
259 };
260 num = (nint)(ptr4 + 1);
261 *(EventData*)num = new EventData
262 {
263 DataPointer = (IntPtr)ptr,
264 Size = (arg2.Length + 1) * 2
265 };
266 num2 = (nint)(ptr4 + 2);
267 *(EventData*)num2 = new EventData
268 {
269 DataPointer = (IntPtr)(&arg3),
270 Size = 4
271 };
272 num3 = (nint)(ptr4 + 3);
273 *(EventData*)num3 = new EventData
274 {
275 DataPointer = (IntPtr)ptr3,
276 Size = (arg4.Length + 1) * 2
277 };
278 num4 = (nint)(ptr4 + 4);
279 *(EventData*)num4 = new EventData
280 {
281 DataPointer = (IntPtr)(&arg5),
282 Size = 1
283 };
284 num5 = (nint)(ptr4 + 5);
285 *(EventData*)num5 = new EventData
286 {
287 DataPointer = (IntPtr)(&arg6),
288 Size = 1
289 };
290 num6 = (nint)(ptr4 + 6);
291 *(EventData*)num6 = new EventData
292 {
293 DataPointer = (IntPtr)(&arg7),
294 Size = 4
295 };
296 WriteEventCore(eventId, 7, ptr4);
297 }
298 }
299 }
300 }
301
302 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
303 [NonEvent]
304 private unsafe void WriteEvent(int eventId, double arg1, byte arg2, byte arg3)
305 {
306 if (IsEnabled())
307 {
308 EventData* ptr = stackalloc EventData[3];
309 *ptr = new EventData
310 {
311 DataPointer = (IntPtr)(&arg1),
312 Size = 8
313 };
314 ptr[1] = new EventData
315 {
316 DataPointer = (IntPtr)(&arg2),
317 Size = 1
318 };
319 ptr[2] = new EventData
320 {
321 DataPointer = (IntPtr)(&arg3),
322 Size = 1
323 };
324 WriteEventCore(eventId, 3, ptr);
325 }
326 }
327
328 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe")]
329 [NonEvent]
330 private unsafe void WriteEvent(int eventId, byte arg1, byte arg2)
331 {
332 if (IsEnabled())
333 {
334 EventData* ptr = stackalloc EventData[2];
335 *ptr = new EventData
336 {
337 DataPointer = (IntPtr)(&arg1),
338 Size = 1
339 };
340 ptr[1] = new EventData
341 {
342 DataPointer = (IntPtr)(&arg2),
343 Size = 1
344 };
345 WriteEventCore(eventId, 2, ptr);
346 }
347 }
348
349 [NonEvent]
350 public void Http11RequestLeftQueue(double timeOnQueueMilliseconds)
351 {
352 _http11RequestsQueueDurationCounter.WriteMetric(timeOnQueueMilliseconds);
353 RequestLeftQueue(timeOnQueueMilliseconds, 1, 1);
354 }
355
356 [NonEvent]
357 public void Http20RequestLeftQueue(double timeOnQueueMilliseconds)
358 {
359 _http20RequestsQueueDurationCounter.WriteMetric(timeOnQueueMilliseconds);
360 RequestLeftQueue(timeOnQueueMilliseconds, 2, 0);
361 }
362
363 protected override void OnEventCommand(EventCommandEventArgs command)
364 {
365 if (command.Command != EventCommand.Enable)
366 {
367 return;
368 }
369 if (_startedRequestsCounter == null)
370 {
371 _startedRequestsCounter = new PollingCounter("requests-started", this, () => Interlocked.Read(ref _startedRequests))
372 {
373 DisplayName = "Requests Started"
374 };
375 }
377 {
379 {
380 DisplayName = "Requests Started Rate",
381 DisplayRateTimeScale = TimeSpan.FromSeconds(1.0)
382 };
383 }
384 if (_failedRequestsCounter == null)
385 {
386 _failedRequestsCounter = new PollingCounter("requests-failed", this, () => Interlocked.Read(ref _failedRequests))
387 {
388 DisplayName = "Requests Failed"
389 };
390 }
392 {
394 {
395 DisplayName = "Requests Failed Rate",
396 DisplayRateTimeScale = TimeSpan.FromSeconds(1.0)
397 };
398 }
399 if (_currentRequestsCounter == null)
400 {
402 {
403 DisplayName = "Current Requests"
404 };
405 }
407 {
408 _totalHttp11ConnectionsCounter = new PollingCounter("http11-connections-current-total", this, () => Interlocked.Read(ref _openedHttp11Connections))
409 {
410 DisplayName = "Current Http 1.1 Connections"
411 };
412 }
414 {
415 _totalHttp20ConnectionsCounter = new PollingCounter("http20-connections-current-total", this, () => Interlocked.Read(ref _openedHttp20Connections))
416 {
417 DisplayName = "Current Http 2.0 Connections"
418 };
419 }
421 {
422 _http11RequestsQueueDurationCounter = new EventCounter("http11-requests-queue-duration", this)
423 {
424 DisplayName = "HTTP 1.1 Requests Queue Duration",
425 DisplayUnits = "ms"
426 };
427 }
429 {
430 _http20RequestsQueueDurationCounter = new EventCounter("http20-requests-queue-duration", this)
431 {
432 DisplayName = "HTTP 2.0 Requests Queue Duration",
433 DisplayUnits = "ms"
434 };
435 }
436 }
437}
unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
PollingCounter _totalHttp11ConnectionsCounter
override void OnEventCommand(EventCommandEventArgs command)
void Http20RequestLeftQueue(double timeOnQueueMilliseconds)
void RequestContentStop(long contentLength)
IncrementingPollingCounter _startedRequestsPerSecondCounter
PollingCounter _startedRequestsCounter
PollingCounter _failedRequestsCounter
void RequestLeftQueue(double timeOnQueueMilliseconds, byte versionMajor, byte versionMinor)
unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3, string arg4, byte arg5, byte arg6, HttpVersionPolicy arg7)
unsafe void WriteEvent(int eventId, byte arg1, byte arg2)
void ConnectionClosed(byte versionMajor, byte versionMinor)
void Http11RequestLeftQueue(double timeOnQueueMilliseconds)
void ConnectionEstablished(byte versionMajor, byte versionMinor)
PollingCounter _totalHttp20ConnectionsCounter
IncrementingPollingCounter _failedRequestsPerSecondCounter
static readonly HttpTelemetry Log
unsafe void WriteEvent(int eventId, double arg1, byte arg2, byte arg3)
void RequestStart(string scheme, string host, int port, string pathAndQuery, byte versionMajor, byte versionMinor, HttpVersionPolicy versionPolicy)
EventCounter _http20RequestsQueueDurationCounter
void RequestStart(HttpRequestMessage request)
PollingCounter _currentRequestsCounter
EventCounter _http11RequestsQueueDurationCounter
static int Decrement(ref int location)
static long Read(ref long location)
static int Increment(ref int location)
string IdnHost
Definition Uri.cs:537
string PathAndQuery
Definition Uri.cs:378
string Scheme
Definition Uri.cs:505
int Port
Definition Uri.cs:453
static TimeSpan FromSeconds(double value)
Definition TimeSpan.cs:247