Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rheventtrace.h « Runtime « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c1dd5be41d1edcddb9bc6939eef178a8c0182b3 (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
// 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.

//
// This header provides Redhawk-specific ETW code and macros, to allow sharing of common
// ETW code between Redhawk and desktop CLR.
//
#ifndef __RHEVENTTRACE_INCLUDED
#define __RHEVENTTRACE_INCLUDED


#ifdef FEATURE_ETW

// FireEtwGCPerHeapHistorySpecial() has to be defined manually rather than via the manifest because it does
// not have a standard signature.
#define FireEtwGCPerHeapHistorySpecial(DataPerHeap, DataSize, ClrId) (MICROSOFT_WINDOWS_REDHAWK_GC_PRIVATE_PROVIDER_Context.IsEnabled && PalEventEnabled(Microsoft_Windows_Redhawk_GC_PrivateHandle, &GCPerHeapHistory)) ? Template_GCPerHeapHistorySpecial(Microsoft_Windows_Redhawk_GC_PrivateHandle, &GCPerHeapHistory, DataPerHeap, DataSize, ClrId) : 0

// Map the CLR private provider to our version so we can avoid inserting more #ifdef's in the code.
#define MICROSOFT_WINDOWS_DOTNETRUNTIME_PRIVATE_PROVIDER_Context MICROSOFT_WINDOWS_REDHAWK_GC_PRIVATE_PROVIDER_Context
#define MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context MICROSOFT_WINDOWS_REDHAWK_GC_PUBLIC_PROVIDER_Context
#define Microsoft_Windows_DotNETRuntimeHandle Microsoft_Windows_Redhawk_GC_PublicHandle

#define CLR_GC_KEYWORD 0x1
#define CLR_FUSION_KEYWORD 0x4
#define CLR_LOADER_KEYWORD 0x8
#define CLR_JIT_KEYWORD 0x10
#define CLR_NGEN_KEYWORD 0x20
#define CLR_STARTENUMERATION_KEYWORD 0x40
#define CLR_ENDENUMERATION_KEYWORD 0x80
#define CLR_SECURITY_KEYWORD 0x400
#define CLR_APPDOMAINRESOURCEMANAGEMENT_KEYWORD 0x800
#define CLR_JITTRACING_KEYWORD 0x1000
#define CLR_INTEROP_KEYWORD 0x2000
#define CLR_CONTENTION_KEYWORD 0x4000
#define CLR_EXCEPTION_KEYWORD 0x8000
#define CLR_THREADING_KEYWORD 0x10000
#define CLR_JITTEDMETHODILTONATIVEMAP_KEYWORD 0x20000
#define CLR_OVERRIDEANDSUPPRESSNGENEVENTS_KEYWORD 0x40000
#define CLR_TYPE_KEYWORD 0x80000
#define CLR_GCHEAPDUMP_KEYWORD 0x100000
#define CLR_GCHEAPALLOC_KEYWORD 0x200000
#define CLR_GCHEAPSURVIVALANDMOVEMENT_KEYWORD 0x400000
#define CLR_GCHEAPCOLLECT_KEYWORD 0x800000
#define CLR_GCHEAPANDTYPENAMES_KEYWORD 0x1000000
#define CLR_PERFTRACK_KEYWORD 0x20000000
#define CLR_STACK_KEYWORD 0x40000000
#ifndef ERROR_SUCCESS
#define ERROR_SUCCESS   0
#endif

#undef ETW_TRACING_INITIALIZED
#define ETW_TRACING_INITIALIZED(RegHandle) (RegHandle != NULL)

#undef ETW_CATEGORY_ENABLED
#define ETW_CATEGORY_ENABLED(Context, LevelParam, Keyword) \
    (Context.IsEnabled &&                                                               \
    (                                                                                   \
        (LevelParam <= ((Context).Level)) ||                                                    \
        ((Context.Level) == 0)                                                           \
    ) &&                                                                                \
    (   \
        (Keyword == (ULONGLONG)0) ||    \
        (   \
            (Keyword & (Context.MatchAnyKeyword)) && \
            (   \
                (Keyword & (Context.MatchAllKeyword)) == (Context.MatchAllKeyword)    \
            )   \
        )   \
    )   \
    )

class EEType;
class Module;
class BulkTypeEventLogger;

namespace ETW
{
    // Class to wrap all type system logic for ETW
    class TypeSystemLog
    {
    public:
        // This enum is unused on Redhawk, but remains here to keep Redhawk / desktop CLR
        // code shareable.
        enum TypeLogBehavior
        {
            kTypeLogBehaviorTakeLockAndLogIfFirstTime,
            kTypeLogBehaviorAssumeLockAndLogIfFirstTime,
            kTypeLogBehaviorAlwaysLog,
        };

        static void LogTypeAndParametersIfNecessary(BulkTypeEventLogger * pLogger, UInt64 thAsAddr, TypeLogBehavior typeLogBehavior);
    };

    class LoaderLog
    {
    public:
        static void SendModuleEvent(Module *pModule);
    };
};

struct EventRCWEntry
{
    UInt64 ObjectID;
    UInt64 TypeID;
    UInt64 IUnk;
    UInt64 VTable;
    UInt32 RefCount;
    UInt32 Flags;
};

#pragma pack(push, 1)
struct EventCCWEntry
{
    UInt64 RootID;
    UInt64 ObjectID;
    UInt64 TypeID;
    UInt64 IUnk;
    UInt32 RefCount;
    UInt32 JupiterRefCount;
    UInt32 Flags;
};

C_ASSERT(sizeof(EventCCWEntry) == 44);
#pragma pack(pop)

const UInt32 cbComMaxEtwEvent = 64 * 1024;

// Does all logging for RCWs and CCWs in the process.
class BulkComLogger
{
public:
    // Returns true is gc heap collection is on.
    static bool ShouldReportComForGCHeapEtw(); 

    // Write one CCW to the CCW buffer.
    static void WriteCCW(void* CCWGCHandle, void* objectID, void* typeRawValue, void* IUnknown, long comRefCount, long jupiterRefCount, long flags);

    // Write one RCW to the RCW buffer.
    static void WriteRCW(void* objectID, void* typeRawValue, void* IUnknown, void* VTable, long refCount, long flags);

    // Gets or creates a unique BulkComLogger instance 
    static BulkComLogger* GetInstance();
    
    // Write the remaining events and deletes the static instance.
    static void FlushComETW();

private:
    BulkComLogger();
    ~BulkComLogger();

    // Forces a flush of all ETW events not yet fired.
    void FireBulkComEvent();

    // Writes one RCW to the RCW buffer.  May or may not fire the event.
    void WriteRcw(const EventRCWEntry& rcw);

    // Writes one CCW to the CCW buffer.  May or may not fire the event.
    void WriteCcw(const EventCCWEntry& ccw);

    // Forces a flush of all RCW ETW events not yet fired.
    void FlushRcw();

    // Forces a flush of all CCW ETW events not yet fired.
    void FlushCcw();

    // Distroys the unique instance and forces a flush for all ETW events not yet fired.
    void Cleanup();

private:
    // The maximum number of RCW/CCW events we can batch up based on the max size of an ETW event.
    static const int kMaxRcwCount = (cbComMaxEtwEvent - 0x30) / sizeof(EventRCWEntry);
    static const int kMaxCcwCount = (cbComMaxEtwEvent - 0x30) / sizeof(EventCCWEntry);

    int m_currRcw;  // The current number of batched (but not emitted) RCW events.
    int m_currCcw;  // The current number of batched (but not emitted) CCW events.

    BulkTypeEventLogger *m_typeLogger;  // Type logger to emit type data for.

    EventRCWEntry *m_etwRcwData;  // RCW buffer.
    EventCCWEntry *m_etwCcwData;  // CCW buffer.

    static BulkComLogger* s_comLogger;
};

#else
#define FireEtwGCPerHeapHistorySpecial(DataPerHeap, DataSize, ClrId)
#endif

#endif //__RHEVENTTRACE_INCLUDED