Skip to content

Commit 0716913

Browse files
authored
Fix GC heap dump (#38893)
#36932 had a typo that caused types to never be logged
1 parent 919e683 commit 0716913

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

src/coreclr/src/vm/eventtrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3559,7 +3559,7 @@ BOOL ETW::TypeSystemLog::AddTypeToGlobalCacheIfNotExists(TypeHandle th, BOOL * p
35593559
{
35603560
CrstHolder _crst(GetHashCrst());
35613561
// Like above, check if the type has been added from a different thread since we last looked it up.
3562-
if (pLoggedTypesFromModule->loggedTypesFromModuleHash.Lookup(th).th.IsNull())
3562+
if (!pLoggedTypesFromModule->loggedTypesFromModuleHash.Lookup(th).th.IsNull())
35633563
{
35643564
*pfCreatedNew = FALSE;
35653565
return fSucceeded;

src/coreclr/tests/issues.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,9 @@
16251625
<ExcludeList Include="$(XunitTestBinBase)/tracing/tracevalidation/tracelogging/tracelogging/**">
16261626
<Issue>needs triage</Issue>
16271627
</ExcludeList>
1628+
<ExcludeList Include="$(XunitTestBinBase)/tracing/eventpipe/gcdump/gcdump/**">
1629+
<Issue>needs triage</Issue>
1630+
</ExcludeList>
16281631
<ExcludeList Include="$(XunitTestBinBase)/readytorun/coreroot_determinism/coreroot_determinism/**">
16291632
<Issue>needs triage</Issue>
16301633
</ExcludeList>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
using System;
6+
using System.Diagnostics.Tracing;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
using System.Collections.Generic;
12+
using Microsoft.Diagnostics.NETCore.Client;
13+
using Microsoft.Diagnostics.Tools.RuntimeClient;
14+
using Microsoft.Diagnostics.Tracing;
15+
using Microsoft.Diagnostics.Tracing.Parsers;
16+
using Tracing.Tests.Common;
17+
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
18+
19+
namespace Tracing.Tests.EventSourceError
20+
{
21+
// Regression test for https://github.com/dotnet/runtime/issues/38639
22+
public class GCDumpTest
23+
{
24+
private static int _bulkTypeCount = 0;
25+
private static int _bulkNodeCount = 0;
26+
private static int _bulkEdgeCount = 0;
27+
private static int _bulkRootEdgeCount = 0;
28+
private static int _bulkRootStaticVarCount = 0;
29+
30+
private static readonly ulong GC_HeapDump_Keyword = 0x100000UL;
31+
32+
public static int Main(string[] args)
33+
{
34+
// This test validates that if an EventSource generates an error
35+
// during construction it gets emitted over EventPipe
36+
37+
List<Provider> providers = new List<Provider>
38+
{
39+
new Provider("Microsoft-Windows-DotNETRuntime", eventLevel: EventLevel.Verbose, keywords: (ulong)ClrTraceEventParser.Keywords.GCHeapSnapshot)
40+
};
41+
42+
var configuration = new SessionConfiguration(circularBufferSizeMB: 1024, format: EventPipeSerializationFormat.NetTrace, providers: providers);
43+
return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, configuration, _DoesRundownContainMethodEvents);
44+
}
45+
46+
private static Dictionary<string, ExpectedEventCount> _expectedEventCounts = new Dictionary<string, ExpectedEventCount>()
47+
{
48+
// This space intentionally left blank
49+
};
50+
51+
private static Action _eventGeneratingAction = () =>
52+
{
53+
// This space intentionally left blank
54+
};
55+
56+
private static Func<EventPipeEventSource, Func<int>> _DoesRundownContainMethodEvents = (source) =>
57+
{
58+
source.Clr.TypeBulkType += (GCBulkTypeTraceData data) =>
59+
{
60+
_bulkTypeCount += data.Count;
61+
};
62+
63+
source.Clr.GCBulkNode += delegate (GCBulkNodeTraceData data)
64+
{
65+
_bulkNodeCount += data.Count;
66+
};
67+
68+
source.Clr.GCBulkEdge += (GCBulkEdgeTraceData data) =>
69+
{
70+
_bulkEdgeCount += data.Count;
71+
};
72+
73+
source.Clr.GCBulkRootEdge += (GCBulkRootEdgeTraceData data) =>
74+
{
75+
_bulkRootEdgeCount += data.Count;
76+
};
77+
78+
source.Clr.GCBulkRootStaticVar += (GCBulkRootStaticVarTraceData data) =>
79+
{
80+
_bulkRootStaticVarCount += data.Count;
81+
};
82+
83+
return () =>
84+
{
85+
// These values are ~80% (rounded to nice whole numbers) of the values
86+
// I saw when writing the test. The idea is that I want to catch
87+
// any real deviation in the number of types, but don't want to have
88+
// to maintain this test as the number of types varies. (And they will vary due to
89+
// framework code changes). If this test needs any sort of ongoing maintenance
90+
// just change all these values to a low number like 10 and move on.
91+
if (_bulkTypeCount > 125
92+
&& _bulkNodeCount > 600
93+
&& _bulkEdgeCount > 850
94+
&& _bulkRootEdgeCount > 250
95+
&& _bulkRootStaticVarCount > 70)
96+
{
97+
return 100;
98+
}
99+
100+
101+
Console.WriteLine($"Test failed due to missing GC heap events.");
102+
Console.WriteLine($"_bulkTypeCount = {_bulkTypeCount}");
103+
Console.WriteLine($"_bulkNodeCount = {_bulkNodeCount}");
104+
Console.WriteLine($"_bulkEdgeCount = {_bulkEdgeCount}");
105+
Console.WriteLine($"_bulkRootEdgeCount = {_bulkRootEdgeCount}");
106+
Console.WriteLine($"_bulkRootStaticVarCount = {_bulkRootStaticVarCount}");
107+
return -1;
108+
};
109+
};
110+
}
111+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
4+
<OutputType>exe</OutputType>
5+
<CLRTestKind>BuildAndRun</CLRTestKind>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
8+
<CLRTestPriority>0</CLRTestPriority>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="$(MSBuildProjectName).cs" />
12+
<ProjectReference Include="../common/common.csproj" />
13+
</ItemGroup>
14+
</Project>

0 commit comments

Comments
 (0)