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
93
94
95
96
97
98
99
100
101
102
103
104
|
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#include "simpletimer.h"
// Class to implement method context hive reading and iterating.
class MethodContextIterator
{
public:
MethodContextIterator(bool progressReport = false)
: m_hFile(INVALID_HANDLE_VALUE)
, m_fileSize(0)
, m_methodContextNumber(0)
, m_mc(nullptr)
, m_indexCount(-1)
, m_index(0)
, m_indexes(nullptr)
, m_progressReport(progressReport)
, m_timer(nullptr)
{
if (m_progressReport)
{
m_timer = new SimpleTimer();
}
}
MethodContextIterator(const int indexCount, const int* indexes, bool progressReport = false)
: m_hFile(INVALID_HANDLE_VALUE)
, m_fileSize(0)
, m_methodContextNumber(0)
, m_mc(nullptr)
, m_indexCount(indexCount)
, m_index(0)
, m_indexes(indexes)
, m_progressReport(progressReport)
, m_timer(nullptr)
{
if (m_progressReport)
{
m_timer = new SimpleTimer();
}
}
~MethodContextIterator()
{
Destroy();
}
bool Initialize(const char* fileName);
bool Destroy();
bool MoveNext();
// The iterator class owns the memory returned by Current(); the caller should not delete it.
MethodContext* Current()
{
return m_mc;
}
// In this case, we are giving ownership of the MethodContext* to the caller. So, null out m_mc
// before we return, so we don't attempt to delete it in this class.
MethodContext* CurrentTakeOwnership()
{
MethodContext* ret = m_mc;
m_mc = nullptr;
return ret;
}
// Return the file position offset of the current method context.
__int64 CurrentPos()
{
return m_pos.QuadPart;
}
int MethodContextNumber()
{
return m_methodContextNumber;
}
private:
HANDLE m_hFile;
int64_t m_fileSize;
int m_methodContextNumber;
MethodContext* m_mc;
LARGE_INTEGER m_pos;
// If m_indexCount==-1, use all method contexts. Otherwise, m_indexCount is the number of elements in the
// m_indexes array, which contains a sorted set of method context indexes to return. In this case, m_index
// is the index of the current element in m_indexes.
const int m_indexCount;
int m_index;
const int* m_indexes;
// Should we log a progress report as we are loading the method contexts?
// The timer is only used when m_progressReport==true.
bool m_progressReport;
SimpleTimer* m_timer;
};
|