-
Notifications
You must be signed in to change notification settings - Fork 2
/
profiler.cpp
535 lines (444 loc) · 13.6 KB
/
profiler.cpp
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#include "profiler.h"
#include "log.h"
Profiler::Profiler()
: m_referenceCount(1)
{
}
Profiler::~Profiler()
{
}
HRESULT STDMETHODCALLTYPE Profiler::QueryInterface(REFIID riid, void **ppvObject)
{
if (riid == IID_ICorProfilerCallback3 ||
riid == IID_ICorProfilerCallback2 ||
riid == IID_ICorProfilerCallback ||
riid == IID_IUnknown)
{
*ppvObject = this;
this->AddRef();
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE Profiler::AddRef(void)
{
return __sync_fetch_and_add(&m_referenceCount, 1) + 1;
}
ULONG STDMETHODCALLTYPE Profiler::Release(void)
{
LONG result = __sync_fetch_and_sub(&m_referenceCount, 1) - 1;
if (result == 0)
{
delete this;
}
return result;
}
HRESULT STDMETHODCALLTYPE Profiler::Initialize(IUnknown *pICorProfilerInfoUnk)
{
LogProfilerActivity("Initialize\n");
ICorProfilerInfo3 *info;
HRESULT hr = pICorProfilerInfoUnk->QueryInterface(IID_ICorProfilerInfo3, (void **) &info);
if (hr == S_OK && info != NULL)
{
info->SetEventMask(COR_PRF_MONITOR_JIT_COMPILATION | COR_PRF_MONITOR_ASSEMBLY_LOADS | COR_PRF_MONITOR_CLASS_LOADS);
info->Release();
info = NULL;
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::Shutdown(void)
{
LogProfilerActivity("Shutdown\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AppDomainCreationStarted(AppDomainID appDomainId)
{
LogProfilerActivity("AppDomainCreationStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AppDomainCreationFinished(AppDomainID appDomainId, HRESULT hrStatus)
{
LogProfilerActivity("AppDomainCreationFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AppDomainShutdownStarted(AppDomainID appDomainId)
{
LogProfilerActivity("AppDomainShutdownStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AppDomainShutdownFinished(AppDomainID appDomainId, HRESULT hrStatus)
{
LogProfilerActivity("AppDomainShutdownFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AssemblyLoadStarted(AssemblyID assemblyId)
{
LogProfilerActivity("AssemblyLoadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AssemblyLoadFinished(AssemblyID assemblyId, HRESULT hrStatus)
{
LogProfilerActivity("AssemblyLoadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AssemblyUnloadStarted(AssemblyID assemblyId)
{
LogProfilerActivity("AssemblyUnloadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::AssemblyUnloadFinished(AssemblyID assemblyId, HRESULT hrStatus)
{
LogProfilerActivity("AssemblyUnloadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ModuleLoadStarted(ModuleID moduleId)
{
LogProfilerActivity("ModuleLoadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ModuleLoadFinished(ModuleID moduleId, HRESULT hrStatus)
{
LogProfilerActivity("ModuleLoadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ModuleUnloadStarted(ModuleID moduleId)
{
LogProfilerActivity("ModuleUnloadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ModuleUnloadFinished(ModuleID moduleId, HRESULT hrStatus)
{
LogProfilerActivity("ModuleUnloadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ModuleAttachedToAssembly(ModuleID moduleId, AssemblyID AssemblyId)
{
LogProfilerActivity("ModuleAttachedToAssembly\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ClassLoadStarted(ClassID classId)
{
LogProfilerActivity("ClassLoadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ClassLoadFinished(ClassID classId, HRESULT hrStatus)
{
LogProfilerActivity("ClassLoadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ClassUnloadStarted(ClassID classId)
{
LogProfilerActivity("ClassUnloadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ClassUnloadFinished(ClassID classId, HRESULT hrStatus)
{
LogProfilerActivity("ClassUnloadFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::FunctionUnloadStarted(FunctionID functionId)
{
LogProfilerActivity("FunctionUnloadStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITCompilationStarted(FunctionID functionId, BOOL fIsSafeToBlock)
{
LogProfilerActivity("JITCompilationStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITCompilationFinished(FunctionID functionId, HRESULT hrStatus, BOOL fIsSafeToBlock)
{
LogProfilerActivity("JITCompilationFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITCachedFunctionSearchStarted(FunctionID functionId, BOOL *pbUseCachedFunction)
{
LogProfilerActivity("JITCachedFunctionSearchStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITCachedFunctionSearchFinished(FunctionID functionId, COR_PRF_JIT_CACHE result)
{
LogProfilerActivity("JITCachedFunctionSearchFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITFunctionPitched(FunctionID functionId)
{
LogProfilerActivity("JITFunctionPitched\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::JITInlining(FunctionID callerId, FunctionID calleeId, BOOL *pfShouldInline)
{
LogProfilerActivity("JITInlining\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ThreadCreated(ThreadID threadId)
{
LogProfilerActivity("ThreadCreated\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ThreadDestroyed(ThreadID threadId)
{
LogProfilerActivity("ThreadDestroyed\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ThreadAssignedToOSThread(ThreadID managedThreadId, DWORD osThreadId)
{
LogProfilerActivity("ThreadAssignedToOSThread\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingClientInvocationStarted(void)
{
LogProfilerActivity("RemotingClientInvocationStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingClientSendingMessage(GUID *pCookie, BOOL fIsAsync)
{
LogProfilerActivity("RemotingClientSendingMessage\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingClientReceivingReply(GUID *pCookie, BOOL fIsAsync)
{
LogProfilerActivity("RemotingClientReceivingReply\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingClientInvocationFinished(void)
{
LogProfilerActivity("RemotingClientInvocationFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingServerReceivingMessage(GUID *pCookie, BOOL fIsAsync)
{
LogProfilerActivity("RemotingServerReceivingMessage\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingServerInvocationStarted(void)
{
LogProfilerActivity("RemotingServerInvocationStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingServerInvocationReturned(void)
{
LogProfilerActivity("RemotingServerInvocationReturned\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RemotingServerSendingReply(GUID *pCookie, BOOL fIsAsync)
{
LogProfilerActivity("RemotingServerSendingReply\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::UnmanagedToManagedTransition(FunctionID functionId, COR_PRF_TRANSITION_REASON reason)
{
LogProfilerActivity("UnmanagedToManagedTransition\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ManagedToUnmanagedTransition(FunctionID functionId, COR_PRF_TRANSITION_REASON reason)
{
LogProfilerActivity("ManagedToUnmanagedTransition\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeSuspendStarted(COR_PRF_SUSPEND_REASON suspendReason)
{
LogProfilerActivity("RuntimeSuspendStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeSuspendFinished(void)
{
LogProfilerActivity("RuntimeSuspendFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeSuspendAborted(void)
{
LogProfilerActivity("RuntimeSuspendAborted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeResumeStarted(void)
{
LogProfilerActivity("RuntimeResumeStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeResumeFinished(void)
{
LogProfilerActivity("RuntimeResumeFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeThreadSuspended(ThreadID threadId)
{
LogProfilerActivity("RuntimeThreadSuspended\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RuntimeThreadResumed(ThreadID threadId)
{
LogProfilerActivity("RuntimeThreadResumed\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::MovedReferences(ULONG cMovedObjectIDRanges, ObjectID oldObjectIDRangeStart[], ObjectID newObjectIDRangeStart[], ULONG cObjectIDRangeLength[])
{
LogProfilerActivity("MovedReferences\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ObjectAllocated(ObjectID objectId, ClassID classId)
{
LogProfilerActivity("ObjectAllocated\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ObjectsAllocatedByClass(ULONG cClassCount, ClassID classIds[], ULONG cObjects[])
{
LogProfilerActivity("ObjectsAllocatedByClass\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ObjectReferences(ObjectID objectId, ClassID classId, ULONG cObjectRefs, ObjectID objectRefIds[])
{
LogProfilerActivity("ObjectReferences\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RootReferences(ULONG cRootRefs, ObjectID rootRefIds[])
{
LogProfilerActivity("RootReferences\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionThrown(ObjectID thrownObjectId)
{
LogProfilerActivity("ExceptionThrown\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionSearchFunctionEnter(FunctionID functionId)
{
LogProfilerActivity("ExceptionSearchFunctionEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionSearchFunctionLeave(void)
{
LogProfilerActivity("ExceptionSearchFunctionLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionSearchFilterEnter(FunctionID functionId)
{
LogProfilerActivity("ExceptionSearchFilterEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionSearchFilterLeave(void)
{
LogProfilerActivity("ExceptionSearchFilterLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionSearchCatcherFound(FunctionID functionId)
{
LogProfilerActivity("ExceptionSearchCatcherFound\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionOSHandlerEnter(UINT_PTR __unused)
{
LogProfilerActivity("ExceptionOSHandlerEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionOSHandlerLeave(UINT_PTR __unused)
{
LogProfilerActivity("ExceptionOSHandlerLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionUnwindFunctionEnter(FunctionID functionId)
{
LogProfilerActivity("ExceptionUnwindFunctionEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionUnwindFunctionLeave(void)
{
LogProfilerActivity("ExceptionUnwindFunctionLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionUnwindFinallyEnter(FunctionID functionId)
{
LogProfilerActivity("ExceptionUnwindFinallyEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionUnwindFinallyLeave(void)
{
LogProfilerActivity("ExceptionUnwindFinallyLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionCatcherEnter(FunctionID functionId, ObjectID objectId)
{
LogProfilerActivity("ExceptionCatcherEnter\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionCatcherLeave(void)
{
LogProfilerActivity("ExceptionCatcherLeave\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::COMClassicVTableCreated(ClassID wrappedClassId, REFGUID implementedIID, void *pVTable, ULONG cSlots)
{
LogProfilerActivity("COMClassicVTableCreated\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::COMClassicVTableDestroyed(ClassID wrappedClassId, REFGUID implementedIID, void *pVTable)
{
LogProfilerActivity("COMClassicVTableDestroyed\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionCLRCatcherFound(void)
{
LogProfilerActivity("ExceptionCLRCatcherFound\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ExceptionCLRCatcherExecute(void)
{
LogProfilerActivity("ExceptionCLRCatcherExecute\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ThreadNameChanged(ThreadID threadId, ULONG cchName, _In_reads_opt_(cchName) WCHAR name[])
{
LogProfilerActivity("ThreadNameChanged\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::GarbageCollectionStarted(int cGenerations, BOOL generationCollected[], COR_PRF_GC_REASON reason)
{
LogProfilerActivity("GarbageCollectionStarted\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::SurvivingReferences(ULONG cSurvivingObjectIDRanges, ObjectID objectIDRangeStart[], ULONG cObjectIDRangeLength[])
{
LogProfilerActivity("SurvivingReferences\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::GarbageCollectionFinished(void)
{
LogProfilerActivity("GarbageCollectionFinished\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::FinalizeableObjectQueued(DWORD finalizerFlags, ObjectID objectID)
{
LogProfilerActivity("FinalizeableObjectQueued\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::RootReferences2(ULONG cRootRefs, ObjectID rootRefIds[], COR_PRF_GC_ROOT_KIND rootKinds[], COR_PRF_GC_ROOT_FLAGS rootFlags[], UINT_PTR rootIds[])
{
LogProfilerActivity("RootReferences2\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::HandleCreated(GCHandleID handleId, ObjectID initialObjectId)
{
LogProfilerActivity("HandleCreated\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::HandleDestroyed(GCHandleID handleId)
{
LogProfilerActivity("HandleDestroyed\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::InitializeForAttach(IUnknown *pCorProfilerInfoUnk, void *pvClientData, UINT cbClientData)
{
LogProfilerActivity("InitializeForAttach\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ProfilerAttachComplete(void)
{
LogProfilerActivity("ProfilerAttachComplete\n");
return S_OK;
}
HRESULT STDMETHODCALLTYPE Profiler::ProfilerDetachSucceeded(void)
{
LogProfilerActivity("ProfilerDetachSucceeded\n");
return S_OK;
}