public async Task Profiler_Counts_Exceptions()
    {
        ILogger          logger           = new Logger();
        SessionDiscovery sessionDiscovery = new SessionDiscovery(logger);
        Profiler         profiler         = GetProfiler();

        Guid sessionId = profiler.StartProfilingSession(Process.GetCurrentProcess().Id, logger);

        // Intentionally throws (handled) exceptions
        ThreadPool.QueueUserWorkItem(async _ =>
        {
            while (true)
            {
                try
                {
                    throw new TestException();
                }
                catch { }
                await Task.Delay(300);
            }
        });

        var session = await sessionDiscovery.AwaitUntilCompletion(sessionId);

        var summary = session.EnumerateFiles().Where(x => x.Name == "summary.md").FirstOrDefault();

        Assert.NotNull(summary, "No summary have been created!");

        var content = File.ReadAllText(summary.FullName);

        Console.WriteLine(content);

        Assert.IsTrue(content.Contains("DrDotnet.Tests.TestException:"));
        Assert.IsFalse(content.Contains("DrDotnet.Tests.TestException: 0"));
    }
Exemple #2
0
    public async Task Profiler_Counts_Allocations_By_Class()
    {
        ILogger          logger           = new Logger();
        SessionDiscovery sessionDiscovery = new SessionDiscovery(logger);
        Profiler         profiler         = GetProfiler();

        Guid sessionId = profiler.StartProfilingSession(Process.GetCurrentProcess().Id, logger);

        // Intentionally allocates memory
        int  i    = 0;
        Node node = new Node();

        ThreadPool.QueueUserWorkItem(async _ =>
        {
            while (true)
            {
                node.Child = node = new Node {
                    Name = "mynode" + i++, List = new List <int>()
                };
                if (i % 100 == 0)
                {
                    await Task.Delay(10);
                }
                if (i % 1000 == 0)
                {
                    GC.Collect();
                }
            }
        });

        var session = await sessionDiscovery.AwaitUntilCompletion(sessionId);

        var summary = session.EnumerateFiles().Where(x => x.Name == "summary.md").FirstOrDefault();

        Assert.NotNull(summary, "No summary have been created!");

        var content = File.ReadAllText(summary.FullName);

        Console.WriteLine(content);
        Console.WriteLine(node.Name);

        //Assert.IsTrue(content.Contains("DrDotnet.Tests.TestException:"));
        //Assert.IsFalse(content.Contains("DrDotnet.Tests.TestException: 0"));
    }