コード例 #1
0
 protected void AddRecursiveChildren(MiniProfiler profiler, int maxDepth, int stepMs, int curDepth = 0)
 {
     if (curDepth++ < maxDepth)
     {
         using (profiler.Step("Depth " + curDepth))
         {
             profiler.Increment(stepMs);
             AddRecursiveChildren(profiler, maxDepth, stepMs, curDepth);
         }
     }
 }
コード例 #2
0
        public void WebRequestEnsureName()
        {
            using (var rq = GetRequest("http://localhost/Test.aspx", startAndStopProfiler: false))
            {
                var mp = new MiniProfiler(null, Options);
                mp.Increment(); // 1 ms
                mp.Stop(false);

                Assert.NotNull(mp);
                Assert.Equal("/Test.aspx", mp.Name);

                Assert.NotNull(mp.Root);
                Assert.False(mp.Root.HasChildren);
            }
        }
コード例 #3
0
ファイル: BaseTest.cs プロジェクト: wangchengqun/dotnet
        /// <summary>
        /// Returns a profiler for <paramref name="url"/>. Only child steps will take any time,
        /// e.g. when <paramref name="childDepth"/> is 0, the resulting <see cref="MiniProfiler.DurationMilliseconds"/> will be zero.
        /// </summary>
        /// <param name="url">The uri of the request.</param>
        /// <param name="childDepth">number of levels of child steps underneath result's <see cref="MiniProfiler.Root"/></param>
        /// <param name="stepsEachTakeMilliseconds">Amount of time each step will "do work for" in each step</param>
        /// <returns>The generated <see cref="MiniProfiler"/>.</returns>
        public async Task <MiniProfiler> GetProfilerAsync(
            string url     = DefaultRequestUrl,
            int childDepth = 0,
            int stepsEachTakeMilliseconds = StepTimeMilliseconds)
        {
            // TODO: Consolidate with above, maybe some out params
            MiniProfiler result   = null;
            Action       step     = null;
            var          curDepth = 0;

            // recursively add child steps
            step = () =>
            {
                if (curDepth++ < childDepth)
                {
                    using (result.Step("Depth " + curDepth))
                    {
                        result.Increment(stepsEachTakeMilliseconds);
                        step();
                    }
                }
            };

            using (GetRequest(url, startAndStopProfiler: false))
            {
                result = Options.StartProfiler();
                step();

                if (_testStorage != null)
                {
                    result.Storage = _testStorage;
                }

                await result.StopAsync().ConfigureAwait(false);
            }

            return(result);
        }
コード例 #4
0
ファイル: BaseTest.cs プロジェクト: wangchengqun/dotnet
        /// <summary>
        /// Returns a profiler for <paramref name="url"/>. Only child steps will take any time,
        /// e.g. when <paramref name="childDepth"/> is 0, the resulting <see cref="MiniProfiler.DurationMilliseconds"/> will be zero.
        /// </summary>
        /// <param name="url">The uri of the request.</param>
        /// <param name="childDepth">number of levels of child steps underneath result's <see cref="MiniProfiler.Root"/>.</param>
        /// <param name="stepsEachTakeMilliseconds">Amount of time each step will "do work for" in each step.</param>
        /// <returns>The generated <see cref="MiniProfiler"/>.</returns>
        public MiniProfiler GetProfiler(
            string url     = DefaultRequestUrl,
            int childDepth = 0,
            int stepsEachTakeMilliseconds = StepTimeMilliseconds)
        {
            MiniProfiler result   = null;
            Action       step     = null;
            var          curDepth = 0;

            // recursively add child steps
            step = () =>
            {
                if (curDepth++ < childDepth)
                {
                    using (result.Step("Depth " + curDepth))
                    {
                        result.Increment(stepsEachTakeMilliseconds);
                        step();
                    }
                }
            };

            using (GetRequest(url, startAndStopProfiler: false))
            {
                result = Options.StartProfiler(url);
                step();

                if (_testStorage != null)
                {
                    result.Storage = _testStorage;
                }

                result.Stop();
            }

            return(result);
        }