Delete FriendAccessAllowedAttribute and associated dead code (#15101)
[platform/upstream/coreclr.git] / src / mscorlib / src / System / Diagnostics / Eventing / FrameworkEventSource.cs
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 //
6 // ResourcesEtwProvider.cs
7 //
8 //
9 // Managed event source for things that can version with MSCORLIB.  
10 //
11
12 using System;
13 using System.Collections.Generic;
14 using System.Globalization;
15 using System.Reflection;
16 using System.Text;
17 using System.Runtime.CompilerServices;
18
19 namespace System.Diagnostics.Tracing
20 {
21     // To use the framework provider
22     // 
23     //     \\clrmain\tools\Perfmonitor /nokernel /noclr /provider:8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1 start
24     //     Run run your app
25     //     \\clrmain\tools\Perfmonitor stop
26     //     \\clrmain\tools\Perfmonitor print
27     //
28     // This will produce an XML file, where each event is pretty-printed with all its arguments nicely parsed.
29     //
30     // [FriendAccessAllowed]
31     [EventSource(Guid = "8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1", Name = "System.Diagnostics.Eventing.FrameworkEventSource")]
32     sealed internal class FrameworkEventSource : EventSource
33     {
34         // Defines the singleton instance for the Resources ETW provider
35         public static readonly FrameworkEventSource Log = new FrameworkEventSource();
36
37         // Keyword definitions.  These represent logical groups of events that can be turned on and off independently
38         // Often each task has a keyword, but where tasks are determined by subsystem, keywords are determined by
39         // usefulness to end users to filter.  Generally users don't mind extra events if they are not high volume
40         // so grouping low volume events together in a single keywords is OK (users can post-filter by task if desired)
41         public static class Keywords
42         {
43             public const EventKeywords Loader = (EventKeywords)0x0001; // This is bit 0
44             public const EventKeywords ThreadPool = (EventKeywords)0x0002;
45             public const EventKeywords NetClient = (EventKeywords)0x0004;
46             //
47             // This is a private event we do not want to expose to customers.  It is to be used for profiling
48             // uses of dynamic type loading by ProjectN applications running on the desktop CLR
49             //
50             public const EventKeywords DynamicTypeUsage = (EventKeywords)0x0008;
51             public const EventKeywords ThreadTransfer = (EventKeywords)0x0010;
52         }
53
54         /// <summary>ETW tasks that have start/stop events.</summary>
55         public static class Tasks // this name is important for EventSource
56         {
57             /// <summary>Begin / End - GetResponse.</summary>
58             public const EventTask GetResponse = (EventTask)1;
59             /// <summary>Begin / End - GetRequestStream</summary>
60             public const EventTask GetRequestStream = (EventTask)2;
61             /// <summary>Send / Receive - begin transfer/end transfer</summary>
62             public const EventTask ThreadTransfer = (EventTask)3;
63         }
64
65         public static class Opcodes
66         {
67             public const EventOpcode ReceiveHandled = (EventOpcode)11;
68         }
69
70         // This predicate is used by consumers of this class to deteremine if the class has actually been initialized,
71         // and therefore if the public statics are available for use. This is typically not a problem... if the static
72         // class constructor fails, then attempts to access the statics (or even this property) will result in a 
73         // TypeInitializationException. However, that is not the case while the class loader is actually trying to construct
74         // the TypeInitializationException instance to represent that failure, and some consumers of this class are on
75         // that code path, specifically the resource manager. 
76         public static bool IsInitialized
77         {
78             get
79             {
80                 return Log != null;
81             }
82         }
83
84         // The FrameworkEventSource GUID is {8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1}
85         private FrameworkEventSource() : base(new Guid(0x8e9f5090, 0x2d75, 0x4d03, 0x8a, 0x81, 0xe5, 0xaf, 0xbf, 0x85, 0xda, 0xf1), "System.Diagnostics.Eventing.FrameworkEventSource") { }
86
87         // WriteEvent overloads (to avoid the "params" EventSource.WriteEvent
88
89         // optimized for common signatures (used by the ThreadTransferSend/Receive events)
90         [NonEvent]
91 #if !CORECLR
92         [System.Security.SecuritySafeCritical]
93 #endif // !CORECLR
94         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
95         private unsafe void WriteEvent(int eventId, long arg1, int arg2, string arg3, bool arg4)
96         {
97             if (IsEnabled())
98             {
99                 if (arg3 == null) arg3 = "";
100                 fixed (char* string3Bytes = arg3)
101                 {
102                     EventSource.EventData* descrs = stackalloc EventSource.EventData[4];
103                     descrs[0].DataPointer = (IntPtr)(&arg1);
104                     descrs[0].Size = 8;
105                     descrs[1].DataPointer = (IntPtr)(&arg2);
106                     descrs[1].Size = 4;
107                     descrs[2].DataPointer = (IntPtr)string3Bytes;
108                     descrs[2].Size = ((arg3.Length + 1) * 2);
109                     descrs[3].DataPointer = (IntPtr)(&arg4);
110                     descrs[3].Size = 4;
111                     WriteEventCore(eventId, 4, descrs);
112                 }
113             }
114         }
115
116         // optimized for common signatures (used by the ThreadTransferSend/Receive events)
117         [NonEvent]
118 #if !CORECLR
119         [System.Security.SecuritySafeCritical]
120 #endif // !CORECLR
121         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
122         private unsafe void WriteEvent(int eventId, long arg1, int arg2, string arg3)
123         {
124             if (IsEnabled())
125             {
126                 if (arg3 == null) arg3 = "";
127                 fixed (char* string3Bytes = arg3)
128                 {
129                     EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
130                     descrs[0].DataPointer = (IntPtr)(&arg1);
131                     descrs[0].Size = 8;
132                     descrs[1].DataPointer = (IntPtr)(&arg2);
133                     descrs[1].Size = 4;
134                     descrs[2].DataPointer = (IntPtr)string3Bytes;
135                     descrs[2].Size = ((arg3.Length + 1) * 2);
136                     WriteEventCore(eventId, 3, descrs);
137                 }
138             }
139         }
140
141         // optimized for common signatures (used by the BeginGetResponse/BeginGetRequestStream events)
142         [NonEvent]
143 #if !CORECLR
144         [System.Security.SecuritySafeCritical]
145 #endif // !CORECLR
146         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
147         private unsafe void WriteEvent(int eventId, long arg1, string arg2, bool arg3, bool arg4)
148         {
149             if (IsEnabled())
150             {
151                 if (arg2 == null) arg2 = "";
152                 fixed (char* string2Bytes = arg2)
153                 {
154                     EventSource.EventData* descrs = stackalloc EventSource.EventData[4];
155                     descrs[0].DataPointer = (IntPtr)(&arg1);
156                     descrs[0].Size = 8;
157                     descrs[1].DataPointer = (IntPtr)string2Bytes;
158                     descrs[1].Size = ((arg2.Length + 1) * 2);
159                     descrs[2].DataPointer = (IntPtr)(&arg3);
160                     descrs[2].Size = 4;
161                     descrs[3].DataPointer = (IntPtr)(&arg4);
162                     descrs[3].Size = 4;
163                     WriteEventCore(eventId, 4, descrs);
164                 }
165             }
166         }
167
168         // optimized for common signatures (used by the EndGetRequestStream event)
169         [NonEvent]
170 #if !CORECLR
171         [System.Security.SecuritySafeCritical]
172 #endif // !CORECLR
173         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
174         private unsafe void WriteEvent(int eventId, long arg1, bool arg2, bool arg3)
175         {
176             if (IsEnabled())
177             {
178                 EventSource.EventData* descrs = stackalloc EventSource.EventData[3];
179                 descrs[0].DataPointer = (IntPtr)(&arg1);
180                 descrs[0].Size = 8;
181                 descrs[1].DataPointer = (IntPtr)(&arg2);
182                 descrs[1].Size = 4;
183                 descrs[2].DataPointer = (IntPtr)(&arg3);
184                 descrs[2].Size = 4;
185                 WriteEventCore(eventId, 3, descrs);
186             }
187         }
188
189         // optimized for common signatures (used by the EndGetResponse event)
190         [NonEvent]
191 #if !CORECLR
192         [System.Security.SecuritySafeCritical]
193 #endif // !CORECLR
194         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "This does not need to be correct when racing with other threads")]
195         private unsafe void WriteEvent(int eventId, long arg1, bool arg2, bool arg3, int arg4)
196         {
197             if (IsEnabled())
198             {
199                 EventSource.EventData* descrs = stackalloc EventSource.EventData[4];
200                 descrs[0].DataPointer = (IntPtr)(&arg1);
201                 descrs[0].Size = 8;
202                 descrs[1].DataPointer = (IntPtr)(&arg2);
203                 descrs[1].Size = 4;
204                 descrs[2].DataPointer = (IntPtr)(&arg3);
205                 descrs[2].Size = 4;
206                 descrs[3].DataPointer = (IntPtr)(&arg4);
207                 descrs[3].Size = 4;
208                 WriteEventCore(eventId, 4, descrs);
209             }
210         }
211
212         // ResourceManager Event Definitions 
213
214         [Event(1, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
215         public void ResourceManagerLookupStarted(String baseName, String mainAssemblyName, String cultureName)
216         {
217             WriteEvent(1, baseName, mainAssemblyName, cultureName);
218         }
219
220         [Event(2, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
221         public void ResourceManagerLookingForResourceSet(String baseName, String mainAssemblyName, String cultureName)
222         {
223             if (IsEnabled())
224                 WriteEvent(2, baseName, mainAssemblyName, cultureName);
225         }
226
227         [Event(3, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
228         public void ResourceManagerFoundResourceSetInCache(String baseName, String mainAssemblyName, String cultureName)
229         {
230             if (IsEnabled())
231                 WriteEvent(3, baseName, mainAssemblyName, cultureName);
232         }
233
234         // After loading a satellite assembly, we already have the ResourceSet for this culture in
235         // the cache. This can happen if you have an assembly load callback that called into this
236         // instance of the ResourceManager.
237         [Event(4, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
238         public void ResourceManagerFoundResourceSetInCacheUnexpected(String baseName, String mainAssemblyName, String cultureName)
239         {
240             if (IsEnabled())
241                 WriteEvent(4, baseName, mainAssemblyName, cultureName);
242         }
243
244         // manifest resource stream lookup succeeded
245         [Event(5, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
246         public void ResourceManagerStreamFound(String baseName, String mainAssemblyName, String cultureName, String loadedAssemblyName, String resourceFileName)
247         {
248             if (IsEnabled())
249                 WriteEvent(5, baseName, mainAssemblyName, cultureName, loadedAssemblyName, resourceFileName);
250         }
251
252         // manifest resource stream lookup failed
253         [Event(6, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
254         public void ResourceManagerStreamNotFound(String baseName, String mainAssemblyName, String cultureName, String loadedAssemblyName, String resourceFileName)
255         {
256             if (IsEnabled())
257                 WriteEvent(6, baseName, mainAssemblyName, cultureName, loadedAssemblyName, resourceFileName);
258         }
259
260         [Event(7, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
261         public void ResourceManagerGetSatelliteAssemblySucceeded(String baseName, String mainAssemblyName, String cultureName, String assemblyName)
262         {
263             if (IsEnabled())
264                 WriteEvent(7, baseName, mainAssemblyName, cultureName, assemblyName);
265         }
266
267         [Event(8, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
268         public void ResourceManagerGetSatelliteAssemblyFailed(String baseName, String mainAssemblyName, String cultureName, String assemblyName)
269         {
270             if (IsEnabled())
271                 WriteEvent(8, baseName, mainAssemblyName, cultureName, assemblyName);
272         }
273
274         [Event(9, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
275         public void ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(String baseName, String mainAssemblyName, String assemblyName, String resourceFileName)
276         {
277             if (IsEnabled())
278                 WriteEvent(9, baseName, mainAssemblyName, assemblyName, resourceFileName);
279         }
280
281         [Event(10, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
282         public void ResourceManagerCaseInsensitiveResourceStreamLookupFailed(String baseName, String mainAssemblyName, String assemblyName, String resourceFileName)
283         {
284             if (IsEnabled())
285                 WriteEvent(10, baseName, mainAssemblyName, assemblyName, resourceFileName);
286         }
287
288         // Could not access the manifest resource the assembly
289         [Event(11, Level = EventLevel.Error, Keywords = Keywords.Loader)]
290         public void ResourceManagerManifestResourceAccessDenied(String baseName, String mainAssemblyName, String assemblyName, String canonicalName)
291         {
292             if (IsEnabled())
293                 WriteEvent(11, baseName, mainAssemblyName, assemblyName, canonicalName);
294         }
295
296         // Neutral resources are sufficient for this culture. Skipping satellites
297         [Event(12, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
298         public void ResourceManagerNeutralResourcesSufficient(String baseName, String mainAssemblyName, String cultureName)
299         {
300             if (IsEnabled())
301                 WriteEvent(12, baseName, mainAssemblyName, cultureName);
302         }
303
304         [Event(13, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
305         public void ResourceManagerNeutralResourceAttributeMissing(String mainAssemblyName)
306         {
307             if (IsEnabled())
308                 WriteEvent(13, mainAssemblyName);
309         }
310
311         [Event(14, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
312         public void ResourceManagerCreatingResourceSet(String baseName, String mainAssemblyName, String cultureName, String fileName)
313         {
314             if (IsEnabled())
315                 WriteEvent(14, baseName, mainAssemblyName, cultureName, fileName);
316         }
317
318         [Event(15, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
319         public void ResourceManagerNotCreatingResourceSet(String baseName, String mainAssemblyName, String cultureName)
320         {
321             if (IsEnabled())
322                 WriteEvent(15, baseName, mainAssemblyName, cultureName);
323         }
324
325         [Event(16, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
326         public void ResourceManagerLookupFailed(String baseName, String mainAssemblyName, String cultureName)
327         {
328             if (IsEnabled())
329                 WriteEvent(16, baseName, mainAssemblyName, cultureName);
330         }
331
332         [Event(17, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
333         public void ResourceManagerReleasingResources(String baseName, String mainAssemblyName)
334         {
335             if (IsEnabled())
336                 WriteEvent(17, baseName, mainAssemblyName);
337         }
338
339         [Event(18, Level = EventLevel.Warning, Keywords = Keywords.Loader)]
340         public void ResourceManagerNeutralResourcesNotFound(String baseName, String mainAssemblyName, String resName)
341         {
342             if (IsEnabled())
343                 WriteEvent(18, baseName, mainAssemblyName, resName);
344         }
345
346         [Event(19, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
347         public void ResourceManagerNeutralResourcesFound(String baseName, String mainAssemblyName, String resName)
348         {
349             if (IsEnabled())
350                 WriteEvent(19, baseName, mainAssemblyName, resName);
351         }
352
353         [Event(20, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
354         public void ResourceManagerAddingCultureFromConfigFile(String baseName, String mainAssemblyName, String cultureName)
355         {
356             if (IsEnabled())
357                 WriteEvent(20, baseName, mainAssemblyName, cultureName);
358         }
359
360         [Event(21, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
361         public void ResourceManagerCultureNotFoundInConfigFile(String baseName, String mainAssemblyName, String cultureName)
362         {
363             if (IsEnabled())
364                 WriteEvent(21, baseName, mainAssemblyName, cultureName);
365         }
366
367         [Event(22, Level = EventLevel.Informational, Keywords = Keywords.Loader)]
368         public void ResourceManagerCultureFoundInConfigFile(String baseName, String mainAssemblyName, String cultureName)
369         {
370             if (IsEnabled())
371                 WriteEvent(22, baseName, mainAssemblyName, cultureName);
372         }
373
374
375         // ResourceManager Event Wrappers
376
377         [NonEvent]
378         public void ResourceManagerLookupStarted(String baseName, Assembly mainAssembly, String cultureName)
379         {
380             if (IsEnabled())
381                 ResourceManagerLookupStarted(baseName, GetName(mainAssembly), cultureName);
382         }
383
384         [NonEvent]
385         public void ResourceManagerLookingForResourceSet(String baseName, Assembly mainAssembly, String cultureName)
386         {
387             if (IsEnabled())
388                 ResourceManagerLookingForResourceSet(baseName, GetName(mainAssembly), cultureName);
389         }
390
391         [NonEvent]
392         public void ResourceManagerFoundResourceSetInCache(String baseName, Assembly mainAssembly, String cultureName)
393         {
394             if (IsEnabled())
395                 ResourceManagerFoundResourceSetInCache(baseName, GetName(mainAssembly), cultureName);
396         }
397
398         [NonEvent]
399         public void ResourceManagerFoundResourceSetInCacheUnexpected(String baseName, Assembly mainAssembly, String cultureName)
400         {
401             if (IsEnabled())
402                 ResourceManagerFoundResourceSetInCacheUnexpected(baseName, GetName(mainAssembly), cultureName);
403         }
404
405         [NonEvent]
406         public void ResourceManagerStreamFound(String baseName, Assembly mainAssembly, String cultureName, Assembly loadedAssembly, String resourceFileName)
407         {
408             if (IsEnabled())
409                 ResourceManagerStreamFound(baseName, GetName(mainAssembly), cultureName, GetName(loadedAssembly), resourceFileName);
410         }
411
412         [NonEvent]
413         public void ResourceManagerStreamNotFound(String baseName, Assembly mainAssembly, String cultureName, Assembly loadedAssembly, String resourceFileName)
414         {
415             if (IsEnabled())
416                 ResourceManagerStreamNotFound(baseName, GetName(mainAssembly), cultureName, GetName(loadedAssembly), resourceFileName);
417         }
418
419         [NonEvent]
420         public void ResourceManagerGetSatelliteAssemblySucceeded(String baseName, Assembly mainAssembly, String cultureName, String assemblyName)
421         {
422             if (IsEnabled())
423                 ResourceManagerGetSatelliteAssemblySucceeded(baseName, GetName(mainAssembly), cultureName, assemblyName);
424         }
425
426         [NonEvent]
427         public void ResourceManagerGetSatelliteAssemblyFailed(String baseName, Assembly mainAssembly, String cultureName, String assemblyName)
428         {
429             if (IsEnabled())
430                 ResourceManagerGetSatelliteAssemblyFailed(baseName, GetName(mainAssembly), cultureName, assemblyName);
431         }
432
433         [NonEvent]
434         public void ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(String baseName, Assembly mainAssembly, String assemblyName, String resourceFileName)
435         {
436             if (IsEnabled())
437                 ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(baseName, GetName(mainAssembly), assemblyName, resourceFileName);
438         }
439
440         [NonEvent]
441         public void ResourceManagerCaseInsensitiveResourceStreamLookupFailed(String baseName, Assembly mainAssembly, String assemblyName, String resourceFileName)
442         {
443             if (IsEnabled())
444                 ResourceManagerCaseInsensitiveResourceStreamLookupFailed(baseName, GetName(mainAssembly), assemblyName, resourceFileName);
445         }
446
447         [NonEvent]
448         public void ResourceManagerManifestResourceAccessDenied(String baseName, Assembly mainAssembly, String assemblyName, String canonicalName)
449         {
450             if (IsEnabled())
451                 ResourceManagerManifestResourceAccessDenied(baseName, GetName(mainAssembly), assemblyName, canonicalName);
452         }
453
454         [NonEvent]
455         public void ResourceManagerNeutralResourcesSufficient(String baseName, Assembly mainAssembly, String cultureName)
456         {
457             if (IsEnabled())
458                 ResourceManagerNeutralResourcesSufficient(baseName, GetName(mainAssembly), cultureName);
459         }
460
461         [NonEvent]
462         public void ResourceManagerNeutralResourceAttributeMissing(Assembly mainAssembly)
463         {
464             if (IsEnabled())
465                 ResourceManagerNeutralResourceAttributeMissing(GetName(mainAssembly));
466         }
467
468         [NonEvent]
469         public void ResourceManagerCreatingResourceSet(String baseName, Assembly mainAssembly, String cultureName, String fileName)
470         {
471             if (IsEnabled())
472                 ResourceManagerCreatingResourceSet(baseName, GetName(mainAssembly), cultureName, fileName);
473         }
474
475         [NonEvent]
476         public void ResourceManagerNotCreatingResourceSet(String baseName, Assembly mainAssembly, String cultureName)
477         {
478             if (IsEnabled())
479                 ResourceManagerNotCreatingResourceSet(baseName, GetName(mainAssembly), cultureName);
480         }
481
482         [NonEvent]
483         public void ResourceManagerLookupFailed(String baseName, Assembly mainAssembly, String cultureName)
484         {
485             if (IsEnabled())
486                 ResourceManagerLookupFailed(baseName, GetName(mainAssembly), cultureName);
487         }
488
489         [NonEvent]
490         public void ResourceManagerReleasingResources(String baseName, Assembly mainAssembly)
491         {
492             if (IsEnabled())
493                 ResourceManagerReleasingResources(baseName, GetName(mainAssembly));
494         }
495
496         [NonEvent]
497         public void ResourceManagerNeutralResourcesNotFound(String baseName, Assembly mainAssembly, String resName)
498         {
499             if (IsEnabled())
500                 ResourceManagerNeutralResourcesNotFound(baseName, GetName(mainAssembly), resName);
501         }
502
503         [NonEvent]
504         public void ResourceManagerNeutralResourcesFound(String baseName, Assembly mainAssembly, String resName)
505         {
506             if (IsEnabled())
507                 ResourceManagerNeutralResourcesFound(baseName, GetName(mainAssembly), resName);
508         }
509
510         [NonEvent]
511         public void ResourceManagerAddingCultureFromConfigFile(String baseName, Assembly mainAssembly, String cultureName)
512         {
513             if (IsEnabled())
514                 ResourceManagerAddingCultureFromConfigFile(baseName, GetName(mainAssembly), cultureName);
515         }
516
517         [NonEvent]
518         public void ResourceManagerCultureNotFoundInConfigFile(String baseName, Assembly mainAssembly, String cultureName)
519         {
520             if (IsEnabled())
521                 ResourceManagerCultureNotFoundInConfigFile(baseName, GetName(mainAssembly), cultureName);
522         }
523
524         [NonEvent]
525         public void ResourceManagerCultureFoundInConfigFile(String baseName, Assembly mainAssembly, String cultureName)
526         {
527             if (IsEnabled())
528                 ResourceManagerCultureFoundInConfigFile(baseName, GetName(mainAssembly), cultureName);
529         }
530
531         private static string GetName(Assembly assembly)
532         {
533             if (assembly == null)
534                 return "<<NULL>>";
535             else
536                 return assembly.FullName;
537         }
538
539         [Event(30, Level = EventLevel.Verbose, Keywords = Keywords.ThreadPool | Keywords.ThreadTransfer)]
540         public void ThreadPoolEnqueueWork(long workID)
541         {
542             WriteEvent(30, workID);
543         }
544         [NonEvent]
545 #if !CORECLR
546         [System.Security.SecuritySafeCritical]
547 #endif // !CORECLR
548         public unsafe void ThreadPoolEnqueueWorkObject(object workID)
549         {
550             // convert the Object Id to a long
551             ThreadPoolEnqueueWork((long)*((void**)JitHelpers.UnsafeCastToStackPointer(ref workID)));
552         }
553
554         [Event(31, Level = EventLevel.Verbose, Keywords = Keywords.ThreadPool | Keywords.ThreadTransfer)]
555         public void ThreadPoolDequeueWork(long workID)
556         {
557             WriteEvent(31, workID);
558         }
559
560         [NonEvent]
561 #if !CORECLR
562         [System.Security.SecuritySafeCritical]
563 #endif // !CORECLR
564         public unsafe void ThreadPoolDequeueWorkObject(object workID)
565         {
566             // convert the Object Id to a long
567             ThreadPoolDequeueWork((long)*((void**)JitHelpers.UnsafeCastToStackPointer(ref workID)));
568         }
569
570         // In the desktop runtime they don't use Tasks for the point at which the response happens, which means that the
571         // Activity ID created by start using implicit activity IDs does not match.   Thus disable implicit activities (until we fix that)
572         [Event(140, Level = EventLevel.Informational, Keywords = Keywords.NetClient, ActivityOptions = EventActivityOptions.Disable,
573          Task = Tasks.GetResponse, Opcode = EventOpcode.Start, Version = 1)]
574         private void GetResponseStart(long id, string uri, bool success, bool synchronous)
575         {
576             WriteEvent(140, id, uri, success, synchronous);
577         }
578
579         [Event(141, Level = EventLevel.Informational, Keywords = Keywords.NetClient, ActivityOptions = EventActivityOptions.Disable,
580          Task = Tasks.GetResponse, Opcode = EventOpcode.Stop, Version = 1)]
581         private void GetResponseStop(long id, bool success, bool synchronous, int statusCode)
582         {
583             WriteEvent(141, id, success, synchronous, statusCode);
584         }
585
586         // In the desktop runtime they don't use Tasks for the point at which the response happens, which means that the
587         // Activity ID created by start using implicit activity IDs does not match.   Thus disable implicit activities (until we fix that)
588         [Event(142, Level = EventLevel.Informational, Keywords = Keywords.NetClient, ActivityOptions = EventActivityOptions.Disable,
589          Task = Tasks.GetRequestStream, Opcode = EventOpcode.Start, Version = 1)]
590         private void GetRequestStreamStart(long id, string uri, bool success, bool synchronous)
591         {
592             WriteEvent(142, id, uri, success, synchronous);
593         }
594
595         [Event(143, Level = EventLevel.Informational, Keywords = Keywords.NetClient, ActivityOptions = EventActivityOptions.Disable,
596          Task = Tasks.GetRequestStream, Opcode = EventOpcode.Stop, Version = 1)]
597         private void GetRequestStreamStop(long id, bool success, bool synchronous)
598         {
599             WriteEvent(143, id, success, synchronous);
600         }
601
602         [NonEvent]
603 #if !CORECLR
604         [System.Security.SecuritySafeCritical]
605 #endif // !CORECLR
606         public unsafe void BeginGetResponse(object id, string uri, bool success, bool synchronous)
607         {
608             if (IsEnabled())
609                 GetResponseStart(IdForObject(id), uri, success, synchronous);
610         }
611
612         [NonEvent]
613 #if !CORECLR
614         [System.Security.SecuritySafeCritical]
615 #endif // !CORECLR
616         public unsafe void EndGetResponse(object id, bool success, bool synchronous, int statusCode)
617         {
618             if (IsEnabled())
619                 GetResponseStop(IdForObject(id), success, synchronous, statusCode);
620         }
621
622         [NonEvent]
623 #if !CORECLR
624         [System.Security.SecuritySafeCritical]
625 #endif // !CORECLR
626         public unsafe void BeginGetRequestStream(object id, string uri, bool success, bool synchronous)
627         {
628             if (IsEnabled())
629                 GetRequestStreamStart(IdForObject(id), uri, success, synchronous);
630         }
631
632         [NonEvent]
633 #if !CORECLR
634         [System.Security.SecuritySafeCritical]
635 #endif // !CORECLR
636         public unsafe void EndGetRequestStream(object id, bool success, bool synchronous)
637         {
638             if (IsEnabled())
639                 GetRequestStreamStop(IdForObject(id), success, synchronous);
640         }
641
642         // id -   represents a correlation ID that allows correlation of two activities, one stamped by 
643         //        ThreadTransferSend, the other by ThreadTransferReceive
644         // kind - identifies the transfer: values below 64 are reserved for the runtime. Currently used values:
645         //        1 - managed Timers ("roaming" ID)
646         //        2 - managed async IO operations (FileStream, PipeStream, a.o.)
647         //        3 - WinRT dispatch operations
648         // info - any additional information user code might consider interesting
649         [Event(150, Level = EventLevel.Informational, Keywords = Keywords.ThreadTransfer, Task = Tasks.ThreadTransfer, Opcode = EventOpcode.Send)]
650         public void ThreadTransferSend(long id, int kind, string info, bool multiDequeues)
651         {
652             if (IsEnabled())
653                 WriteEvent(150, id, kind, info, multiDequeues);
654         }
655         // id - is a managed object. it gets translated to the object's address. ETW listeners must
656         //      keep track of GC movements in order to correlate the value passed to XyzSend with the
657         //      (possibly changed) value passed to XyzReceive
658         [NonEvent]
659 #if !CORECLR
660         [System.Security.SecuritySafeCritical]
661 #endif // !CORECLR
662         public unsafe void ThreadTransferSendObj(object id, int kind, string info, bool multiDequeues)
663         {
664             ThreadTransferSend((long)*((void**)JitHelpers.UnsafeCastToStackPointer(ref id)), kind, info, multiDequeues);
665         }
666
667         // id -   represents a correlation ID that allows correlation of two activities, one stamped by 
668         //        ThreadTransferSend, the other by ThreadTransferReceive
669         // kind - identifies the transfer: values below 64 are reserved for the runtime. Currently used values:
670         //        1 - managed Timers ("roaming" ID)
671         //        2 - managed async IO operations (FileStream, PipeStream, a.o.)
672         //        3 - WinRT dispatch operations
673         // info - any additional information user code might consider interesting
674         [Event(151, Level = EventLevel.Informational, Keywords = Keywords.ThreadTransfer, Task = Tasks.ThreadTransfer, Opcode = EventOpcode.Receive)]
675         public void ThreadTransferReceive(long id, int kind, string info)
676         {
677             if (IsEnabled())
678                 WriteEvent(151, id, kind, info);
679         }
680         // id - is a managed object. it gets translated to the object's address. ETW listeners must
681         //      keep track of GC movements in order to correlate the value passed to XyzSend with the
682         //      (possibly changed) value passed to XyzReceive
683         [NonEvent]
684 #if !CORECLR
685         [System.Security.SecuritySafeCritical]
686 #endif // !CORECLR
687         public unsafe void ThreadTransferReceiveObj(object id, int kind, string info)
688         {
689             ThreadTransferReceive((long)*((void**)JitHelpers.UnsafeCastToStackPointer(ref id)), kind, info);
690         }
691
692         // id -   represents a correlation ID that allows correlation of two activities, one stamped by 
693         //        ThreadTransferSend, the other by ThreadTransferReceive
694         // kind - identifies the transfer: values below 64 are reserved for the runtime. Currently used values:
695         //        1 - managed Timers ("roaming" ID)
696         //        2 - managed async IO operations (FileStream, PipeStream, a.o.)
697         //        3 - WinRT dispatch operations
698         // info - any additional information user code might consider interesting
699         [Event(152, Level = EventLevel.Informational, Keywords = Keywords.ThreadTransfer, Task = Tasks.ThreadTransfer, Opcode = Opcodes.ReceiveHandled)]
700         public void ThreadTransferReceiveHandled(long id, int kind, string info)
701         {
702             if (IsEnabled())
703                 WriteEvent(152, id, kind, info);
704         }
705         // id - is a managed object. it gets translated to the object's address. ETW listeners must
706         //      keep track of GC movements in order to correlate the value passed to XyzSend with the
707         //      (possibly changed) value passed to XyzReceive
708         [NonEvent]
709 #if !CORECLR
710         [System.Security.SecuritySafeCritical]
711 #endif // !CORECLR
712         public unsafe void ThreadTransferReceiveHandledObj(object id, int kind, string info)
713         {
714             ThreadTransferReceive((long)*((void**)JitHelpers.UnsafeCastToStackPointer(ref id)), kind, info);
715         }
716
717         // return a stable ID for a an object.  We use the hash code which is not truely unique but is 
718         // close enough for now at least. we add to it 0x7FFFFFFF00000000 to make it distinguishable
719         // from the style of ID that simply casts the object reference to a long (since old versions of the 
720         // runtime will emit IDs of that form).  
721         private static long IdForObject(object obj)
722         {
723             return obj.GetHashCode() + 0x7FFFFFFF00000000;
724         }
725     }
726 }
727