summaryrefslogtreecommitdiff
path: root/src/vm/perfmap.h
blob: 1f06bd4091f9ffc5c73aa6a23ec738a1606a0d57 (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
// 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.
// ===========================================================================
// File: perfmap.h
//
#ifndef PERFPID_H
#define PERFPID_H

#include "sstring.h"
#include "fstream.h"

class PerfInfo;

// Generates a perfmap file.
class PerfMap
{
private:
    // The one and only PerfMap for the process.
    static PerfMap * s_Current;

    // The file stream to write the map to.
    CFileStream * m_FileStream;

    // The perfinfo file to log images to.
    PerfInfo* m_PerfInfo;

    // Set to true if an error is encountered when writing to the file.
    bool m_ErrorEncountered;

    // Set to true if an error is encountered when writing to the file.
    unsigned m_StubsMapped;

    // Construct a new map for the specified pid.
    PerfMap(int pid);

    // Write a line to the map file.
    void WriteLine(SString & line);

protected:
    // Construct a new map without a specified file name.
    // Used for offline creation of NGEN map files.
    PerfMap();

    // Clean-up resources.
    ~PerfMap();

    // Open the perf map file for write.
    void OpenFile(SString& path);

    // Does the actual work to log a method to the map.
    void LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize);

    // Does the actual work to log an image
    void LogImage(PEFile * pFile);

    // Get the image signature and store it as a string.
    static void GetNativeImageSignature(PEFile * pFile, WCHAR * pwszSig, unsigned int nSigSize);

public:
    // Initialize the map for the current process.
    static void Initialize();

    // Log a native image load to the map.
    static void LogImageLoad(PEFile * pFile);

    // Log a JIT compiled method to the map.
    static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize);

    // Log a set of stub to the map.
    static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize);

    // Close the map and flush any remaining data.
    static void Destroy();
};

// Generates a perfmap file for a native image by running crossgen.
class NativeImagePerfMap : PerfMap
{
private:
    // Log a pre-compiled method to the map.
    void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, SIZE_T baseAddr);

public:
    // Construct a new map for a native image.
    NativeImagePerfMap(Assembly * pAssembly, BSTR pDestPath);

    // Log method information for each module.
    void LogDataForModule(Module * pModule);
};

#endif // PERFPID_H