Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                s_numTasks = Convert.ToInt32(args[0]);
            }
            int currentIteration = 1;

            Thread taskThread = new Thread(new ThreadStart(TaskThreadProc));

            taskThread.Start();

            while (!s_errorOccurred)
            {
                Console.WriteLine("Running iteration {0}", currentIteration++);

                // Start tracing.
                TraceControl.EnableDefault();

                // Sleep for 5 seconds to fill the trace buffer.
                Thread.Sleep(TimeSpan.FromSeconds(5));

                // Stop tracing.
                TraceControl.Disable();
            }
        }
        static int Main(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(netPerfFile.Path);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Allocation.");
                // Allocate for allocIterations iterations.
                for (int i = 0; i < allocIterations; i++)
                {
                    GC.KeepAlive(new object());
                }
                Console.WriteLine("\tEnd: Allocation.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                FileInfo outputMeta = new FileInfo(netPerfFile.Path);
                Console.WriteLine("\tExpecting at least {0} bytes of data", trivialSize);
                Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

                return(outputMeta.Length > trivialSize ? 100 : 0);
            }
        }
Exemple #3
0
        static int Main(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                SimpleEventSource eventSource = new SimpleEventSource();

                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.Enable(GetConfig(eventSource, netPerfFile.Path));
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Messaging.");
                // Send messages
                // Use random numbers and addition as a simple, human readble checksum
                Random generator = new Random();
                for (int i = 0; i < messageIterations; i++)
                {
                    int    x       = generator.Next(1, 1000);
                    int    y       = generator.Next(1, 1000);
                    string formula = String.Format("{0} + {1} = {2}", x, y, x + y);

                    eventSource.MathResult(x, y, x + y, formula);
                }
                Console.WriteLine("\tEnd: Messaging.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                FileInfo outputMeta = new FileInfo(netPerfFile.Path);
                Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

                return(outputMeta.Length > trivialSize ? 100 : -1);
            }
        }
