summaryrefslogtreecommitdiff
path: root/src/md/compiler/mdperf.h
blob: 77def32d215a370adf83ee7c64a22119b679776c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//*****************************************************************************
// Mdperf.h 
// 

// 
//*****************************************************************************

#ifndef __MDCOMPILERPERF_H__
#define __MDCOMPILERPERF_H__

//#define FEATURE_METADATA_PERF_STATS

#ifdef FEATURE_METADATA_PERF_STATS

// Avoid dynamic allocs to display the API names.
#define API_NAME_STR_SIZE 80

//-----------------------------------------------------------------------------
// In order to add instrumentation for an API, two changes have to be made. 
// One, add the API name in the table below (MD_TABLE). 
// Second, add two lines of code (shown below) in the implementation 
// of the API itself. e.g.
//      RegMeta::MyNewMetataDataAPI(...)
//      {
//           LOG(...);
//           START_MD_PERF();        // <------ add this line as is.
//           .... 
//           // API implementation
//       ErrExit:
//           STOP_MD_PERF(RegMeta_MyNewMetaDataAPI); // <---------- add this line with the appropriate name
//           return (hr);
//      ]
//  
//-----------------------------------------------------------------------------
#define MD_COMPILER_PERF_TABLE\
    MD_FUNC(SaveToMemory)\
    MD_FUNC(DefineMethod)\
    MD_FUNC(DefineMethodImpl)\
    MD_FUNC(SetRVA)\
    MD_FUNC(DefineTypeRefByName)\
    MD_FUNC(DefineImportType)\
    MD_FUNC(DefineMemberRef)\
    MD_FUNC(DefineImportMember)\
    MD_FUNC(DefineEvent)\
    MD_FUNC(SetClassLayout)\
    MD_FUNC(DeleteClassLayout)\
    MD_FUNC(SetFieldMarshal)\
    MD_FUNC(DeleteFieldMarshal)\
    MD_FUNC(DefinePermissionSet)\
    MD_FUNC(SetMemberIndex)\
    MD_FUNC(GetTokenFromSig)\
    MD_FUNC(DefineModuleRef)\
    MD_FUNC(SetParent)\
    MD_FUNC(GetTokenFromTypeSpec)\
    MD_FUNC(DefineUserString)\
    MD_FUNC(DeleteToken)\
    MD_FUNC(SetTypeDefProps)\
    MD_FUNC(DefineNestedType)\
    MD_FUNC(SetMethodProps)\
    MD_FUNC(SetEventProps)\
    MD_FUNC(SetPermissionSetProps)\
    MD_FUNC(DefinePinvokeMap)\
    MD_FUNC(SetPinvokeMap)\
    MD_FUNC(DeletePinvokeMap)\
    MD_FUNC(DefineField)\
    MD_FUNC(DefineProperty)\
    MD_FUNC(DefineParam)\
    MD_FUNC(SetFieldProps)\
    MD_FUNC(SetPropertyProps)\
    MD_FUNC(SetParamProps)\
    MD_FUNC(EnumMembers)\
    MD_FUNC(EnumMembersWithName)\
    MD_FUNC(EnumMethods)\
    MD_FUNC(EnumMethodsWithName)\
    MD_FUNC(EnumFields)\
    MD_FUNC(EnumFieldsWithName)\
    MD_FUNC(EnumParams)\
    MD_FUNC(EnumMemberRefs)\
    MD_FUNC(EnumMethodImpls)\
    MD_FUNC(EnumPermissionSets)\
    MD_FUNC(FindMember)\
    MD_FUNC(FindMethod)\
    MD_FUNC(FindField)\
    MD_FUNC(FindMemberRef)\
    MD_FUNC(GetMethodProps)\
    MD_FUNC(GetMemberRefProps)\
    MD_FUNC(EnumProperties)\
    MD_FUNC(EnumEvents)\
    MD_FUNC(GetEventProps)\
    MD_FUNC(EnumMethodSemantics)\
    MD_FUNC(GetMethodSemantics)\
    MD_FUNC(GetClassLayout)\
    MD_FUNC(GetFieldMarshal)\
    MD_FUNC(GetRVA)\
    MD_FUNC(GetPermissionSetProps)\
    MD_FUNC(GetSigFromToken)\
    MD_FUNC(GetModuleRefProps)\
    MD_FUNC(EnumModuleRefs)\
    MD_FUNC(GetTypeSpecFromToken)\
    MD_FUNC(GetNameFromToken)\
    MD_FUNC(EnumUnresolvedMethods)\
    MD_FUNC(GetUserString)\
    MD_FUNC(GetPinvokeMap)\
    MD_FUNC(EnumSignatures)\
    MD_FUNC(EnumTypeSpecs)\
    MD_FUNC(EnumUserStrings)\
    MD_FUNC(GetParamForMethodIndex)\
    MD_FUNC(GetMemberProps)\
    MD_FUNC(GetFieldProps)\
    MD_FUNC(GetPropertyProps)\
    MD_FUNC(GetParamProps)\
    MD_FUNC(SetModuleProps)\
    MD_FUNC(Save)\
    MD_FUNC(SaveToStream)\
    MD_FUNC(GetSaveSize)\
    MD_FUNC(Merge)\
    MD_FUNC(DefineCustomAttribute)\
    MD_FUNC(SetCustomAttributeValue)\
    MD_FUNC(DefineSecurityAttributeSet)\
    MD_FUNC(UnmarkAll)\
    MD_FUNC(MarkToken)\
    MD_FUNC(IsTokenMarked)\
    MD_FUNC(DefineTypeDef)\
    MD_FUNC(SetHandler)\
    MD_FUNC(CountEnum)\
    MD_FUNC(ResetEnum)\
    MD_FUNC(EnumTypeDefs)\
    MD_FUNC(EnumInterfaceImpls)\
    MD_FUNC(EnumTypeRefs)\
    MD_FUNC(FindTypeDefByName)\
    MD_FUNC(FindTypeDefByGUID)\
    MD_FUNC(GetScopeProps)\
    MD_FUNC(GetModuleFromScope)\
    MD_FUNC(GetTypeDefProps)\
    MD_FUNC(GetInterfaceImplProps)\
    MD_FUNC(GetCustomAttributeByName)\
    MD_FUNC(GetTypeRefProps)\
    MD_FUNC(ResolveTypeRef)\
    MD_FUNC(EnumCustomAttributes)\
    MD_FUNC(GetCustomAttributeProps)\
    MD_FUNC(FindTypeRef)\
    MD_FUNC(RefToDefOptimization)\
    MD_FUNC(ProcessFilter)\
    MD_FUNC(DefineAssembly)\
    MD_FUNC(DefineAssemblyRef)\
    MD_FUNC(DefineFile)\
    MD_FUNC(DefineExportedType)\
    MD_FUNC(DefineManifestResource)\
    MD_FUNC(DefineExecutionLocation)\
    MD_FUNC(SetAssemblyProps)\
    MD_FUNC(SetAssemblyRefProps)\
    MD_FUNC(SetFileProps)\
    MD_FUNC(SetExportedTypeProps)\
    MD_FUNC(GetAssemblyProps)\
    MD_FUNC(GetAssemblyRefProps)\
    MD_FUNC(GetFileProps)\
    MD_FUNC(GetExportedTypeProps)\
    MD_FUNC(GetManifestResourceProps)\
    MD_FUNC(EnumAssemblyRefs)\
    MD_FUNC(EnumFiles)\
    MD_FUNC(EnumExportedTypes)\
    MD_FUNC(EnumManifestResources)\
    MD_FUNC(EnumExecutionLocations)\
    MD_FUNC(GetAssemblyFromScope)\
    MD_FUNC(FindExportedTypeByName)\
    MD_FUNC(FindManifestResourceByName)\
    MD_FUNC(FindAssembliesByName)\
    MD_FUNC(SetGenericPars)\
    MD_FUNC(DefineGenericParam)\
    MD_FUNC(SetGenericParamProps)\
    MD_FUNC(EnumGenericParamConstraints)\
    MD_FUNC(GetGenericParamProps)\
    MD_FUNC(GetGenericParamConstraintProps)\
    MD_FUNC(GetPEKind)\
    MD_FUNC(GetVersionString)\
    MD_FUNC(GetAssemblyUnification)

