Exemplo n.º 1
0
            public void Dispose()
            {
                var scope = (IServiceScope)_threadData[ThreadDataKey];

                scope?.Dispose();
                _threadData.SetValue(ThreadDataKey, null);
            }
Exemplo n.º 2
0
        private Dictionary <Type, DataInterceptor> GetDataInterceptors(ThreadDataManagerData threadData)
        {
            Verify.ArgumentNotNull(threadData, nameof(threadData));
            const string threadDataKey = "DataFacade:DataInterceptors";

            var dataInterceptors = threadData.GetValue(threadDataKey) as Dictionary <Type, DataInterceptor>;

            if (dataInterceptors == null)
            {
                dataInterceptors = new Dictionary <Type, DataInterceptor>();
                threadData.SetValue(threadDataKey, dataInterceptors);
            }

            return(dataInterceptors);
        }
Exemplo n.º 3
0
        // private static readonly IEnumerable<Measurement> EmptyReport = new Measurement[0];


        /// <exclude />
        public static void BeginProfiling()
        {
            if (Disabled)
            {
                return;
            }

            ThreadDataManagerData threadData = ThreadDataManager.Current;

            Verify.That(!threadData.HasValue(ProfilerKey), "Profiler has already been initialized");

            var stack = new Stack <Measurement>();

            stack.Push(new Measurement("Root")
            {
                MemoryUsage = GC.GetTotalMemory(true)
            });
            threadData.SetValue(ProfilerKey, stack);
        }
Exemplo n.º 4
0
        /// <exclude />
        public static IDisposable Measure(string name, Func <EntityToken> entityTokenFactory)
        {
            if (Disabled)
            {
                return(EmptyDisposable.Instance);
            }

            Measurement         currentNode;
            Stack <Measurement> stack;
            bool isInParallel;

            if (!GetCurrentNode(out currentNode, out stack, out isInParallel))
            {
                return(EmptyDisposable.Instance);
            }

            Stack <Measurement> newNodeStack;

            if (isInParallel)
            {
                ThreadDataManagerData currentThreadData = ThreadDataManager.Current;

                if (currentThreadData.HasValue(currentThreadData))
                {
                    newNodeStack = currentThreadData[ProfilerKey] as Stack <Measurement>;
                }
                else
                {
                    newNodeStack = new Stack <Measurement>();
                    currentThreadData.SetValue(ProfilerKey, newNodeStack);
                }
            }
            else
            {
                newNodeStack = stack;
            }

            return(new InfoCollector(currentNode, name, isInParallel, newNodeStack, entityTokenFactory));
        }