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: HotHeapWriter.h
6//
7
8//
9// Class code:HotHeapWriter represents a writer of hot heap into MetaData hot stream (collected by IBC).
10//
11// ======================================================================================
12
13#pragma once
14
15#include "external.h"
16#include "heapindex.h"
17
18// Forward declarations
19class CorProfileData;
20struct IStream;
21
22namespace MetaData
23{
24
25// Forward declarations
26class StringHeapRW;
27class BlobHeapRW;
28class GuidHeapRW;
29
30// --------------------------------------------------------------------------------------
31//
32// This class represents a writer of hot heap into MetaData hot stream (collected by IBC).
33//
34class HotHeapWriter
35{
36private:
37 // Index of the represented heap (type of the heap).
38 HeapIndex m_HeapIndex;
39 union
40 {
41 const StringHeapRW *m_pStringHeap;
42 // Both #Blob and #US heaps are represented as code:BlobHeapRW.
43 const BlobHeapRW *m_pBlobHeap;
44 const GuidHeapRW *m_pGuidHeap;
45 };
46
47public:
48 // Creates writer for #String heap.
49 HotHeapWriter(const StringHeapRW *pStringHeap);
50 // Creates writer for #Blob or #US heap (if fUserStringHeap is TRUE).
51 HotHeapWriter(
52 const BlobHeapRW *pBlobHeap,
53 BOOL fUserStringHeap);
54 // Creates writer for #GUID heap.
55 HotHeapWriter(const GuidHeapRW *pGuidHeap);
56
57 // Destroys the writer of hot heap.
58 void Delete();
59
60 // Stores hot data reported by IBC in profile data (code:CorProfileData) to a stream.
61 // Aligns output stream to 4-bytes.
62 __checkReturn
63 HRESULT SaveToStream(
64 IStream *pStream,
65 CorProfileData *pProfileData,
66 UINT32 *pnSavedSize) const;
67
68 // Returns index of the heap as table index used by IBC (code:CorProfileData).
69 UINT32 GetTableIndex() const;
70
71private:
72 //
73 // Helpers
74 //
75
76 // Returns heap data at index (nIndex).
77 __checkReturn
78 HRESULT GetData(
79 UINT32 nIndex,
80 DataBlob *pData) const;
81
82}; // class HotHeapWriter
83
84}; // namespace MetaData
85