Beispiel #1
0
        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);
            }
        }
Beispiel #2
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();
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }