|
| 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 | + |
| 4 | +using System; |
| 5 | +using System.Diagnostics; |
| 6 | +using System.Threading; |
| 7 | +using Tracing.UserEvents.Tests.Common; |
| 8 | +using Microsoft.Diagnostics.Tracing; |
| 9 | + |
| 10 | +namespace Tracing.UserEvents.Tests.Basic |
| 11 | +{ |
| 12 | + public class Basic |
| 13 | + { |
| 14 | + private static byte[] s_array; |
| 15 | + |
| 16 | + public static void BasicTracee() |
| 17 | + { |
| 18 | + long startTimestamp = Stopwatch.GetTimestamp(); |
| 19 | + long targetTicks = Stopwatch.Frequency; // 1s |
| 20 | + |
| 21 | + while (Stopwatch.GetTimestamp() - startTimestamp < targetTicks) |
| 22 | + { |
| 23 | + s_array = new byte[1024 * 100]; |
| 24 | + Thread.Sleep(100); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + private readonly static Func<EventPipeEventSource, bool> s_traceValidator = source => |
| 29 | + { |
| 30 | + bool allocationSampledEventFound = false; |
| 31 | + |
| 32 | + source.Dynamic.All += (TraceEvent e) => |
| 33 | + { |
| 34 | + if (e.ProviderName == "Microsoft-Windows-DotNETRuntime") |
| 35 | + { |
| 36 | + // TraceEvent's ClrTraceEventParser does not know about the AllocationSampled Event, so it shows up as "Unknown(303)" |
| 37 | + if (e.EventName.StartsWith("Unknown") && e.ID == (TraceEventID)303) |
| 38 | + { |
| 39 | + allocationSampledEventFound = true; |
| 40 | + } |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + source.Process(); |
| 45 | + |
| 46 | + if (!allocationSampledEventFound) |
| 47 | + { |
| 48 | + Console.Error.WriteLine("The trace did not contain an AllocationSampled event."); |
| 49 | + } |
| 50 | + return allocationSampledEventFound; |
| 51 | + }; |
| 52 | + |
| 53 | + public static int Main(string[] args) |
| 54 | + { |
| 55 | + if (args.Length > 0 && args[0].Equals("tracee", StringComparison.OrdinalIgnoreCase)) |
| 56 | + { |
| 57 | + BasicTracee(); |
| 58 | + return 0; |
| 59 | + } |
| 60 | + |
| 61 | + return UserEventsTestRunner.Run("basic", typeof(Basic).Assembly.Location, s_traceValidator); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments