summaryrefslogtreecommitdiff
path: root/src/vm/sampleprofiler.h
blob: 02eb6b39cdaa9f37504567d3853a71eaf28ef0c5 (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
// 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.

#ifndef __SAMPLEPROFILER_H__
#define __SAMPLEPROFILER_H__

#ifdef FEATURE_PERFTRACING

#include "common.h"
#include "eventpipe.h"

enum class SampleProfilerSampleType
{
    Error = 0,
    External = 1,
    Managed = 2
};

class SampleProfiler
{

    // Declare friends.
    friend class EventPipe;
    friend class SampleProfilerEventInstance;

    public:

        // Enable profiling.
        static void Enable();

        // Disable profiling.
        static void Disable();

        // Set the sampling rate.
        static void SetSamplingRate(long nanoseconds);

    private:

        // Iterate through all managed threads and walk all stacks.
        static void WalkManagedThreads();

        // Profiling thread proc.  Invoked on a new thread when profiling is enabled.
        static DWORD WINAPI ThreadProc(void *args);

        // True when profiling is enabled.
        static Volatile<BOOL> s_profilingEnabled;

        // The sampling thread.
        static Thread *s_pSamplingThread;

        // The provider and event emitted by the profiler.
        static const GUID s_providerID;
        static EventPipeProvider *s_pEventPipeProvider;
        static EventPipeEvent *s_pThreadTimeEvent;

        // Event payloads.
        // External represents a sample in external or native code.
        // Managed represents a sample in managed code.
        static BYTE *s_pPayloadExternal;
        static BYTE *s_pPayloadManaged;
        static const unsigned int c_payloadSize = sizeof(unsigned int);

        // Thread shutdown event for synchronization between Disable() and the sampling thread.
        static CLREventStatic s_threadShutdownEvent;

        // The sampling rate.
        static long s_samplingRateInNs;
};

#endif // FEATURE_PERFTRACING

#endif // __SAMPLEPROFILER_H__