Exemple #4
0
        public static int Main(string[] args)
        {
            // Additional assemblies will be seen, but these are ones we must see
            string[] AssembliesExpected = new string[] {
                "rundown", // this assembly
                "System.Runtime",
                "Microsoft.Diagnostics.Tracing.TraceEvent",
                "System.Diagnostics.Tracing",
                "System.Private.CoreLib"
            };

            using (var netPerfFile = NetPerfFile.Create(args))
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(netPerfFile.Path);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                // Since all we care about is rundown, there is nothing to do there

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Process the trace file.");

                var assembliesLoaded      = new HashSet <string>();
                int nonMatchingEventCount = 0;

                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(netPerfFile.Path))
                {
                    var rundownParser = new ClrRundownTraceEventParser(trace);

                    rundownParser.LoaderAssemblyDCStop += delegate(AssemblyLoadUnloadTraceData data)
                    {
                        var nameIndex = Array.IndexOf(data.PayloadNames, ("FullyQualifiedAssemblyName"));
                        if (nameIndex >= 0)
                        {
                            // Add the assembly name to a set to verify later
                            assembliesLoaded.Add(((string)data.PayloadValue(nameIndex)).Split(',')[0]);
                        }
                        else
                        {
                            nonMatchingEventCount++;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                foreach (var name in AssembliesExpected)
                {
                    Assert.True($"Assembly {name} in loaded assemblies", assembliesLoaded.Contains(name));
                }
                Assert.Equal(nameof(nonMatchingEventCount), nonMatchingEventCount, 0);
            }

            return(100);
        }
Exemple #5
0
 public void UpdatePages()
 {
     MatrControl.UpdateMatrices();
     CompControl.Update();
     PlaceControl.Update();
     TraceControl.Update();
     LayerControl.Update();
 }
Exemple #6
0
        static int Main(string[] args)
        {
            bool keepOutput = false;
            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            Console.WriteLine("\tStart: Enable tracing.");
            TraceControl.EnableDefault(outputFilename);
            Console.WriteLine("\tEnd: Enable tracing.\n");

            Console.WriteLine("\tStart: Allocation.");
            // Allocate for allocIterations iterations.
            for (int i = 0; i < allocIterations; i++)
            {
                GC.KeepAlive(new object());
            }
            Console.WriteLine("\tEnd: Allocation.\n");

            Console.WriteLine("\tStart: Disable tracing.");
            TraceControl.Disable();
            Console.WriteLine("\tEnd: Disable tracing.\n");

            FileInfo outputMeta = new FileInfo(outputFilename);

            Console.WriteLine("\tExpecting at least {0} bytes of data", trivialSize);
            Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

            bool pass = false;

            if (outputMeta.Length > trivialSize)
            {
                pass = true;
            }

            if (keepOutput)
            {
                Console.WriteLine(String.Format("\tOutput file: {0}", outputFilename));
            }
            else
            {
                System.IO.File.Delete(outputFilename);
            }

            return(pass ? 100 : 0);
        }
        public PluginTraceViewer()
        {
            InitializeComponent();
            var theme = new VS2015LightTheme();

            dockContainer.Theme = theme;
            gridControl         = new GridControl(this);
            filterControl       = new FilterControl(this);
            statsControl        = new StatsControl(this);
            traceControl        = new TraceControl();
            exceptionControl    = new ExceptionControl();
        }
Exemple #8
0
        static TimeSpan Run(bool enableTracing, WorkerArgs workerArgs)
        {
            // Create threads.
            Thread[] workers = new Thread[NumThreads];
            for (int i = 0; i < NumThreads; i++)
            {
                workers[i] = new Thread(WorkerThreadProc);
            }

            // Start tracing.
            if (enableTracing)
            {
                TraceControl.EnableDefault(TimeSpan.FromMilliseconds(1));
            }

            // Start time measurement.
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Start threads.
            for (int i = 0; i < NumThreads; i++)
            {
                workers[i].Start(workerArgs);

                // Insert some delay between threads so that they don't all try to take the CPU at the same time.
                Thread.Sleep(1);
            }

            // Wait for threads to run to completion.
            for (int i = 0; i < NumThreads; i++)
            {
                workers[i].Join();
            }

            // Stop time measurement.
            stopWatch.Stop();

            // Stop tracing.
            if (enableTracing)
            {
                Console.WriteLine("\tStart: Rundown/Write");
                TraceControl.Disable();
                Console.WriteLine("\tStop: Rundown/Write");
            }

            // Perform a full blocking GC to allow threads to be cleaned up.
            workers = null;
            GC.Collect(2, GCCollectionMode.Forced);

            return(stopWatch.Elapsed);
        }
Exemple #9
0
        public static int Main(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(netPerfFile.Path);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Generate some events.");
                DynamicallyCompiledMethodInvoker invoker = BuildDynamicMethod();
                invoker.Invoke();
                Console.WriteLine("\tEnd: Generate some events.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Process the trace file.");

                int matchingEventCount    = 0;
                int nonMatchingEventCount = 0;

                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(netPerfFile.Path))
                {
                    string methodNamespace      = "dynamicClass";
                    string methodName           = "DynamicallyCompiledMethod";
                    string methodSignature      = "void  ()";
                    string providerName         = "Microsoft-Windows-DotNETRuntime";
                    string gcTriggeredEventName = "Method/JittingStarted";

                    trace.Clr.MethodJittingStarted += delegate(MethodJittingStartedTraceData data)
                    {
                        if (methodNamespace.Equals(data.MethodNamespace) &&
                            methodName.Equals(data.MethodName) &&
                            methodSignature.Equals(data.MethodSignature) &&
                            providerName.Equals(data.ProviderName) &&
                            gcTriggeredEventName.Equals(data.EventName))
                        {
                            matchingEventCount++;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                // CompiledMethod
                Assert.Equal(nameof(matchingEventCount), matchingEventCount, 1);
            }

            return(100);
        }
Exemple #10
0
        public static int Main(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(netPerfFile.Path);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Generate some events.");
                for (int i = 0; i < InducedGCIterations; i++)
                {
                    GC.Collect();
                }
                Console.WriteLine("\tEnd: Generate some events.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Process the trace file.");
                int matchingEventCount    = 0;
                int nonMatchingEventCount = 0;
                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(netPerfFile.Path))
                {
                    string gcReasonInduced      = GCReason.Induced.ToString();
                    string providerName         = "Microsoft-Windows-DotNETRuntime";
                    string gcTriggeredEventName = "GC/Triggered";

                    trace.Clr.GCTriggered += delegate(GCTriggeredTraceData data)
                    {
                        if (gcReasonInduced.Equals(data.Reason.ToString()) &&
                            providerName.Equals(data.ProviderName) &&
                            gcTriggeredEventName.Equals(data.EventName))
                        {
                            matchingEventCount++;
                        }
                        else
                        {
                            nonMatchingEventCount++;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                Assert.Equal(nameof(matchingEventCount), InducedGCIterations, matchingEventCount);
                Assert.Equal(nameof(nonMatchingEventCount), nonMatchingEventCount, 0);
            }

            return(100);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            // Start the allocator thread.
            //Task t = new Task(new Action(Allocator));
            //t.Start();

            string             outputFilename = string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            TraceConfiguration config         = CreateConfiguration(outputFilename);

            Console.WriteLine("\tStart: Enable tracing.");
            TraceControl.Enable(config);
            Console.WriteLine("\tEnd: Enable tracing.\n");

            Console.WriteLine("\tStart: Allocation.");
            // Allocate for allocIterations iterations.
            for (int i = 0; i < allocIterations; i++)
            {
                GC.KeepAlive(new object());
            }
            Console.WriteLine("\tEnd: Allocation.\n");

            Console.WriteLine("\tStart: Disable tracing.");
            TraceControl.Disable();
            Console.WriteLine("\tEnd: Disable tracing.\n");

            FileInfo outputMeta = new FileInfo(outputFilename);

            Console.WriteLine("\tCreated {0} bytes of data", FileInfo.Length);

            if (keepOutput)
            {
                Console.WriteLine(String.Fromat("\tOutput file: {0}", outputFilename));
            }
            else
            {
                System.IO.File.Delete(outputFilename);
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            var control = new TraceControl();

            while (true)
            {
                Console.WriteLine("type 'trace' or 'verbose' or 'none'");
                var kind = Console.ReadLine();
                switch (kind)
                {
                case "trace":
                    control.SetKind(TraceKind.Trace);
                    break;

                case "verbose":
                    control.SetKind(TraceKind.Verbose);
                    break;

                default:
                    control.SetKind(TraceKind.None);
                    break;
                }
            }
        }
Exemple #13
0
        private static void RoundTwo(string[] args)
        {
            using (var netPerfFile = NetPerfFile.Create(args))
            {
                using (var etlFile = EtlFile.Create(args))
                {
                    Console.WriteLine("\tStart: Enable EventPipe.");
                    TraceControl.Enable(EventPipeGetConfig(EventPipeAndEtwEventSource.Log, EventPipeAndEtwEventSource.Keywords.EventPipeKeyword, netPerfFile.Path));
                    Console.WriteLine("\tEnd: Enable EventPipe.\n");

                    Console.WriteLine("\tStart: Enable ETW.");
                    TraceEventSession etwSession = EnableETW(EventPipeAndEtwEventSource.Log, EventPipeAndEtwEventSource.Keywords.EtwKeyword, etlFile.Path);
                    Console.WriteLine("\tEnd: Enable ETW.\n");

                    WriteAllEvents(EventPipeAndEtwEventSource.Log);

                    Console.WriteLine("\tStart: Disable EventPipe.");
                    TraceControl.Disable();
                    Console.WriteLine("\tEnd: Disable EventPipe.\n");

                    WriteAllEvents(EventPipeAndEtwEventSource.Log);

                    Console.WriteLine("\tStart: Disable ETW.");
                    DisableETW(etwSession);
                    Console.WriteLine("\tEnd: Disable ETW.\n");

                    Console.WriteLine("\tStart: Processing events from EventPipe file.");

                    EventResults eventPipeResults = new EventResults();
                    EventResults etwResults       = new EventResults();

                    using (var trace = new TraceLog(TraceLog.CreateFromEventPipeDataFile(netPerfFile.Path)).Events.GetSource())
                    {
                        trace.Dynamic.All += delegate(TraceEvent data)
                        {
                            eventPipeResults.AddEvent(data);
                        };

                        trace.Process();
                    }

                    // Validate EventPipe results.
                    eventPipeResults.Print("EventPipe Results:");
                    Assert.Equal("EventPipeEvent1Count", eventPipeResults.Event1Count, 1);
                    Assert.Equal("EventPipeEvent2Count", eventPipeResults.Event2Count, 0);
                    Assert.Equal("EventPipeEvent3Count", eventPipeResults.Event3Count, 1);

                    Console.WriteLine("\tEnd: Processing events from EventPipe file.\n");

                    Console.WriteLine("\tStart: Processing events from ETW file.");

                    using (var trace = new ETWTraceEventSource(etlFile.Path))
                    {
                        trace.Dynamic.All += delegate(TraceEvent data)
                        {
                            etwResults.AddEvent(data);
                        };

                        trace.Process();
                    }

                    // Validate ETW results.
                    etwResults.Print("ETW Results:");
                    Assert.Equal("EventPipeEvent1Count", etwResults.Event1Count, 0);
                    Assert.Equal("EventPipeEvent2Count", etwResults.Event2Count, 2);
                    Assert.Equal("EventPipeEvent3Count", etwResults.Event3Count, 2);

                    Console.WriteLine("\tEnd: Processing events from ETW file.");
                }
            }
        }
Exemple #14
0
        static int Main(string[] args)
        {
            bool pass       = true;
            bool keepOutput = false;

            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            try
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(outputFilename);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Generating CLR events");
                // Allocate for allocIterations iterations.
                for (int i = 0; i < allocIterations; i++)
                {
                    GC.KeepAlive(new object());
                }
                // GC gcIternation times
                for (int i = 0; i < gcIterations; i++)
                {
                    GC.Collect();
                }
                Console.WriteLine("\tEnd: Generating CLR Events\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Processing events from file.");
                int allocTickCount = 0;
                int gcTriggerCount = 0;
                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
                {
                    trace.Clr.GCAllocationTick += delegate(GCAllocationTickTraceData data)
                    {
                        allocTickCount += 1;

                        // Some basic integrity checks
                        AssertEqual(data.TypeName, "System.Object");
                        AssertEqual(data.AllocationKind.ToString(), GCAllocationKind.Small.ToString());
                        AssertEqual(data.ProviderName, "Microsoft-Windows-DotNETRuntime");
                        AssertEqual(data.EventName, "GC/AllocationTick");
                    };
                    trace.Clr.GCTriggered += delegate(GCTriggeredTraceData data)
                    {
                        gcTriggerCount += 1;

                        // Some basic integrity checks
                        AssertEqual(data.Reason.ToString(), GCReason.Induced.ToString());
                        AssertEqual(data.ProviderName, "Microsoft-Windows-DotNETRuntime");
                        AssertEqual(data.EventName, "GC/Triggered");
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                Console.WriteLine("\tProcessed {0} GCAllocationTick events", allocTickCount);
                Console.WriteLine("\tProcessed {0} GCTriggered events", gcTriggerCount);

                pass &= allocTickCount > 0;
                pass &= gcTriggerCount == gcIterations;
            }
            finally {
                if (keepOutput)
                {
                    Console.WriteLine("\n\tOutput file: {0}", outputFilename);
                }
                else
                {
                    System.IO.File.Delete(outputFilename);
                }
            }

            return(pass ? 100 : 0);
        }
Exemple #15
0
        static int Main(string[] args)
        {
            bool pass = true;

            using (SimpleEventSource eventSource = new SimpleEventSource())
            {
                using (var netPerfFile = NetPerfFile.Create(args))
                {
                    Console.WriteLine("\tStart: Enable tracing.");
                    TraceControl.Enable(GetConfig(eventSource, netPerfFile.Path));
                    Console.WriteLine("\tEnd: Enable tracing.\n");

                    Console.WriteLine("\tStart: Messaging.");
                    // Send messages
                    // Use random numbers and addition as a simple, human readble checksum
                    Random generator = new Random();
                    for (int i = 0; i < messageIterations; i++)
                    {
                        int    x       = generator.Next(1, 1000);
                        int    y       = generator.Next(1, 1000);
                        string formula = String.Format("{0} + {1} = {2}", x, y, x + y);

                        eventSource.MathResult(x, y, x + y, formula);
                    }
                    Console.WriteLine("\tEnd: Messaging.\n");

                    Console.WriteLine("\tStart: Disable tracing.");
                    TraceControl.Disable();
                    Console.WriteLine("\tEnd: Disable tracing.\n");

                    Console.WriteLine("\tStart: Processing events from file.");
                    int msgCount = 0;
                    using (var trace = new TraceLog(TraceLog.CreateFromEventPipeDataFile(netPerfFile.Path)).Events.GetSource())
                    {
                        var names = new HashSet <string>();

                        trace.Dynamic.All += delegate(TraceEvent data)
                        {
                            if (!names.Contains(data.ProviderName))
                            {
                                Console.WriteLine("\t{0}", data.ProviderName);
                                names.Add(data.ProviderName);
                            }

                            if (data.ProviderName == "SimpleEventSource")
                            {
                                msgCount += 1;
                            }
                        };

                        trace.Process();
                    }
                    Console.WriteLine("\tEnd: Processing events from file.\n");

                    Console.WriteLine("\tProcessed {0} events from EventSource", msgCount);

                    pass &= msgCount == messageIterations;
                }
            }

            return(pass ? 100 : 0);
        }
Exemple #16
0
        public static int Main(string[] args)
        {
            bool pass       = true;
            bool keepOutput = false;

            // Use the first arg as an output filename if there is one.
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            try
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(outputFilename);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Generate some events.");
                for (int i = 0; i < InducedGCIterations; i++)
                {
                    GC.Collect();
                }
                Console.WriteLine("\tEnd: Generate some events.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Process the trace file.");
                int matchingEventCount    = 0;
                int nonMatchingEventCount = 0;
                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
                {
                    string gcReasonInduced      = GCReason.Induced.ToString();
                    string providerName         = "Microsoft-Windows-DotNETRuntime";
                    string gcTriggeredEventName = "GC/Triggered";

                    trace.Clr.GCTriggered += delegate(GCTriggeredTraceData data)
                    {
                        if (gcReasonInduced.Equals(data.Reason.ToString()) &&
                            providerName.Equals(data.ProviderName) &&
                            gcTriggeredEventName.Equals(data.EventName))
                        {
                            matchingEventCount++;
                        }
                        else
                        {
                            nonMatchingEventCount++;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                Assert.Equal(nameof(matchingEventCount), InducedGCIterations, matchingEventCount);
                Assert.Equal(nameof(nonMatchingEventCount), nonMatchingEventCount, 0);
            }
            finally {
                if (keepOutput)
                {
                    Console.WriteLine("\n\tOutput file: {0}", outputFilename);
                }
                else
                {
                    System.IO.File.Delete(outputFilename);
                }
            }

            return(100);
        }
Exemple #17
0
        public static int Main(string[] args)
        {
            bool pass       = true;
            bool keepOutput = false;

            // Use the first arg as an output filename if there is one.
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            try
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.EnableDefault(outputFilename);
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Generate some events.");
                DynamicallyCompiledMethodInvoker invoker = BuildDynamicMethod();
                invoker.Invoke();
                Console.WriteLine("\tEnd: Generate some events.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Process the trace file.");

                int matchingEventCount    = 0;
                int nonMatchingEventCount = 0;

                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
                {
                    string methodNamespace      = "dynamicClass";
                    string methodName           = "DynamicallyCompiledMethod";
                    string methodSignature      = "void  ()";
                    string providerName         = "Microsoft-Windows-DotNETRuntime";
                    string gcTriggeredEventName = "Method/JittingStarted";

                    trace.Clr.MethodJittingStarted += delegate(MethodJittingStartedTraceData data)
                    {
                        if (methodNamespace.Equals(data.MethodNamespace) &&
                            methodName.Equals(data.MethodName) &&
                            methodSignature.Equals(data.MethodSignature) &&
                            providerName.Equals(data.ProviderName) &&
                            gcTriggeredEventName.Equals(data.EventName))
                        {
                            matchingEventCount++;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                // CompiledMethod
                Assert.Equal(nameof(matchingEventCount), matchingEventCount, 1);
            }
            finally
            {
                if (keepOutput)
                {
                    Console.WriteLine("\n\tOutput file: {0}", outputFilename);
                }
                else
                {
                    System.IO.File.Delete(outputFilename);
                }
            }

            return(100);
        }
        static int Main(string[] args)
        {
            bool keepOutput = false;
            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            SimpleEventSource eventSource = new SimpleEventSource();

            Console.WriteLine("\tStart: Enable tracing.");
            TraceControl.Enable(GetConfig(eventSource, outputFilename));
            Console.WriteLine("\tEnd: Enable tracing.\n");

            Console.WriteLine("\tStart: Messaging.");
            // Send messages
            // Use random numbers and addition as a simple, human readble checksum
            Random generator = new Random();

            for (int i = 0; i < messageIterations; i++)
            {
                int    x      = generator.Next(1, 1000);
                int    y      = generator.Next(1, 1000);
                string result = String.Format("{0} + {1} = {2}", x, y, x + y);

                eventSource.Message(result);
            }
            Console.WriteLine("\tEnd: Messaging.\n");

            Console.WriteLine("\tStart: Disable tracing.");
            TraceControl.Disable();
            Console.WriteLine("\tEnd: Disable tracing.\n");

            FileInfo outputMeta = new FileInfo(outputFilename);

            Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length);

            bool pass = false;

            if (outputMeta.Length > trivialSize)
            {
                pass = true;
            }

            if (keepOutput)
            {
                Console.WriteLine(String.Format("\tOutput file: {0}", outputFilename));
            }
            else
            {
                System.IO.File.Delete(outputFilename);
            }

            return(pass ? 100 : -1);
        }
Exemple #19
0
        static int Main(string[] args)
        {
            bool pass       = true;
            bool keepOutput = false;

            // Use the first arg as an output filename if there is one
            string outputFilename = null;

            if (args.Length >= 1)
            {
                outputFilename = args[0];
                keepOutput     = true;
            }
            else
            {
                outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
            }

            SimpleEventSource eventSource = new SimpleEventSource();

            try
            {
                Console.WriteLine("\tStart: Enable tracing.");
                TraceControl.Enable(GetConfig(eventSource, outputFilename));
                Console.WriteLine("\tEnd: Enable tracing.\n");

                Console.WriteLine("\tStart: Messaging.");
                // Send messages
                // Use random numbers and addition as a simple, human readble checksum
                Random generator = new Random();
                for (int i = 0; i < messageIterations; i++)
                {
                    int    x       = generator.Next(1, 1000);
                    int    y       = generator.Next(1, 1000);
                    string formula = String.Format("{0} + {1} = {2}", x, y, x + y);

                    eventSource.MathResult(x, y, x + y, formula);
                }
                Console.WriteLine("\tEnd: Messaging.\n");

                Console.WriteLine("\tStart: Disable tracing.");
                TraceControl.Disable();
                Console.WriteLine("\tEnd: Disable tracing.\n");

                Console.WriteLine("\tStart: Processing events from file.");
                int msgCount = 0;
                using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
                {
                    var names = new HashSet <string>();

                    trace.Dynamic.All += delegate(TraceEvent data)
                    {
                        if (!names.Contains(data.ProviderName))
                        {
                            Console.WriteLine("\t{0}", data.ProviderName);
                            names.Add(data.ProviderName);
                        }

                        if (data.ProviderName == "SimpleEventSource")
                        {
                            msgCount += 1;
                        }
                    };

                    trace.Process();
                }
                Console.WriteLine("\tEnd: Processing events from file.\n");

                Console.WriteLine("\tProcessed {0} events from EventSource", msgCount);

                pass &= msgCount == messageIterations;
            }
            finally {
                if (keepOutput)
                {
                    Console.WriteLine("\n\tOutput file: {0}", outputFilename);
                }
                else
                {
                    System.IO.File.Delete(outputFilename);
                }
            }

            return(pass ? 100 : 0);
        }