dotnet-installer/src/Microsoft.DotNet.Cli.Utils/Tracing/PerfTrace.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2016-04-27 23:04:26 +00:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
namespace Microsoft.DotNet.Cli.Utils
{
public static class PerfTrace
{
private static ConcurrentBag<PerfTraceThreadContext> _threads = new ConcurrentBag<PerfTraceThreadContext>();
[ThreadStatic]
private static PerfTraceThreadContext _current;
public static bool Enabled { get; set; }
public static PerfTraceThreadContext Current => _current ?? (_current = InitializeCurrent());
private static PerfTraceThreadContext InitializeCurrent()
{
var context = new PerfTraceThreadContext(Thread.CurrentThread.ManagedThreadId);
_threads.Add(context);
return context;
}
public static IEnumerable<PerfTraceThreadContext> GetEvents()
{
return _threads;
}
}
}