1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4// ===========================================================================
5// File: perfmap.h
6//
7#ifndef PERFPID_H
8#define PERFPID_H
9
10#include "sstring.h"
11#include "fstream.h"
12
13class PerfInfo;
14
15// Generates a perfmap file.
16class PerfMap
17{
18private:
19 // The one and only PerfMap for the process.
20 static PerfMap * s_Current;
21
22 // The file stream to write the map to.
23 CFileStream * m_FileStream;
24
25 // The perfinfo file to log images to.
26 PerfInfo* m_PerfInfo;
27
28 // Set to true if an error is encountered when writing to the file.
29 bool m_ErrorEncountered;
30
31 // Set to true if an error is encountered when writing to the file.
32 unsigned m_StubsMapped;
33
34 // Construct a new map for the specified pid.
35 PerfMap(int pid);
36
37 // Write a line to the map file.
38 void WriteLine(SString & line);
39
40protected:
41 // Construct a new map without a specified file name.
42 // Used for offline creation of NGEN map files.
43 PerfMap();
44
45 // Clean-up resources.
46 ~PerfMap();
47
48 // Open the perf map file for write.
49 void OpenFile(SString& path);
50
51 // Does the actual work to log a method to the map.
52 void LogMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize);
53
54 // Does the actual work to log an image
55 void LogImage(PEFile * pFile);
56
57 // Get the image signature and store it as a string.
58 static void GetNativeImageSignature(PEFile * pFile, WCHAR * pwszSig, unsigned int nSigSize);
59
60public:
61 // Initialize the map for the current process.
62 static void Initialize();
63
64 // Log a native image load to the map.
65 static void LogImageLoad(PEFile * pFile);
66
67 // Log a JIT compiled method to the map.
68 static void LogJITCompiledMethod(MethodDesc * pMethod, PCODE pCode, size_t codeSize);
69
70 // Log a set of stub to the map.
71 static void LogStubs(const char* stubType, const char* stubOwner, PCODE pCode, size_t codeSize);
72
73 // Close the map and flush any remaining data.
74 static void Destroy();
75};
76
77// Generates a perfmap file for a native image by running crossgen.
78class NativeImagePerfMap : PerfMap
79{
80private:
81 // Log a pre-compiled method to the map.
82 void LogPreCompiledMethod(MethodDesc * pMethod, PCODE pCode, SIZE_T baseAddr);
83
84public:
85 // Construct a new map for a native image.
86 NativeImagePerfMap(Assembly * pAssembly, BSTR pDestPath);
87
88 // Log method information for each module.
89 void LogDataForModule(Module * pModule);
90};
91
92#endif // PERFPID_H
93