Esempio n. 1
0
        /// <summary>
        /// 获得第一个快照
        /// </summary>
        internal void GetSnapshotAfter()
        {
            var thread = CodeTimerNativeApi.GetCurrentThread();

            _timer2 = CodeTimerNativeApi.GetCurrentThreadTimes(thread);
            if (IsSupportCycle)
            {
                CodeTimerNativeApi.QueryThreadCycleTime(thread, ref _cycle2);
            }

            _stopWatch.Stop();
            this.ElapsedTime = _stopWatch.Elapsed;

            _gcAfter = new int[GC.MaxGeneration];
            for (var i = 0; i < _gcBefore.Length; i++)
            {
                _gcBefore[i] = GC.CollectionCount(i);
            }

            GCCount = _gcAfter.Select((a, i) => a - _gcBefore[i]).ToArray();
            if (IsSupportCycle)
            {
                ThreadCycleCount = _cycle2 - _cycle1;
            }
            CPUTimer = _timer2 - _timer1;
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        }
Esempio n. 2
0
        /// <summary>
        /// 获得第一个快照
        /// </summary>
        internal void GetSnapshotBefore()
        {
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            _gcBefore = new int[GC.MaxGeneration];
            for (var i = 0; i < _gcBefore.Length; i++)
            {
                _gcBefore[i] = GC.CollectionCount(i);
            }

            var thread = CodeTimerNativeApi.GetCurrentThread();

            _timer1 = CodeTimerNativeApi.GetCurrentThreadTimes(thread);
            if (IsSupportCycle)
            {
                CodeTimerNativeApi.QueryThreadCycleTime(thread, ref _cycle1);
            }
            _stopWatch = new System.Diagnostics.Stopwatch();
            _stopWatch.Start();
        }