Пример #1
0
        static void Main(string[] args)
        {
            var logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.File(new CompactJsonFormatter(), "report.txt")
                         .WriteTo.Console()
                         .CreateLogger();

            var profiler = new ProfilerConfiguration()
                           .UseSerilogReportWriter(settings => settings
                                                   .UseLogEventLevel(LogEventLevel.Verbose)
                                                   .UseDefaultReportFormatter()
                                                   .UseLogger(logger))
                           .CreateProfiler();

            int n = 100;

            var tasks = new Task[n];

            for (int i = 0; i < n; i++)
            {
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    using (var section = profiler.Section("outer {number}", "one"))
                    {
                        using (var section2 = section.Section("inner {letter}", "z"))
                        {
                            using (section2.Section("deep {sign}", "-"))
                            {
                            }

                            using (section2.Section("deep {sign}", "+"))
                            {
                            }
                        }

                        using (var section2 = section.Section("inner {letter}", "x"))
                        {
                            using (section2.Section("deep {sign}", "-"))
                            {
                            }

                            using (section2.Section("deep {sign}", "+"))
                            {
                            }
                        }
                    }
                });
            }

            Task.WaitAll(tasks);

            profiler.WriteReport();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var profiler = new ProfilerConfiguration()
                           .UseStopwatchTimeMeasure()
                           .UseConsoleTraceWriter()
                           .UseConsoleReportWriter()
                           .CreateProfiler();

            var threads = new List <Thread>();

            for (int i = 0; i < 3; i++)
            {
                var thread = new Thread(() =>
                {
                    TimeSpan delay = TimeSpan.FromMilliseconds(i * 100);
                    using (var section = profiler.Section("section.{i}.{delay}", i, delay))
                    {
                        Thread.Sleep(delay);

                        for (int j = 0; j < 3; j++)
                        {
                            TimeSpan innerDelay = TimeSpan.FromMilliseconds(j * 10);
                            using (section.Section("child.{j}.{innerDelay}", j, innerDelay))
                            {
                                Thread.Sleep(innerDelay);
                            }
                        }
                    }
                });
                threads.Add(thread);
                thread.Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            profiler.WriteReport();

            Console.ReadKey();
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            var insider = new LocalInsiderConfiguration()
                          .ConfigureDefault()
                          .CreateInsider();

            var profiler = new ProfilerConfiguration()
                           .UseInsiderReportWriter(insider)
                           .CreateProfiler();

            insider.Run();

            Console.WriteLine("Commands:");
            Console.WriteLine("e - [E]xit");
            Console.WriteLine("s - measure-[S]tart KEY");
            Console.WriteLine("p - measure-[P]ause KEY");
            Console.WriteLine("r - measure-[R]eport");
            Console.WriteLine("v - state-set KEY [V]ALUE");
            Console.WriteLine("b - open [B]rowser with `ui-web` page");

            var sections = new Dictionary <string, ISection>();

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Press one key of: 'e', 's', 'p', 'r', 'v', 'b':");

                var command = Console.ReadKey().KeyChar;

                if (!new[] { 'e', 's', 'p', 'r', 'v', 'b' }.Contains(command))
                {
                    continue;
                }

                if (command == 'e')
                {
                    break;
                }
                else if (command == 's')
                {
                    Console.WriteLine(" - measure-start");

                    Console.Write("KEY: ");
                    string key = Console.ReadLine();

                    if (!sections.ContainsKey(key))
                    {
                        sections[key] = profiler.Section(key);
                    }
                }
                else if (command == 'p')
                {
                    Console.WriteLine(" - measure-pause");

                    Console.Write("KEY: ");
                    string key = Console.ReadLine();

                    if (sections.TryGetValue(key, out ISection section))
                    {
                        section.Dispose();

                        Console.WriteLine($"measure: {(section as ISectionMetrics).Elapsed}");

                        sections.Remove(key);
                    }
                }
                else if (command == 'r')
                {
                    Console.WriteLine(" - measure-report");

                    profiler.WriteReport();
                }
                else if (command == 'v')
                {
                    Console.WriteLine(" - state-set");

                    Console.Write("KEY: ");
                    string key = Console.ReadLine();

                    Console.Write("VALUE: ");
                    string value = Console.ReadLine();

                    insider.SetState(new[] { key }, value);
                }
                else if (command == 'b')
                {
                    Browser.Open("http://localhost:8080/insider/ui-web");
                }
            }

            await insider.StopAsync();

            Console.ReadKey();
        }