Exemplo n.º 1
0
        /// <summary>Creates a Performance countering element. The monitor will be notified on disposal</summary>
        public IDisposable Create(string name)
        {
            if (Enabled)
            {
                PerfElement e  = pool.GetNew();
                int         id = Thread.CurrentThread.ManagedThreadId;
                if (pt_current.TryGetValue(id, out List <PerfElement> list) && list.Count > 0)
                {
                    e.Name = list[list.Count - 1].Name + PerfElement.Delimiter + name;
                }
                else
                {
                    e.Name = name;
                }

                if (pt_current.ContainsKey(id))
                {
                    pt_current[id].Add(e);
                }
                else
                {
                    pt_current.Add(id, new List <PerfElement> {
                        e
                    });
                }
                return(e);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        internal void UpdatePerfElement(PerfElement element, double value)
        {
            if (Queue.Count < _limit)
            {
                Queue.Enqueue(new PerfToken {
                    Name = element.Name, Seconds = value
                });
            }

            int id = Thread.CurrentThread.ManagedThreadId;

            if (pt_current.ContainsKey(id))
            {
                pt_current[id].Remove(element);
            }

            pool.Return(element);
        }