//-----------------------------------------------------------------------------
// Create an enum of all the API names. This is the index to access the APIs.
//-----------------------------------------------------------------------------
#undef MD_FUNC
#define MD_FUNC(MDTag)\
    MDTag ## _ENUM,

typedef enum _MDAPIs
{
    MD_COMPILER_PERF_TABLE
    LAST_MD_API
} MDApis;

//-----------------------------------------------------------------------------
// Declare the struct which contais all the interesting stats for a particular 
// API call.
//-----------------------------------------------------------------------------
typedef struct _MDAPIPerfData
{
    DWORD dwQueryPerfCycles;             // # of cycles spent in this call
    DWORD dwCalledNumTimes;              // # of times this API was called
} MDAPIPerfData;

    
//-----------------------------------------------------------------------------
// MDCompilerPerf
//-----------------------------------------------------------------------------
class MDCompilerPerf 
{
public:
    MDCompilerPerf();
    ~MDCompilerPerf();
    
private:
    MDAPIPerfData MDPerfStats[LAST_MD_API];
    
    void MetaDataPerfReport ();
};

// Note that this macro declares a local var. 
#define START_MD_PERF()\
    LARGE_INTEGER __startVal;\
    QueryPerformanceCounter(&__startVal); 

#undef MD_FUNC
#define MD_FUNC(MDTag)\
    MDTag ## _ENUM

// Note that this macro uses the local var startVal declared in START_MD_PERF()
#define STOP_MD_PERF(MDTag)\
    LARGE_INTEGER __stopVal;\
    QueryPerformanceCounter(&__stopVal);\
    m_MDCompilerPerf.MDPerfStats[MD_FUNC(MDTag)].dwCalledNumTimes++;\
    m_MDCompilerPerf.MDPerfStats[MD_FUNC(MDTag)].dwQueryPerfCycles += (DWORD)(__stopVal.QuadPart - __startVal.QuadPart);
    
#else //!FEATURE_METADATA_PERF_STATS

#define START_MD_PERF()
#define STOP_MD_PERF(MDTag)

#endif //!FEATURE_METADATA_PERF_STATS

#endif // __MDCOMPILERPERF_H__