Debian Codegraph @

mcs/class/referencesource/mscorlib/system/collections/Concurrent/CDSCollectionETWBCLProvider.cs

raw
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7 //
8 // CDSCollectionETWBCLProvider.cs
9 //
10 // <OWNER>Microsoft</OWNER>
11 //
12 // A helper class for firing ETW events related to the Coordination Data Structure
13 // collection types. This provider is used by CDS collections in both mscorlib.dll
14 // and System.dll. The purpose of sharing the provider class is to be able to enable
15 // ETW tracing on all CDS collection with a single ETW provider GUID, and to minimize
16 // the number of providers in use.
17 //
18 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
19 using System;
20 using System.Collections.Generic;
21 using System.Text;
22
23 namespace System.Collections.Concurrent
24 {
25 #if !FEATURE_PAL // PAL doesn't support eventing
26 using System.Diagnostics.Tracing;
27
28 /// <summary>Provides an event source for tracing CDS collection information.</summary>
29 [System.Runtime.CompilerServices.FriendAccessAllowed]
30 [EventSource(
31 Name = "System.Collections.Concurrent.ConcurrentCollectionsEventSource",
32 Guid = "35167F8E-49B2-4b96-AB86-435B59336B5E",
33 LocalizationResources = "mscorlib")]
34 internal sealed class CDSCollectionETWBCLProvider : EventSource
35 {
36 /// <summary>
37 /// Defines the singleton instance for the collection ETW provider.
38 /// The collection provider GUID is {35167F8E-49B2-4b96-AB86-435B59336B5E}.
39 /// </summary>
40 public static CDSCollectionETWBCLProvider Log = new CDSCollectionETWBCLProvider();
41 /// <summary>Prevent external instantiation. All logging should go through the Log instance.</summary>
42 private CDSCollectionETWBCLProvider() { }
43
44 /// <summary>Enabled for all keywords.</summary>
45 private const EventKeywords ALL_KEYWORDS = (EventKeywords)(-1);
46
47 //-----------------------------------------------------------------------------------
48 //
49 // CDS Collection Event IDs (must be unique)
50 //
51
52 private const int CONCURRENTSTACK_FASTPUSHFAILED_ID = 1;
53 private const int CONCURRENTSTACK_FASTPOPFAILED_ID = 2;
54 private const int CONCURRENTDICTIONARY_ACQUIRINGALLLOCKS_ID = 3;
55 private const int CONCURRENTBAG_TRYTAKESTEALS_ID = 4;
56 private const int CONCURRENTBAG_TRYPEEKSTEALS_ID = 5;
57
58
59 /////////////////////////////////////////////////////////////////////////////////////
60 //
61 // ConcurrentStack Events
62 //
63
64 [Event(CONCURRENTSTACK_FASTPUSHFAILED_ID, Level = EventLevel.Warning)]
65 public void ConcurrentStack_FastPushFailed(int spinCount)
66 {
67 if (IsEnabled(EventLevel.Warning, ALL_KEYWORDS))
68 {
69 WriteEvent(CONCURRENTSTACK_FASTPUSHFAILED_ID, spinCount);
70 }
71 }
72
73 [Event(CONCURRENTSTACK_FASTPOPFAILED_ID, Level = EventLevel.Warning)]
74 public void ConcurrentStack_FastPopFailed(int spinCount)
75 {
76 if (IsEnabled(EventLevel.Warning, ALL_KEYWORDS))
77 {
78 WriteEvent(CONCURRENTSTACK_FASTPOPFAILED_ID, spinCount);
79 }
80 }
81
82
83 /////////////////////////////////////////////////////////////////////////////////////
84 //
85 // ConcurrentDictionary Events
86 //
87
88 [Event(CONCURRENTDICTIONARY_ACQUIRINGALLLOCKS_ID, Level = EventLevel.Warning)]
89 public void ConcurrentDictionary_AcquiringAllLocks(int numOfBuckets)
90 {
91 if (IsEnabled(EventLevel.Warning, ALL_KEYWORDS))
92 {
93 WriteEvent(CONCURRENTDICTIONARY_ACQUIRINGALLLOCKS_ID, numOfBuckets);
94 }
95 }
96
97
98
99 //
100 // Events below this point are used by the CDS types in System.DLL
101 //
102
103 /////////////////////////////////////////////////////////////////////////////////////
104 //
105 // ConcurrentBag Events
106 //
107
108 [Event(CONCURRENTBAG_TRYTAKESTEALS_ID, Level = EventLevel.Verbose)]
109 public void ConcurrentBag_TryTakeSteals()
110 {
111 if (IsEnabled(EventLevel.Verbose, ALL_KEYWORDS))
112 {
113 WriteEvent(CONCURRENTBAG_TRYTAKESTEALS_ID);
114 }
115 }
116
117 [Event(CONCURRENTBAG_TRYPEEKSTEALS_ID, Level = EventLevel.Verbose)]
118 public void ConcurrentBag_TryPeekSteals()
119 {
120 if (IsEnabled(EventLevel.Verbose, ALL_KEYWORDS))
121 {
122 WriteEvent(CONCURRENTBAG_TRYPEEKSTEALS_ID);
123 }
124 }
125 }
126
127 #endif // !FEATURE_PAL
128 }