summaryrefslogtreecommitdiff
path: root/src/vm/stacksampler.h
blob: c17dd3e804be31d61d6e16e4321c7fcf1eb0924c (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
// 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.

/*++

Module Name:

    StackSampler.h

--*/

#ifndef __STACK_SAMPLER_H
#define __STACK_SAMPLER_H
#endif

#ifdef FEATURE_STACK_SAMPLING

class StackSampler
{
public:
    // Interface
    static void Init();
    static void RecordJittingInfo(MethodDesc* pMD, CORJIT_FLAGS flags);

private:

    // Methods
    StackSampler();
    ~StackSampler();

    static DWORD __stdcall SamplingThreadProc(void* arg);

    static StackWalkAction StackWalkCallback(CrawlFrame* pCf, VOID* data);
    
    StackWalkAction CrawlFrameVisitor(CrawlFrame* pCf, Thread* pMdThread);

    void ThreadProc();

    void JitFrequentMethodsInSamples();

    void JitAndCollectTrace(MethodDesc* pMD);

    void RecordJittingInfoInternal(MethodDesc* pMD, CORJIT_FLAGS flags);


    // Constants
    static const int s_knDefaultSamplingIntervalMsec = 100;
    static const int s_knDefaultNumMethods = 32;
    static const int s_knDefaultCountForImportance = 0;    // TODO: Set to some reasonable value.

    // Typedefs
    struct CountInfo;
    typedef MapSHash<MethodDesc*, CountInfo> CountInfoHash;
    typedef CountInfoHash::element_t CountInfoHashEntry;

    typedef MapSHash<MethodDesc*, CORJIT_FLAGS> JitInfoHash;
    typedef JitInfoHash::element_t JitInfoHashEntry;

    // Nested types
    struct CountInfo
    {
        unsigned uCount;
        bool fJitted;
        CountInfo() : fJitted(false), uCount(0) {}
    };

    // Fields
    Crst m_crstJitInfo;
    CountInfoHash m_countInfo;
    JitInfoHash m_jitInfo;
    Thread* m_pThread;
    unsigned m_nSampleEvery;
    unsigned m_nSampleAfter;
    unsigned m_nNumMethods;
};
#endif // FEATURE_STACK_SAMPLING