Skip to content

Commit 1e1a76b

Browse files
author
Mike Kaufman
committed
[MERGE chakra-core#5098 @mike-kaufman] Moving HeapBucketStats into its own file
Merge pull request chakra-core#5098 from mike-kaufman:build/mkaufman/refactor-HeapBucketStats For GC telemetry stats we need to take a dep on HeapBucketStats. It simplifies things if `HeapBucketStats` and `MemStats` are in their own header file. Moved these structs to `HeapBucketStats.h` and moved implementation methods into `HeapBucketStats.cpp`.
2 parents adbe6de + e2bf039 commit 1e1a76b

File tree

6 files changed

+146
-116
lines changed

6 files changed

+146
-116
lines changed

lib/Common/Memory/Chakra.Common.Memory.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<ClCompile Include="$(MSBuildThisFileDirectory)HeapInfoManager.cpp" />
9494
<ClCompile Include="$(MSBuildThisFileDirectory)RecyclerSweepManager.cpp" />
9595
<ClCompile Include="$(MSBuildThisFileDirectory)DelayDeletingFunctionTable.cpp" />
96+
<ClCompile Include="$(MSBuildThisFileDirectory)HeapBucketStats.cpp" />
9697
</ItemGroup>
9798
<ItemGroup>
9899
<ClInclude Include="AllocationPolicyManager.h" />
@@ -119,6 +120,7 @@
119120
<ClInclude Include="HeapBlock.h" />
120121
<ClInclude Include="HeapBlockMap.h" />
121122
<ClInclude Include="HeapBucket.h" />
123+
<ClInclude Include="HeapBucketStats.h" />
122124
<ClInclude Include="HeapConstants.h" />
123125
<ClInclude Include="HeapInfo.h" />
124126
<ClInclude Include="HeapInfoManager.h" />

lib/Common/Memory/Chakra.Common.Memory.vcxproj.filters

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<ClCompile Include="$(MSBuildThisFileDirectory)HeapInfoManager.cpp" />
5959
<ClCompile Include="$(MSBuildThisFileDirectory)RecyclerSweepManager.cpp" />
6060
<ClCompile Include="$(MSBuildThisFileDirectory)DelayDeletingFunctionTable.cpp" />
61+
<ClCompile Include="$(MSBuildThisFileDirectory)HeapBucketStats.cpp" />
6162
</ItemGroup>
6263
<ItemGroup>
6364
<ClInclude Include="Allocator.h" />
@@ -122,6 +123,7 @@
122123
<ClInclude Include="HeapInfoManager.h" />
123124
<ClInclude Include="BucketStatsReporter.h" />
124125
<ClInclude Include="RecyclerSweepManager.h" />
126+
<ClInclude Include="HeapBucketStats.h" />
125127
</ItemGroup>
126128
<ItemGroup>
127129
<None Include="HeapBlock.inl" />

lib/Common/Memory/HeapBlock.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7,92 +7,6 @@
77
#include <cxxabi.h>
88
#endif
99

10-
11-
#if ENABLE_MEM_STATS
12-
MemStats::MemStats()
13-
: objectByteCount(0), totalByteCount(0)
14-
{}
15-
16-
void MemStats::Reset()
17-
{
18-
objectByteCount = 0;
19-
totalByteCount = 0;
20-
}
21-
22-
size_t MemStats::FreeBytes() const
23-
{
24-
return totalByteCount - objectByteCount;
25-
}
26-
27-
double MemStats::UsedRatio() const
28-
{
29-
return (double)objectByteCount / totalByteCount;
30-
}
31-
32-
void MemStats::Aggregate(const MemStats& other)
33-
{
34-
objectByteCount += other.objectByteCount;
35-
totalByteCount += other.totalByteCount;
36-
}
37-
38-
#ifdef DUMP_FRAGMENTATION_STATS
39-
HeapBucketStats::HeapBucketStats()
40-
: totalBlockCount(0), objectCount(0), finalizeCount(0)
41-
{}
42-
43-
void HeapBucketStats::Reset()
44-
{
45-
MemStats::Reset();
46-
totalBlockCount = 0;
47-
objectCount = 0;
48-
finalizeCount = 0;
49-
}
50-
51-
void HeapBucketStats::Dump() const
52-
{
53-
Output::Print(_u("%5d %7d %7d %11lu %11lu %11lu %6.2f%%\n"),
54-
totalBlockCount, objectCount, finalizeCount,
55-
static_cast<ULONG>(objectByteCount),
56-
static_cast<ULONG>(FreeBytes()),
57-
static_cast<ULONG>(totalByteCount),
58-
UsedRatio() * 100);
59-
}
60-
#endif
61-
62-
void HeapBucketStats::PreAggregate()
63-
{
64-
// When first enter Pre-Aggregate state, clear data and mark state.
65-
if (!(totalByteCount & 1))
66-
{
67-
Reset();
68-
totalByteCount |= 1;
69-
}
70-
}
71-
72-
void HeapBucketStats::BeginAggregate()
73-
{
74-
// If was Pre-Aggregate state, keep data and clear state
75-
if (totalByteCount & 1)
76-
{
77-
totalByteCount &= ~1;
78-
}
79-
else
80-
{
81-
Reset();
82-
}
83-
}
84-
85-
void HeapBucketStats::Aggregate(const HeapBucketStats& other)
86-
{
87-
MemStats::Aggregate(other);
88-
#ifdef DUMP_FRAGMENTATION_STATS
89-
totalBlockCount += other.totalBlockCount;
90-
objectCount += other.objectCount;
91-
finalizeCount += other.finalizeCount;
92-
#endif
93-
}
94-
#endif // ENABLE_MEM_STATS
95-
9610
//========================================================================================================
9711
// HeapBlock
9812
//========================================================================================================

lib/Common/Memory/HeapBlock.h

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Copyright (C) Microsoft. All rights reserved.
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
5+
6+
#pragma once
7+
8+
#include "HeapBucketStats.h"
9+
510
class ScriptMemoryDumper;
611

712
namespace Memory
@@ -39,36 +44,6 @@ class RecyclerSweep;
3944
class MarkContext;
4045

4146
#if ENABLE_MEM_STATS
42-
struct MemStats
43-
{
44-
size_t objectByteCount;
45-
size_t totalByteCount;
46-
47-
MemStats();
48-
49-
void Reset();
50-
size_t FreeBytes() const;
51-
double UsedRatio() const;
52-
void Aggregate(const MemStats& other);
53-
};
54-
55-
struct HeapBucketStats: MemStats
56-
{
57-
#ifdef DUMP_FRAGMENTATION_STATS
58-
uint totalBlockCount;
59-
uint objectCount;
60-
uint finalizeCount;
61-
62-
HeapBucketStats();
63-
void Reset();
64-
void Dump() const;
65-
#endif
66-
67-
void PreAggregate();
68-
void BeginAggregate();
69-
void Aggregate(const HeapBucketStats& other);
70-
};
71-
7247
#ifdef DUMP_FRAGMENTATION_STATS
7348
#define DUMP_FRAGMENTATION_STATS_ONLY(x) x
7449
#define DUMP_FRAGMENTATION_STATS_IS(x) x

lib/Common/Memory/HeapBucketStats.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
#include "CommonMemoryPch.h"
6+
#ifdef __clang__
7+
#include <cxxabi.h>
8+
#endif
9+
10+
#if ENABLE_MEM_STATS
11+
MemStats::MemStats()
12+
: objectByteCount(0), totalByteCount(0)
13+
{}
14+
15+
void MemStats::Reset()
16+
{
17+
objectByteCount = 0;
18+
totalByteCount = 0;
19+
}
20+
21+
size_t MemStats::FreeBytes() const
22+
{
23+
return totalByteCount - objectByteCount;
24+
}
25+
26+
double MemStats::UsedRatio() const
27+
{
28+
return (double)objectByteCount / totalByteCount;
29+
}
30+
31+
void MemStats::Aggregate(const MemStats& other)
32+
{
33+
objectByteCount += other.objectByteCount;
34+
totalByteCount += other.totalByteCount;
35+
}
36+
37+
#ifdef DUMP_FRAGMENTATION_STATS
38+
HeapBucketStats::HeapBucketStats()
39+
: totalBlockCount(0), objectCount(0), finalizeCount(0)
40+
{}
41+
42+
void HeapBucketStats::Reset()
43+
{
44+
MemStats::Reset();
45+
totalBlockCount = 0;
46+
objectCount = 0;
47+
finalizeCount = 0;
48+
}
49+
50+
void HeapBucketStats::Dump() const
51+
{
52+
Output::Print(_u("%5d %7d %7d %11lu %11lu %11lu %6.2f%%\n"),
53+
totalBlockCount, objectCount, finalizeCount,
54+
static_cast<ULONG>(objectByteCount),
55+
static_cast<ULONG>(FreeBytes()),
56+
static_cast<ULONG>(totalByteCount),
57+
UsedRatio() * 100);
58+
}
59+
#endif
60+
61+
void HeapBucketStats::PreAggregate()
62+
{
63+
// When first enter Pre-Aggregate state, clear data and mark state.
64+
if (!(totalByteCount & 1))
65+
{
66+
Reset();
67+
totalByteCount |= 1;
68+
}
69+
}
70+
71+
void HeapBucketStats::BeginAggregate()
72+
{
73+
// If was Pre-Aggregate state, keep data and clear state
74+
if (totalByteCount & 1)
75+
{
76+
totalByteCount &= ~1;
77+
}
78+
else
79+
{
80+
Reset();
81+
}
82+
}
83+
84+
void HeapBucketStats::Aggregate(const HeapBucketStats& other)
85+
{
86+
MemStats::Aggregate(other);
87+
#ifdef DUMP_FRAGMENTATION_STATS
88+
totalBlockCount += other.totalBlockCount;
89+
objectCount += other.objectCount;
90+
finalizeCount += other.finalizeCount;
91+
#endif
92+
}
93+
#endif // ENABLE_MEM_STATS

lib/Common/Memory/HeapBucketStats.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
#pragma once
7+
8+
#include "CommonDefines.h"
9+
10+
namespace Memory
11+
{
12+
#if ENABLE_MEM_STATS
13+
struct MemStats
14+
{
15+
size_t objectByteCount;
16+
size_t totalByteCount;
17+
18+
MemStats();
19+
20+
void Reset();
21+
size_t FreeBytes() const;
22+
double UsedRatio() const;
23+
void Aggregate(const MemStats& other);
24+
};
25+
26+
struct HeapBucketStats : MemStats
27+
{
28+
#ifdef DUMP_FRAGMENTATION_STATS
29+
uint totalBlockCount;
30+
uint objectCount;
31+
uint finalizeCount;
32+
33+
HeapBucketStats();
34+
void Reset();
35+
void Dump() const;
36+
#endif
37+
38+
void PreAggregate();
39+
void BeginAggregate();
40+
void Aggregate(const HeapBucketStats& other);
41+
};
42+
#endif
43+
44+
}

0 commit comments

Comments
 (0)