-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[UserEvents] Add end-to-end runtime test #121316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
47231e1
[UserEvents] Add end-to-end runtime test
mdh1418 963efe1
Merge remote-tracking branch 'upstream/main' into user_events_functio…
mdh1418 e712df6
Cleanup test props
mdh1418 2b246be
Add ProcessStartInfo and using keyword
mdh1418 a7afeb9
Fix process exit detection
mdh1418 c41916a
Retain nettrace test asset
mdh1418 963af3f
Address feedback
mdh1418 005cc94
Fix RecordTrace package resolving
mdh1418 5d09bd2
Alternative user_events_data access check
mdh1418 146b348
Fix record-trace startup
mdh1418 a8d5d97
Detect record-trace unexpected exit and flush output
mdh1418 f9531d2
Fix record-trace output
mdh1418 ffc0c16
Reduce enabled keywords
mdh1418 04f072c
Switch to AllocationSampled Event
mdh1418 98496bc
Attempt to copy userevents assets for CI
mdh1418 96efe8e
Enable Helix tests to run record-trace
mdh1418 fe00510
Add requirements check and upload trace
mdh1418 368b499
Configure DiagnosticPort creation for RecordTrace
mdh1418 50b29aa
[Test] Extend UserEvents to reusable TestRunner
mdh1418 2811831
[Test] Remove eventpipe embedded userevents tests
mdh1418 23474bb
[TEMP] disable all other pipelines
mdh1418 4e2febb
Merge remote-tracking branch 'upstream/main' into user_events_functio…
mdh1418 0acfb99
Include userevents_common in helix payload
mdh1418 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| let Microsoft_Windows_DotNETRuntime_flags = new_dotnet_provider_flags(); | ||
| record_dotnet_provider("Microsoft-Windows-DotNETRuntime", 0x100003801D, 4, Microsoft_Windows_DotNETRuntime_flags); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using Microsoft.Diagnostics.Tracing; | ||
| using Microsoft.Diagnostics.Tracing.Etlx; | ||
|
|
||
| namespace Tracing.Tests.UserEvents | ||
| { | ||
| public class UserEventsTest | ||
| { | ||
| private static readonly string trace = "trace.nettrace"; | ||
| private const int SIGINT = 2; | ||
|
|
||
| [DllImport("libc", SetLastError = true)] | ||
| private static extern int kill(int pid, int sig); | ||
|
|
||
| public static int Main(string[] args) | ||
| { | ||
| if (args.Length > 0 && args[0] == "tracee") | ||
| { | ||
| UserEventsTracee.Run(); | ||
| return 0; | ||
| } | ||
|
|
||
| return TestEntryPoint(); | ||
| } | ||
|
|
||
| public static int TestEntryPoint() | ||
| { | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| string appBaseDir = AppContext.BaseDirectory; | ||
| string recordTracePath = Path.Combine(appBaseDir, "record-trace"); | ||
| string scriptFilePath = Path.Combine(appBaseDir, "dotnet-common.script"); | ||
| string traceFilePath = Path.Combine(appBaseDir, trace); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!File.Exists(recordTracePath) || !File.Exists(scriptFilePath)) | ||
| { | ||
| Console.WriteLine("record-trace or dotnet-common.script not found. Test cannot run."); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return -1; | ||
| } | ||
|
|
||
| Process traceeProcess = new(); | ||
| traceeProcess.StartInfo.FileName = Process.GetCurrentProcess().MainModule.FileName; | ||
| traceeProcess.StartInfo.Arguments = $"{typeof(UserEventsTest).Assembly.Location} tracee"; | ||
| traceeProcess.StartInfo.WorkingDirectory = appBaseDir; | ||
| traceeProcess.Start(); | ||
| int traceePid = traceeProcess.Id; | ||
|
|
||
| Process recordTraceProcess = new(); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| recordTraceProcess.StartInfo.FileName = recordTracePath; | ||
| recordTraceProcess.StartInfo.Arguments = $"--script-file {scriptFilePath} --pid {traceePid}"; | ||
| recordTraceProcess.StartInfo.WorkingDirectory = appBaseDir; | ||
| recordTraceProcess.StartInfo.RedirectStandardOutput = true; | ||
| recordTraceProcess.StartInfo.RedirectStandardError = true; | ||
| recordTraceProcess.OutputDataReceived += (_, args) => Console.WriteLine($"[record-trace] {args.Data}"); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| recordTraceProcess.ErrorDataReceived += (_, args) => Console.Error.WriteLine($"[record-trace] {args.Data}"); | ||
| recordTraceProcess.Start(); | ||
| recordTraceProcess.BeginOutputReadLine(); | ||
| recordTraceProcess.BeginErrorReadLine(); | ||
|
|
||
| if (!recordTraceProcess.HasExited && !traceeProcess.WaitForExit(15000)) | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| traceeProcess.Kill(); | ||
| } | ||
|
|
||
| // Until record-trace supports duration, the only way to stop it is to send SIGINT (ctrl+c) | ||
| kill(recordTraceProcess.Id, SIGINT); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!recordTraceProcess.HasExited && !recordTraceProcess.WaitForExit(20000)) | ||
| { | ||
| // record-trace needs to stop gracefully to generate the trace file | ||
| recordTraceProcess.Kill(); | ||
| } | ||
|
|
||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!File.Exists(traceFilePath)) | ||
| { | ||
| Console.Error.WriteLine($"Expected trace file not found at `{traceFilePath}`"); | ||
| return -1; | ||
| } | ||
|
|
||
| if (!ValidateTraceeEvents(traceFilePath)) | ||
| { | ||
| Console.Error.WriteLine($"Trace file `{traceFilePath}` does not contain expected events."); | ||
| return -1; | ||
| } | ||
|
|
||
| if (File.Exists(traceFilePath)) | ||
| { | ||
| try | ||
| { | ||
| File.Delete(traceFilePath); | ||
| } | ||
| catch {} | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return 100; | ||
| } | ||
|
|
||
| private static bool ValidateTraceeEvents(string traceFilePath) | ||
| { | ||
| string etlxPath = TraceLog.CreateFromEventPipeDataFile(traceFilePath); | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using TraceLog log = new(etlxPath); | ||
| using TraceLogEventSource source = log.Events.GetSource(); | ||
| bool startEventFound = false; | ||
| bool stopEventFound = false; | ||
|
|
||
| source.AllEvents += (TraceEvent e) => | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (e.ProviderName == "Microsoft-Windows-DotNETRuntime") | ||
| { | ||
| if (e.EventName == "GC/Start") | ||
| { | ||
| startEventFound = true; | ||
| } | ||
| else if (e.EventName == "GC/Stop") | ||
| { | ||
| stopEventFound = true; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| source.Process(); | ||
| return startEventFound && stopEventFound; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <CLRTestTargetUnsupported Condition="'$(TargetOS)' != 'linux' or ('$(TargetArchitecture)' != 'x64' and '$(TargetArchitecture)' != 'arm64')">true</CLRTestTargetUnsupported> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| <ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator> | ||
| <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier> | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <IlasmRoundTripIncompatible>true</IlasmRoundTripIncompatible> | ||
| <MicrosoftOneCollectRecordTraceVersion>0.1.32221</MicrosoftOneCollectRecordTraceVersion> | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-diagnostics-tests/nuget/v3/index.json</RestoreAdditionalProjectSources> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.OneCollect.RecordTrace" Version="$(MicrosoftOneCollectRecordTraceVersion)" PrivateAssets="All" Condition="'$(TargetOS)' == 'linux'" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| <Compile Include="usereventstracee.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="dotnet-common.script" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="CopyRecordTraceBinary" AfterTargets="Build" Condition="'$(TargetOS)' == 'linux'"> | ||
| <PropertyGroup> | ||
| <RecordTracePath>$(NuGetPackageRoot)microsoft.onecollect.recordtrace/$(MicrosoftOneCollectRecordTraceVersion)/runtimes/$(TargetOS)-$(TargetArchitecture)/native/record-trace</RecordTracePath> | ||
| </PropertyGroup> | ||
|
|
||
| <Copy SourceFiles="$(RecordTracePath)" DestinationFolder="$(OutputPath)" Condition="Exists('$(RecordTracePath)')" /> | ||
| <Error Text="record-trace not found at $(RecordTracePath)" Condition="!Exists('$(RecordTracePath)')" /> | ||
| </Target> | ||
| </Project> | ||
31 changes: 31 additions & 0 deletions
31
src/tests/tracing/eventpipe/userevents/usereventstracee.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
|
|
||
| namespace Tracing.Tests.UserEvents | ||
| { | ||
| public class UserEventsTracee | ||
| { | ||
| private static byte[] s_array; | ||
|
|
||
| public static void Run() | ||
| { | ||
| long startTimestamp = Stopwatch.GetTimestamp(); | ||
| long targetTicks = Stopwatch.Frequency * 10; // 10s | ||
mdh1418 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| while (Stopwatch.GetTimestamp() - startTimestamp < targetTicks) | ||
| { | ||
| for (int i = 0; i < 100; i++) | ||
| { | ||
| s_array = new byte[1024 * 10]; | ||
| } | ||
|
|
||
| GC.Collect(); | ||
| Thread.Sleep(100); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.