/// <summary>
        /// for counting mode
        /// </summary>
        /// <param name="methodHandle"></param>
        /// <param name="methodName"></param>
        public static void StartEndEvent(int methodHandle, int buildKey)
        {
            if (!_CaptureAllowed)
            {
                return;
            }

            Control(buildKey);

            if (!_Initialized)
            {
                Initialize();
            }

            try
            {
                CallStackItem item = new CallStackItem();
                item.MethodHandle = methodHandle;
                item.TotalTick    = _Timer.ElapsedTicks;
            }
            catch (Exception err)
            {
                RuntimeLogger.Instance.Log(LogType.Error, "ReflectionStudio.Spy.Performance.StartEndEvent", err);
            }
        }
        public static void StartEvent(int methodHandle, int buildKey)
        {
            Debug.WriteLine(string.Format("StartEvent : method {0},  ThreadId {1}", methodHandle, Thread.CurrentThread.ManagedThreadId));

            if (!_Initialized)
            {
                Initialize();
            }

            if (!_CaptureAllowed)
            {
                return;
            }

            Control(buildKey);

            try
            {
                Stack <CallStackItem> callStack = GetThreadCallStack();

                CallStackItem item = new CallStackItem();
                item.MethodHandle = methodHandle;
                item.TotalTick    = _Timer.ElapsedTicks;

                callStack.Push(item);
                Debug.WriteLine(string.Format("StartEvent empile: method {0},  ThreadId {1}", methodHandle, Thread.CurrentThread.ManagedThreadId));
            }
            catch (Exception err)
            {
                RuntimeLogger.Instance.Log(LogType.Error, "ReflectionStudio.Spy.Performance.StartEvent {0}", err.Message);
            }
        }
        public static void EndEvent()
        {
            if (!_CaptureAllowed)
            {
                return;
            }
            Debug.WriteLine(string.Format("EndEvent : ThreadId {0}", Thread.CurrentThread.ManagedThreadId));

            long tickCount = _Timer.ElapsedTicks;

            try
            {
                //get the local thread callstack data
                Stack <CallStackItem> callStack = GetThreadCallStack();

                //un-pile the last start event
                CallStackItem info = callStack.Pop();
                info.TotalTick = tickCount - info.TotalTick;

                Debug.WriteLine(string.Format("EndEvent depile: method {0},  ThreadId {1}", info.MethodHandle, Thread.CurrentThread.ManagedThreadId));

                if (callStack.Count != 0)
                {
                    //the one before is the one that called me
                    CallStackItem infoCaller = callStack.Peek();
                    info.CalledByHandle = infoCaller.MethodHandle;
                }

                //write the log
                CallStackLogger.Instance.Write(info);

                //if no more call on the stack, flush the log writer
                if (callStack.Count == 0)
                {
                    CallStackLogger.Instance.Flush();
                    _ThreadSlotCount--;
                    Debug.WriteLine(string.Format("EndEvent : nb slot {0},  ThreadId {1}", _ThreadSlotCount, Thread.CurrentThread.ManagedThreadId));

                    Thread.SetData(_ThreadLocalSlot, null);
                }

                //no more threads with a start event and a callstack
                if (_ThreadSlotCount == 0)
                {
                    CallStackLogger.Instance.Terminate();

                    if (_Host != null)
                    {
                        _Host.StopService();
                    }
                }
            }
            catch (Exception exception)
            {
                RuntimeLogger.Instance.Log(LogType.Error, "ReflectionStudio.Spy.Performance.EndEvent", exception);
            }
        }
Exemple #4
0
        internal void Write(CallStackItem info)
        {
            return;

            lock (_Lock)
            {
                _Buffer.AppendFormat("<I H=\"{0}\" C=\"{1}\" E=\"{2}\"/>",
                                     info.MethodHandle, info.CalledByHandle, info.TotalTick / 0x2710L);
                _Buffer.AppendLine();
            }
            if (_Buffer.Length > _BufferMaxSize - 100)
            {
                Flush();
            }
        }