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 | // Mdperf.h |
6 | // |
7 | |
8 | // |
9 | //***************************************************************************** |
10 | |
11 | #ifndef __MDCOMPILERPERF_H__ |
12 | #define __MDCOMPILERPERF_H__ |
13 | |
14 | //#define FEATURE_METADATA_PERF_STATS |
15 | |
16 | #ifdef FEATURE_METADATA_PERF_STATS |
17 | |
18 | // Avoid dynamic allocs to display the API names. |
19 | #define API_NAME_STR_SIZE 80 |
20 | |
21 | //----------------------------------------------------------------------------- |
22 | // In order to add instrumentation for an API, two changes have to be made. |
23 | // One, add the API name in the table below (MD_TABLE). |
24 | // Second, add two lines of code (shown below) in the implementation |
25 | // of the API itself. e.g. |
26 | // RegMeta::MyNewMetataDataAPI(...) |
27 | // { |
28 | // LOG(...); |
29 | // START_MD_PERF(); // <------ add this line as is. |
30 | // .... |
31 | // // API implementation |
32 | // ErrExit: |
33 | // STOP_MD_PERF(RegMeta_MyNewMetaDataAPI); // <---------- add this line with the appropriate name |
34 | // return (hr); |
35 | // ] |
36 | // |
37 | //----------------------------------------------------------------------------- |
38 | #define MD_COMPILER_PERF_TABLE\ |
39 | MD_FUNC(SaveToMemory)\ |
40 | MD_FUNC(DefineMethod)\ |
41 | MD_FUNC(DefineMethodImpl)\ |
42 | MD_FUNC(SetRVA)\ |
43 | MD_FUNC(DefineTypeRefByName)\ |
44 | MD_FUNC(DefineImportType)\ |
45 | MD_FUNC(DefineMemberRef)\ |
46 | MD_FUNC(DefineImportMember)\ |
47 | MD_FUNC(DefineEvent)\ |
48 | MD_FUNC(SetClassLayout)\ |
49 | MD_FUNC(DeleteClassLayout)\ |
50 | MD_FUNC(SetFieldMarshal)\ |
51 | MD_FUNC(DeleteFieldMarshal)\ |
52 | MD_FUNC(DefinePermissionSet)\ |
53 | MD_FUNC(SetMemberIndex)\ |
54 | MD_FUNC(GetTokenFromSig)\ |
55 | MD_FUNC(DefineModuleRef)\ |
56 | MD_FUNC(SetParent)\ |
57 | MD_FUNC(GetTokenFromTypeSpec)\ |
58 | MD_FUNC(DefineUserString)\ |
59 | MD_FUNC(DeleteToken)\ |
60 | MD_FUNC(SetTypeDefProps)\ |
61 | MD_FUNC(DefineNestedType)\ |
62 | MD_FUNC(SetMethodProps)\ |
63 | MD_FUNC(SetEventProps)\ |
64 | MD_FUNC(SetPermissionSetProps)\ |
65 | MD_FUNC(DefinePinvokeMap)\ |
66 | MD_FUNC(SetPinvokeMap)\ |
67 | MD_FUNC(DeletePinvokeMap)\ |
68 | MD_FUNC(DefineField)\ |
69 | MD_FUNC(DefineProperty)\ |
70 | MD_FUNC(DefineParam)\ |
71 | MD_FUNC(SetFieldProps)\ |
72 | MD_FUNC(SetPropertyProps)\ |
73 | MD_FUNC(SetParamProps)\ |
74 | MD_FUNC(EnumMembers)\ |
75 | MD_FUNC(EnumMembersWithName)\ |
76 | MD_FUNC(EnumMethods)\ |
77 | MD_FUNC(EnumMethodsWithName)\ |
78 | MD_FUNC(EnumFields)\ |
79 | MD_FUNC(EnumFieldsWithName)\ |
80 | MD_FUNC(EnumParams)\ |
81 | MD_FUNC(EnumMemberRefs)\ |
82 | MD_FUNC(EnumMethodImpls)\ |
83 | MD_FUNC(EnumPermissionSets)\ |
84 | MD_FUNC(FindMember)\ |
85 | MD_FUNC(FindMethod)\ |
86 | MD_FUNC(FindField)\ |
87 | MD_FUNC(FindMemberRef)\ |
88 | MD_FUNC(GetMethodProps)\ |
89 | MD_FUNC(GetMemberRefProps)\ |
90 | MD_FUNC(EnumProperties)\ |
91 | MD_FUNC(EnumEvents)\ |
92 | MD_FUNC(GetEventProps)\ |
93 | MD_FUNC(EnumMethodSemantics)\ |
94 | MD_FUNC(GetMethodSemantics)\ |
95 | MD_FUNC(GetClassLayout)\ |
96 | MD_FUNC(GetFieldMarshal)\ |
97 | MD_FUNC(GetRVA)\ |
98 | MD_FUNC(GetPermissionSetProps)\ |
99 | MD_FUNC(GetSigFromToken)\ |
100 | MD_FUNC(GetModuleRefProps)\ |
101 | MD_FUNC(EnumModuleRefs)\ |
102 | MD_FUNC(GetTypeSpecFromToken)\ |
103 | MD_FUNC(GetNameFromToken)\ |
104 | MD_FUNC(EnumUnresolvedMethods)\ |
105 | MD_FUNC(GetUserString)\ |
106 | MD_FUNC(GetPinvokeMap)\ |
107 | MD_FUNC(EnumSignatures)\ |
108 | MD_FUNC(EnumTypeSpecs)\ |
109 | MD_FUNC(EnumUserStrings)\ |
110 | MD_FUNC(GetParamForMethodIndex)\ |
111 | MD_FUNC(GetMemberProps)\ |
112 | MD_FUNC(GetFieldProps)\ |
113 | MD_FUNC(GetPropertyProps)\ |
114 | MD_FUNC(GetParamProps)\ |
115 | MD_FUNC(SetModuleProps)\ |
116 | MD_FUNC(Save)\ |
117 | MD_FUNC(SaveToStream)\ |
118 | MD_FUNC(GetSaveSize)\ |
119 | MD_FUNC(Merge)\ |
120 | MD_FUNC(DefineCustomAttribute)\ |
121 | MD_FUNC(SetCustomAttributeValue)\ |
122 | MD_FUNC(DefineSecurityAttributeSet)\ |
123 | MD_FUNC(UnmarkAll)\ |
124 | MD_FUNC(MarkToken)\ |
125 | MD_FUNC(IsTokenMarked)\ |
126 | MD_FUNC(DefineTypeDef)\ |
127 | MD_FUNC(SetHandler)\ |
128 | MD_FUNC(CountEnum)\ |
129 | MD_FUNC(ResetEnum)\ |
130 | MD_FUNC(EnumTypeDefs)\ |
131 | MD_FUNC(EnumInterfaceImpls)\ |
132 | MD_FUNC(EnumTypeRefs)\ |
133 | MD_FUNC(FindTypeDefByName)\ |
134 | MD_FUNC(FindTypeDefByGUID)\ |
135 | MD_FUNC(GetScopeProps)\ |
136 | MD_FUNC(GetModuleFromScope)\ |
137 | MD_FUNC(GetTypeDefProps)\ |
138 | MD_FUNC(GetInterfaceImplProps)\ |
139 | MD_FUNC(GetCustomAttributeByName)\ |
140 | MD_FUNC(GetTypeRefProps)\ |
141 | MD_FUNC(ResolveTypeRef)\ |
142 | MD_FUNC(EnumCustomAttributes)\ |
143 | MD_FUNC(GetCustomAttributeProps)\ |
144 | MD_FUNC(FindTypeRef)\ |
145 | MD_FUNC(RefToDefOptimization)\ |
146 | MD_FUNC(DefineAssembly)\ |
147 | MD_FUNC(DefineAssemblyRef)\ |
148 | MD_FUNC(DefineFile)\ |
149 | MD_FUNC(DefineExportedType)\ |
150 | MD_FUNC(DefineManifestResource)\ |
151 | MD_FUNC(DefineExecutionLocation)\ |
152 | MD_FUNC(SetAssemblyProps)\ |
153 | MD_FUNC(SetAssemblyRefProps)\ |
154 | MD_FUNC(SetFileProps)\ |
155 | MD_FUNC(SetExportedTypeProps)\ |
156 | MD_FUNC(GetAssemblyProps)\ |
157 | MD_FUNC(GetAssemblyRefProps)\ |
158 | MD_FUNC(GetFileProps)\ |
159 | MD_FUNC(GetExportedTypeProps)\ |
160 | MD_FUNC(GetManifestResourceProps)\ |
161 | MD_FUNC(EnumAssemblyRefs)\ |
162 | MD_FUNC(EnumFiles)\ |
163 | MD_FUNC(EnumExportedTypes)\ |
164 | MD_FUNC(EnumManifestResources)\ |
165 | MD_FUNC(EnumExecutionLocations)\ |
166 | MD_FUNC(GetAssemblyFromScope)\ |
167 | MD_FUNC(FindExportedTypeByName)\ |
168 | MD_FUNC(FindManifestResourceByName)\ |
169 | MD_FUNC(FindAssembliesByName)\ |
170 | MD_FUNC(SetGenericPars)\ |
171 | MD_FUNC(DefineGenericParam)\ |
172 | MD_FUNC(SetGenericParamProps)\ |
173 | MD_FUNC(EnumGenericParamConstraints)\ |
174 | MD_FUNC(GetGenericParamProps)\ |
175 | MD_FUNC(GetGenericParamConstraintProps)\ |
176 | MD_FUNC(GetPEKind)\ |
177 | MD_FUNC(GetVersionString)\ |
178 | MD_FUNC(GetAssemblyUnification) |
179 | |
180 | //----------------------------------------------------------------------------- |
181 | // Create an enum of all the API names. This is the index to access the APIs. |
182 | //----------------------------------------------------------------------------- |
183 | #undef MD_FUNC |
184 | #define MD_FUNC(MDTag)\ |
185 | MDTag ## _ENUM, |
186 | |
187 | typedef enum _MDAPIs |
188 | { |
189 | MD_COMPILER_PERF_TABLE |
190 | LAST_MD_API |
191 | } MDApis; |
192 | |
193 | //----------------------------------------------------------------------------- |
194 | // Declare the struct which contais all the interesting stats for a particular |
195 | // API call. |
196 | //----------------------------------------------------------------------------- |
197 | typedef struct _MDAPIPerfData |
198 | { |
199 | DWORD dwQueryPerfCycles; // # of cycles spent in this call |
200 | DWORD dwCalledNumTimes; // # of times this API was called |
201 | } MDAPIPerfData; |
202 | |
203 | |
204 | //----------------------------------------------------------------------------- |
205 | // MDCompilerPerf |
206 | //----------------------------------------------------------------------------- |
207 | class MDCompilerPerf |
208 | { |
209 | public: |
210 | MDCompilerPerf(); |
211 | ~MDCompilerPerf(); |
212 | |
213 | private: |
214 | MDAPIPerfData MDPerfStats[LAST_MD_API]; |
215 | |
216 | void MetaDataPerfReport (); |
217 | }; |
218 | |
219 | // Note that this macro declares a local var. |
220 | #define START_MD_PERF()\ |
221 | LARGE_INTEGER __startVal;\ |
222 | QueryPerformanceCounter(&__startVal); |
223 | |
224 | #undef MD_FUNC |
225 | #define MD_FUNC(MDTag)\ |
226 | MDTag ## _ENUM |
227 | |
228 | // Note that this macro uses the local var startVal declared in START_MD_PERF() |
229 | #define STOP_MD_PERF(MDTag)\ |
230 | LARGE_INTEGER __stopVal;\ |
231 | QueryPerformanceCounter(&__stopVal);\ |
232 | m_MDCompilerPerf.MDPerfStats[MD_FUNC(MDTag)].dwCalledNumTimes++;\ |
233 | m_MDCompilerPerf.MDPerfStats[MD_FUNC(MDTag)].dwQueryPerfCycles += (DWORD)(__stopVal.QuadPart - __startVal.QuadPart); |
234 | |
235 | #else //!FEATURE_METADATA_PERF_STATS |
236 | |
237 | #define START_MD_PERF() |
238 | #define STOP_MD_PERF(MDTag) |
239 | |
240 | #endif //!FEATURE_METADATA_PERF_STATS |
241 | |
242 | #endif // __MDCOMPILERPERF_H__ |
243 | |