This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
/
InteropEventProvider.cs
679 lines (632 loc) · 31.6 KB
/
InteropEventProvider.cs
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
// 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.
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
// InteropEventProvider.cs
//
//
// Managed event source for FXCore.
// This will produce an XML file, where each event is pretty-printed with all its arguments nicely parsed.
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System;
using System.Security;
using System.Diagnostics.Tracing;
namespace System.Runtime.InteropServices
{
//#define ENABLE_WINRT
/// <summary>Provides an event source for tracing Interop information.</summary>
#if ENABLE_WINRT
[EventSource(Guid = "C4AC552A-E1EB-4FA2-A651-B200EFD7AA91", Name = "System.Runtime.InteropServices.InteropEventProvider")]
#endif // ENABLE_WINRT
internal sealed class InteropEventProvider
#if ENABLE_WINRT
: EventSource
#endif // ENABLE_WINRT
{
// Defines the singleton instance for the Interop Event ETW provider
public static readonly InteropEventProvider Log = new InteropEventProvider();
#if ENABLE_WINRT
internal new static bool IsEnabled()
{
// The InteropEventProvider class constructor should create an instance of InteropEventProvider and assign
// it to the Log field so Log should never be null here. However the EventSource performs some P/Invoke
// interop and creating a System.Type object which happens while running the EventSource ctor can perform
// WinRT interop so it is possible that we end up calling IsEnabled before the InteropEventProvider class
// constructor has completed so we must check that Log is not null.
return Log != null && ((EventSource)Log).IsEnabled();
}
#else
internal static bool IsEnabled()
{
return false;
}
private static bool IsEnabled(EventLevel level, EventKeywords keywords)
{
return false;
}
private struct EventData
{
public IntPtr DataPointer { get; set; }
public int Size { get; set; }
}
private unsafe void WriteEventCore(int eventId, int eventDataCount, EventData* data) { }
#endif // ENABLE_WINRT
// The InteropEventSource GUID is {C4AC552A-E1EB-4FA2-A651-B200EFD7AA91}
private InteropEventProvider() { }
/// <summary>Keyword definitions.</summary>
public static class Keywords
{
/// <summary>Interop keyword enable or disable the whole interop log events.</summary>
public const EventKeywords Interop = (EventKeywords)0x0001; // This is bit 0.
}
//-----------------------------------------------------------------------------------
//
// Interop Event IDs (must be unique)
//
#region RCWProvider
#region TaskID
/// <summary>A new RCW was created. Details at TaskRCWCreation.</summary>
private const int TASKRCWCREATION_ID = 10;
/// <summary>A RCW was finalized. Details at TaskRCWFinalization.</summary>
private const int TASKRCWFINALIZATION_ID = 11;
/// <summary>The RCW reference counter was incremented. Details at TaskRCWRefCountInc.</summary>
private const int TASKRCWREFCOUNTINC_ID = 12;
/// <summary>The RCW reference counter was decremented. Details at TaskRCWRefCountDec.</summary>
private const int TASKRCWREFCOUNTDEC_ID = 13;
/// <summary>The query interface failure. Details at TaskRCWQueryInterfaceFailure.</summary>
private const int TASKRCWQUERYINTERFACEFAILURE_ID = 14;
/// <summary>The query interface. Details at TaskRCWQueryInterface.</summary>
private const int TASKRCWQUERYINTERFACE_ID = 15;
#endregion TaskID
#region TaskRCWCreation
/// <summary>
/// Fired when a new RCW was created.
/// </summary>
/// <scenarios>
/// - Pair with RCW finalization to understand RCW lifetime and analyze leaks
/// - Reference with other RCW events to understand basic properties of RCW (without using tool to inspect RCWs at runtime)
/// - Understanding why weakly typed RCW are created or strongly-typed RCW are created
/// </scenarios>
/// <param name="comObject">Base address that unique identify the RCW.</param>
/// <param name="typeRawValue">RCW type identification.</param>
/// <param name="runtimeClassName">RCW runtime class name.</param>
/// <param name="context">RCW context.</param>
/// <param name="flags">RCW control flags.</param>
[Event(TASKRCWCREATION_ID, Message = "New RCW created", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWCreation(long objectID, long typeRawValue, string runtimeClassName, long context, long flags)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[5];
int runtimeClassNameLength = (runtimeClassName.Length + 1) * 2;
fixed (char* StringAux = runtimeClassName)
{
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&typeRawValue));
eventPayload[2].Size = runtimeClassNameLength;
eventPayload[2].DataPointer = ((IntPtr)(StringAux));
eventPayload[3].Size = sizeof(long);
eventPayload[3].DataPointer = ((IntPtr)(&context));
eventPayload[4].Size = sizeof(long);
eventPayload[4].DataPointer = ((IntPtr)(&flags));
WriteEventCore(TASKRCWCREATION_ID, 5, eventPayload);
}
}
}
}
#endregion TaskRCWCreation
#region TaskRCWRefCountInc
/// <summary>
/// Fired when a reference counter is incremented in RCW.
/// </summary>
/// <scenarios>
/// - Diagnosing Marshal.ReleaseCOmObject/FInalReleaseComObject errors
/// </scenarios>
/// <param name="objectID">Base address that unique identify the RCW.</param>
/// <param name="refCount">New reference counter value.</param>
[Event(TASKRCWREFCOUNTINC_ID, Message = "RCW refCount incremented", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWRefCountInc(long objectID, int refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(int);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKRCWREFCOUNTINC_ID, 2, eventPayload);
}
}
}
#endregion TaskRCWRefCountInc
#region TaskRCWRefCountDec
/// <summary>
/// Fired when a reference counter is decremented in RCW.
/// </summary>
/// <scenarios>
/// - Diagnosing Marshal.ReleaseCOmObject/FInalReleaseComObject errors
/// </scenarios>
/// <param name="objectID">Base address that unique identify the RCW.</param>
/// <param name="refCount">New reference counter value.</param>
[Event(TASKRCWREFCOUNTDEC_ID, Message = "RCW refCount decremented", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWRefCountDec(long objectID, int refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(int);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKRCWREFCOUNTDEC_ID, 2, eventPayload);
}
}
}
#endregion TaskRCWRefCountDec
#region TaskRCWFinalization
/// <summary>
/// Fired when a new RCW was finalized.
/// </summary>
/// <scenarios>
/// - Pair with RCW finalization to understand RCW lifetime and analyze leaks
/// - See if certain COM objects are finalized or not
/// </scenarios>
/// <param name="objectID">Base address that unique identify the RCW.</param>
/// <param name="refCount">RCW reference counter.</param>
[Event(TASKRCWFINALIZATION_ID, Message = "RCW Finalized", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWFinalization(long objectID, int refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(int);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKRCWFINALIZATION_ID, 2, eventPayload);
}
}
}
#endregion TaskRCWFinalization
#region TaskRCWQueryInterfaceFailure
/// <summary>
/// Fired when a RCW Interface address is queried and failure.
/// </summary>
/// <scenarios>
/// </scenarios>
/// <param name="objectID">Base address that unique identify the RCW.</param>
/// <param name="context">RCW context.</param>
/// <param name="interfaceIId">Queried interface IID.</param>
/// <param name="reason">Failure reason.</param>
/// <remarks>Not used</remarks>
[Event(TASKRCWQUERYINTERFACEFAILURE_ID, Message = "RCW Queried Interface Failure", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWQueryInterfaceFailure(long objectID, long context, Guid interfaceIId, int reason)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[4];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&context));
eventPayload[2].Size = sizeof(Guid);
eventPayload[2].DataPointer = ((IntPtr)(&interfaceIId));
eventPayload[3].Size = sizeof(int);
eventPayload[3].DataPointer = ((IntPtr)(&reason));
WriteEventCore(TASKRCWQUERYINTERFACEFAILURE_ID, 4, eventPayload);
}
}
}
#endregion TaskRCWQueryInterfaceFailure
#region TaskRCWQueryInterface
/// <summary>
/// Fired when a RCW Interface address is queried for the first time
/// </summary>
/// <scenarios>
/// </scenarios>
/// <param name="objectID">Base address that unique identify the RCW.</param>
/// <param name="context">RCW context.</param>
/// <param name="interfaceIId">Queried interface IID.</param>
/// <param name="typeRawValue">Raw value of the type.</param>
/// <remarks>Not used</remarks>
[Event(TASKRCWQUERYINTERFACE_ID, Message = "RCW Queried Interface for the first time", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskRCWQueryInterface(long objectID, long context, Guid interfaceIId, long typeRawValue)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[4];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&context));
eventPayload[2].Size = sizeof(Guid);
eventPayload[2].DataPointer = ((IntPtr)(&interfaceIId));
eventPayload[3].Size = sizeof(long);
eventPayload[3].DataPointer = ((IntPtr)(&typeRawValue));
WriteEventCore(TASKRCWQUERYINTERFACE_ID, 4, eventPayload);
}
}
}
#endregion TaskRCWQueryInterface
#endregion RCWProvider
#region CCWProvider
#region TaskID
/// <summary>A new CCW was created. Details at TaskCCWCreation. Details at TaskCCWCreation.</summary>
private const int TASKCCWCREATION_ID = 20;
/// <summary>A CCW was finalized. Details at TaskCCWFinalization. Details at TaskCCWFinalization.</summary>
private const int TASKCCWFINALIZATION_ID = 21;
/// <summary>The CCW reference counter was incremented. Details at TaskCCWRefCountInc.</summary>
private const int TASKCCWREFCOUNTINC_ID = 22;
/// <summary>The CCW reference counter was decremented. Details at TaskCCWRefCountDec.</summary>
private const int TASKCCWREFCOUNTDEC_ID = 23;
/// <summary>The Runtime class name was queried. Details at TaskCCWQueryRuntimeClassName.</summary>
private const int TASKCCWQUERYRUNTIMECLASSNAME_ID = 24;
/// <summary>An interface was queried whit error. Details at TaskCCWQueryInterfaceFailure.</summary>
private const int TASKCCWQUERYINTERFACEFAILURE_ID = 30;
/// <summary>An interface was queried for the first time. Details at TaskCCWQueryInterface.</summary>
private const int TASKCCWQUERYINTERFACE_ID = 31;
/// <summary>Resolve was queried with error. Details at TaskCCWResolveFailure.</summary>
private const int TASKCCWRESOLVEFAILURE_ID = 33;
#endregion TaskID
#region TaskCCWCreation
/// <summary>
/// Fired when a new CCW was created.
/// </summary>
/// <scenarios>
/// - Understand lifetime of CCWs
/// - Reference with other CCW events
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="targetObjectID">Base address that unique identify the target object in CCW.</param>
/// <param name="typeRawValue">Raw value for the type of the target Object.</param>
[Event(TASKCCWCREATION_ID, Message = "New CCW created", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWCreation(long objectID, long targetObjectID, long typeRawValue)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[3];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&targetObjectID));
eventPayload[2].Size = sizeof(long);
eventPayload[2].DataPointer = ((IntPtr)(&typeRawValue));
WriteEventCore(TASKCCWCREATION_ID, 3, eventPayload);
}
}
}
#endregion TaskCCWCreation
#region TaskCCWFinalization
/// <summary>
/// Fired when a new CCW was finalized.
/// </summary>
/// <scenarios>
/// - Understand lifetime of CCWs and help track addref/release problems.
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="refCount">The reference counter value at the ending time.</param>
[Event(TASKCCWFINALIZATION_ID, Message = "CCW Finalized", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWFinalization(long objectID, long refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKCCWFINALIZATION_ID, 2, eventPayload);
}
}
}
#endregion TaskCCWFinalization
#region TaskCCWRefCountInc
/// <summary>
/// Fired when a reference counter is incremented in CCW.
/// </summary>
/// <scenarios>
/// - Tracking addref/release problems
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="refCount">New reference counter value.</param>
[Event(TASKCCWREFCOUNTINC_ID, Message = "CCW refCount incremented", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWRefCountInc(long objectID, long refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKCCWREFCOUNTINC_ID, 2, eventPayload);
}
}
}
#endregion TaskCCWRefCountInc
#region TaskCCWRefCountDec
/// <summary>
/// Fired when a reference counter is decremented in CCW.
/// </summary>
/// <scenarios>
/// - Tracking addref/release problems
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="refCount">New reference counter value.</param>
[Event(TASKCCWREFCOUNTDEC_ID, Message = "CCW refCount decremented", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWRefCountDec(long objectID, long refCount)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&refCount));
WriteEventCore(TASKCCWREFCOUNTDEC_ID, 2, eventPayload);
}
}
}
#endregion TaskCCWRefCountDec
#region TaskCCWQueryRuntimeClassName
/// <summary>
/// Fired when a runtime class name was queried.
/// </summary>
/// <scenarios>
/// - Diagnosing bugs in JavaScript/.NET interaction, such as why JavaSCript refuse to call a function on a managed WinMD type
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="runtimeClassName">Required runtime class name.</param>
[Event(TASKCCWQUERYRUNTIMECLASSNAME_ID, Message = "CCW runtime class name required", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWQueryRuntimeClassName(long objectID, string runtimeClassName)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
int runtimeClassNameLength = (runtimeClassName.Length + 1) * 2;
fixed (char* StringAux = runtimeClassName)
{
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = runtimeClassNameLength;
eventPayload[1].DataPointer = ((IntPtr)(StringAux));
WriteEventCore(TASKCCWQUERYRUNTIMECLASSNAME_ID, 2, eventPayload);
}
}
}
}
#endregion TaskCCWQueryRuntimeClassName
#region TaskCCWQueryInterfaceFailure
/// <summary>
/// Fired when a CCW Interface address is queried and for any reason it was rejected.
/// </summary>
/// <scenarios>
/// - Diagnosing interop bugs where Qis are rejected for no apparent reason and causing Jupiter to fail in strange ways.
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="interfaceIId">Guid of the queried interface.</param>
[Event(TASKCCWQUERYINTERFACEFAILURE_ID, Message = "CCW queried interface failure", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWQueryInterfaceFailure(long objectID, Guid interfaceIId)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(Guid);
eventPayload[1].DataPointer = ((IntPtr)(&interfaceIId));
WriteEventCore(TASKCCWQUERYINTERFACEFAILURE_ID, 2, eventPayload);
}
}
}
#endregion TaskCCWQueryInterfaceFailure
#region TaskCCWQueryInterface
/// <summary>
/// Fired when a CCW Interface address is queried for the first time
/// </summary>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="typeRawValue">Raw value of the type.</param>
[Event(TASKCCWQUERYINTERFACE_ID, Message = "CCW first queried interface", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWQueryInterface(long objectID, long typeRawValue)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&typeRawValue));
WriteEventCore(TASKCCWQUERYINTERFACE_ID, 2, eventPayload);
}
}
}
#endregion TaskCCWQueryInterface
#region TaskCCWResolveFailure
/// <summary>
/// Fired when a CCW interface resolve is queried and for any reason it was rejected.
/// </summary>
/// <scenarios>
/// - Diagnosing interop bugs where Resolves are rejected for no apparent reason and causing to fail.
/// </scenarios>
/// <param name="objectID">Base address that unique identify the CCW.</param>
/// <param name="interfaceAddress">Address of the interface that must be resolved</param>
/// <param name="interfaceIId">Guid of the queried interface.</param>
/// <param name="rejectedReason">Rejected reason.</param>
[Event(TASKCCWRESOLVEFAILURE_ID, Message = "CCW resolve failure", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskCCWResolveFailure(long objectID, long interfaceAddress, Guid interfaceIId, int rejectedReason)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[4];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&objectID));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&interfaceAddress));
eventPayload[2].Size = sizeof(Guid);
eventPayload[2].DataPointer = ((IntPtr)(&interfaceIId));
eventPayload[3].Size = sizeof(int);
eventPayload[3].DataPointer = ((IntPtr)(&rejectedReason));
WriteEventCore(TASKCCWRESOLVEFAILURE_ID, 4, eventPayload);
}
}
}
#endregion TaskCCWResolveFailure
#endregion CCWProvider
#region JupiterProvider
#region TaskID
/// <summary>Jupter Garbage Collector was invoked via Callback. Details at TaskJupiterGarbageCollect.</summary>
private const int TASKJUPITERGARBAGECOLLECT_ID = 40;
/// <summary>Jupiter disconnect RCWs in current apartment. Details at TaskJupiterDisconnectRCWsInCurrentApartment.</summary>
private const int TASKJUPITERDISCONNECTERCWSINCURRENTAPARTMENT_ID = 41;
/// <summary>Jupiter add memory pressure callback. Details at TaskJupiterAddMemoryPressure.</summary>
private const int TASKJUPITERADDMEMORYPRESSURE_ID = 42;
/// <summary>Jupiter renove memory pressure callback. Details at TaskJupiterRemoveMemoryPressure.</summary>
private const int TASKJUPITERREMOVEMEMORYPRESSURE_ID = 43;
/// <summary>Jupiter create managed reference callback. Details at TaskJupiterCreateManagedReference.</summary>
private const int TASKJUPITERCREATEMANAGEDREFERENCE_ID = 44;
#endregion TaskID
#region TaskJupiterGarbageCollect
/// <summary>
/// Fired when Jupiter garbage collector callback is called.
/// </summary>
/// <scenarios>
/// - Monitoring the frequency of GarbageCollect is being triggered by Jupiter
/// </scenarios>
[Event(TASKJUPITERGARBAGECOLLECT_ID, Message = "Garbage Collect", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskJupiterGarbageCollect()
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
WriteEventCore(TASKJUPITERGARBAGECOLLECT_ID, 0, null);
}
}
}
#endregion TaskJupiterGarbageCollect
#region TaskJupiterDisconnectRCWsInCurrentApartment
/// <summary>
/// Fired when Jupiter disconnect RCWs in current apartment.
/// </summary>
/// <scenarios>
/// - Monitoring the frequency of wait for pending finalizer callback is being triggered by Jupiter
/// </scenarios>
[Event(TASKJUPITERDISCONNECTERCWSINCURRENTAPARTMENT_ID, Message = "Jupiter disconnect RCWs in current apartment", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskJupiterDisconnectRCWsInCurrentApartment()
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
WriteEventCore(TASKJUPITERDISCONNECTERCWSINCURRENTAPARTMENT_ID, 0, null);
}
}
}
#endregion TaskJupiterDisconnectRCWsInCurrentApartment
#region TaskJupiterAddMemoryPressure
/// <summary>
/// Fired when a Jupiter add memory pressure callback is called.
/// </summary>
/// <scenarios>
/// - Monitoring memory pressure added by Jupiter
/// </scenarios>
/// <param name="memorySize">Number of bytes in the added memory.</param>
[Event(TASKJUPITERADDMEMORYPRESSURE_ID, Message = "Jupiter add memory pressure", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskJupiterAddMemoryPressure(long memorySize)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[1];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&memorySize));
WriteEventCore(TASKJUPITERADDMEMORYPRESSURE_ID, 1, eventPayload);
}
}
}
#endregion TaskJupiterAddMemoryPressure
#region TaskJupiterRemoveMemoryPressure
/// <summary>
/// Fired when a Jupiter Remove memory pressure callback is called.
/// </summary>
/// <scenarios>
/// - Monitoring memory pressure Removeed by Jupiter
/// </scenarios>
/// <param name="memorySize">Number of bytes in the memory removed.</param>
[Event(TASKJUPITERREMOVEMEMORYPRESSURE_ID, Message = "Jupiter Remove memory pressure", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskJupiterRemoveMemoryPressure(long memorySize)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[1];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&memorySize));
WriteEventCore(TASKJUPITERREMOVEMEMORYPRESSURE_ID, 1, eventPayload);
}
}
}
#endregion TaskJupiterRemoveMemoryPressure
#region TaskJupiterCreateManagedReference
/// <summary>
/// Fired when a new managed reference is created in Jupiter.
/// </summary>
/// <scenarios>
/// - Monitoring the frequency of managed 'proxies' being created/used.
/// </scenarios>
/// <param name="IUnknown">Base address that unique identify the Jupiter.</param>
/// <param name="objectType">Jupiter type.</param>
[Event(TASKJUPITERCREATEMANAGEDREFERENCE_ID, Message = "Jupiter create managed reference", Level = EventLevel.Verbose, Keywords = Keywords.Interop)]
public void TaskJupiterCreateManagedReference(long IUnknown, long objectType)
{
if (IsEnabled(EventLevel.Verbose, Keywords.Interop))
{
unsafe
{
EventData* eventPayload = stackalloc EventData[2];
eventPayload[0].Size = sizeof(long);
eventPayload[0].DataPointer = ((IntPtr)(&IUnknown));
eventPayload[1].Size = sizeof(long);
eventPayload[1].DataPointer = ((IntPtr)(&objectType));
WriteEventCore(TASKJUPITERCREATEMANAGEDREFERENCE_ID, 2, eventPayload);
}
}
}
#endregion TaskJupiterCreateManagedReference
#endregion JupiterProvider
} //Class InteropEventProvider
}