Why does Visual Studio Profiler fail to display thread names in Resource Contention Data report

462 Views Asked by At

I am trying to profile some multithreaded C# app in VS2013 profiler using Resource Contention Data profiling method, but the problem is that the thread names are not displayed in report, instead I see dummy [clr.dll] name as a thread name. I've found some links in Internet stating that it should be possible at least in VS2010 but nothing helped me.

What should I do to see the thread names in reports?

VS 2010 Beta 2 Concurrency Resource Profiling In Depth First Look

VS 2010 Beta 2 Concurrency Visualizer Profiling In Depth First Look

Profiling an application with Visual Studio – Concurrency

By the way. I use VS2013 Update 4. The test was performed with .NET 3.5, 4.0, 4.5(.1). The app code is shown below:

static void Main(string[] args)
{
    Thread[] threads = new Thread[Environment.ProcessorCount];

    ValueContainer<int> counterContainer = new ValueContainer<int>();
    ValueContainer<byte> shouldStopContainer = new ValueContainer<byte>();

    object locker = new object();

    for (int i = 0; i < threads.Length; i++)
    {
        ThreadData tData = new ThreadData
        {
            CounterContainer = counterContainer,
            ShouldStopContainer = shouldStopContainer,
            Locker = locker,
            SleepDelay = i * 50
        };

        threads[i] = new Thread(threadProc);
        threads[i].Name = "CalcThread_" + i.ToString();
        threads[i].Start(tData);
    }

    Thread.Sleep(10000);

    Thread.VolatileWrite(ref shouldStopContainer.Value, 1);

    for (int i = 0; i < threads.Length; i++)
    {
        threads[i].Join();
    }

    Console.WriteLine(counterContainer.Value);
}

private static void threadProc(object state)
{
    ThreadData tData = state as ThreadData;

    while (Thread.VolatileRead(ref tData.ShouldStopContainer.Value) == 0)
    {
        lock (tData.Locker)
        {
            tData.CounterContainer.Value++;

            Thread.Sleep(tData.SleepDelay);
        }
    }
}

public class ValueContainer<T>
{
    public T Value;
}

public class ThreadData
{
    public ValueContainer<int> CounterContainer { get; set; }
    public ValueContainer<byte> ShouldStopContainer { get; set; }
    public object Locker { get; set; }
    public int SleepDelay { get; set; }
}
0

There are 0 best solutions below