Beispiel #1
0
            public void Dispose()
            {
                _queryTimer.Stop();

                // when the request is finished it will dispose the activity scope and
                // this is when we print the parsed query.
                var variables   = _context.Variables;
                var queryString = _context.Document;

                string htmlText;

                using (MiniProfiler.Current.Ignore()) // this does not seem to ignore as documented
                {
                    htmlText = CreateHtmlFromDocument(queryString, variables, _queryTimer);
                }

                _miniProfiler?.AddCustomLink(htmlText, "#");
                _miniProfiler?.Stop();
            }
Beispiel #2
0
 protected void Application_EndRequest()
 {
     MiniProfiler.Stop(); // Be sure to stop the profiler!
 }
Beispiel #3
0
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     Current.DisposeDB();
     MiniProfiler.Stop();
 }
Beispiel #4
0
        public async Task Step_WithParallelTasks_RealTime()
        {
            var profiler = MiniProfiler.Start("root");

            profiler.Stopwatch = StopwatchWrapper.StartNew();

            Timing timing10 = null,
                   timing11 = null,
                   timing20 = null,
                   timing21 = null,
                   timing30 = null,
                   timing31 = null;

            // Act

            // Add 100ms to root
            await Task.Delay(100).ConfigureAwait(false);

            // Start tasks in parallel
            var whenAllTask = Task.WhenAll(
                Task.Run(async() =>
            {
                // timing10: 100 + 100 = 200 ms
                using (timing10 = profiler.Step("step1.0 (Task.Run)"))
                {
                    await Task.Delay(100).ConfigureAwait(false);
                    await Task.Run(async() =>
                    {
                        using (timing11 = profiler.Step("step1.1 (Task.Run)"))
                        {
                            await Task.Delay(100).ConfigureAwait(false);
                        }
                    }).ConfigureAwait(false);
                }
            }),
                Task.Factory.StartNew(async() =>
            {
                // timing20: 200 + 100 = 300 ms
                using (timing20 = profiler.Step("step2.0 (Task.Factory.StartNew)"))
                {
                    await Task.Delay(200).ConfigureAwait(false);
                    await Task.Run(async() =>
                    {
                        using (timing21 = profiler.Step("step2.1 (Task.Run)"))
                        {
                            await Task.Delay(100).ConfigureAwait(false);
                        }
                    }).ConfigureAwait(false);
                }
                // Important to Unwrap() when using the not-for-mortals StartNew()
            }).Unwrap(),
                Task.Factory.StartNew(async() =>
            {
                // timing30: 300 + 100 = 400 ms
                using (timing30 = profiler.Step("step3.0 (Task.Factory.StartNew:LongRunning)"))
                {
                    await Task.Delay(300).ConfigureAwait(false);
                    await Task.Run(async() =>
                    {
                        using (timing31 = profiler.Step("step3.1 (Task.Run)"))
                        {
                            await Task.Delay(100).ConfigureAwait(false);
                        }
                    }).ConfigureAwait(false);
                }
                // Important to Unwrap() when using the not-for-mortals StartNew()
            }, TaskCreationOptions.LongRunning).Unwrap()
                );

            await whenAllTask;

            MiniProfiler.Stop();

            // Assert
            Console.WriteLine(profiler.RenderPlainText());

            // 100ms + longest running task (step3.0 with 300 + 100 ms) = 500ms
            AssertNear(500, profiler.DurationMilliseconds, 50);

            // Parent durations are sum of itself and children
            AssertNear(200, timing10.DurationMilliseconds, 50);
            AssertNear(100, timing11.DurationMilliseconds, 50);

            AssertNear(300, timing20.DurationMilliseconds, 50);
            AssertNear(100, timing21.DurationMilliseconds, 50);

            AssertNear(400, timing30.DurationMilliseconds, 50);
            AssertNear(100, timing31.DurationMilliseconds, 50);
        }
Beispiel #5
0
        public async Task Step_WithParallelTasks_SimulatedTime()
        {
            var profiler = MiniProfiler.Start("root");

            var    waiters = new ConcurrentBag <CountdownEvent>();
            Timing timing10 = null, timing11 = null, timing20 = null, timing21 = null, timing30 = null, timing31 = null;

            // Add 1ms to root
            Increment();

            // Start tasks in parallel
            var whenAllTask = Task.WhenAll(
                Task.Run(async() =>
            {
                // timing10: 1 + 1 = 2 ms
                using (timing10 = profiler.Step("step1.0 (Task.Run)"))
                {
                    var ce = new CountdownEvent(1);
                    waiters.Add(ce);
                    ce.Wait();

                    await Task.Run(() =>
                    {
                        using (timing11 = profiler.Step("step1.1 (Task.Run)"))
                        {
                            var ce2 = new CountdownEvent(1);
                            waiters.Add(ce2);
                            ce2.Wait();
                        }
                    }).ConfigureAwait(false);
                }
            }),
                Task.Factory.StartNew(async() =>
            {
                // timing20: 2 + 1 = 2 ms
                using (timing20 = profiler.Step("step2.0 (Task.Factory.StartNew)"))
                {
                    var ce = new CountdownEvent(2);
                    waiters.Add(ce);
                    ce.Wait();

                    await Task.Run(() =>
                    {
                        using (timing21 = profiler.Step("step2.1 (Task.Run)"))
                        {
                            var ce2 = new CountdownEvent(1);
                            waiters.Add(ce2);
                            ce2.Wait();
                        }
                    }).ConfigureAwait(false);
                }
            }),
                Task.Factory.StartNew(async() =>
            {
                // timing20: 3 + 1 = 2 ms
                using (timing30 = profiler.Step("step3.0 (Task.Factory.StartNew:LongRunning)"))
                {
                    var ce = new CountdownEvent(3);
                    waiters.Add(ce);
                    ce.Wait();

                    await Task.Run(() =>
                    {
                        using (timing31 = profiler.Step("step3.1 (Task.Run)"))
                        {
                            var ce2 = new CountdownEvent(1);
                            waiters.Add(ce2);
                            ce2.Wait();
                        }
                    }).ConfigureAwait(false);
                }
            }, TaskCreationOptions.LongRunning)
                );

            Func <List <CountdownEvent>, bool> hasPendingTasks =
                handlers2 => (handlers2.Count == 0) || handlers2.Any(y => !y.IsSet);

            // TODO Make this a thread safe signaling lock step to avoid sleeping
            // Wait for tasks to run and call their Step() methods
            Thread.Sleep(50);

            List <CountdownEvent> handlers;

            while (hasPendingTasks(handlers = waiters.ToList()))
            {
                Increment();
                handlers.ForEach(x =>
                {
                    if (!x.IsSet)
                    {
                        x.Signal();
                    }
                });

                // TODO Make this a thread safe signaling lock step to avoid sleeping
                // Wait for sub-tasks to run and call their Step() methods
                Thread.Sleep(50);
            }

            await whenAllTask;

            MiniProfiler.Stop();

            // Assert
            Console.WriteLine(profiler.RenderPlainText());

            // 1ms added to root
            AssertNear(5, profiler.DurationMilliseconds);

            // Parent durations are sum of itself and children
            AssertNear(2, timing10.DurationMilliseconds);
            AssertNear(1, timing11.DurationMilliseconds);

            AssertNear(3, timing20.DurationMilliseconds);
            AssertNear(1, timing21.DurationMilliseconds);

            AssertNear(4, timing30.DurationMilliseconds);
            AssertNear(1, timing31.DurationMilliseconds);
        }
Beispiel #6
0
 public void StopBoot() => _startupProfiler?.Stop();
Beispiel #7
0
 protected void Application_EndRequest()
 {
     MiniProfiler.Stop();
 }
Beispiel #8
0
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     MiniProfiler.Stop();
 }
Beispiel #9
0
        public void InsertTest(string connectionName, string databaseName, string schemaName)
        {
            var options = new StorageOptions(new ConnectionStrings().Get(connectionName), databaseName: databaseName, schemaName: schemaName);
            //var options = new StorageOptions(new ConnectionStrings().Get("XtricateTestSqlLocalDb"), databaseName: databaseName, schemaName: "StorageTests");
            //var connectionFactory = new SqlLocalDbConnectionFactory();
            var connectionFactory = new SqlConnectionFactory();
            var indexMap          = TestDocumentIndexMap;
            var storage           = new DocStorage <TestDocument>(connectionFactory, options, new SqlBuilder(),
                                                                  new JsonNetSerializer(), new Md5Hasher(), indexMap);

            MiniProfiler.Start();
            var mp = MiniProfiler.Current;

            storage.Reset();
            var preCount = storage.Count(new[] { "en-US" });

            Log.Debug($"pre count: {preCount}");

            var key = DateTime.Now.Epoch() + new Random().Next(10000, 99999);

            for (var i = 1; i < 5; i++)
            {
                Log.Debug($"+{i}");
                using (mp.Step("insert " + i))
                {
                    var doc1 = new Fixture().Create <TestDocument>();
                    //doc1.Name = "Routing wide joints (≥ 4 mm, e.g. between natural stone tiles)öoäa®r¼4èe";
                    doc1.Name = "NEU!Kreissägeblätter Expert for Steel NOUVEAU˜!Lames de scies circulaires Expert for Steel °˛˝˙°ˆˇ! ˘  Expert for Steel";

                    var result1 = storage.Upsert("key1", doc1, new[] { "en-US" });
                    //    Assert.That(result1, Is.EqualTo(StorageAction.Updated));
                    //}
                    //using (mp.Step("upsert string"))
                    //{
                    var result2 = storage.Upsert(Guid.NewGuid(), new Fixture().Create <TestDocument>(), new[] { "en-US" });
                    //Assert.That(result2, Is.EqualTo(StorageAction.Inserted));
                    //}
                    //using (mp.Step("upsert int"))
                    //{
                    var result3 = storage.Upsert(key + i, new Fixture().Create <TestDocument>(), new[] { "en-US" });
                    //Assert.That(result3, Is.EqualTo(StorageAction.Inserted));
                }
            }

            for (var i = 1; i <= 5; i++)
            {
                using (mp.Step("load " + i))
                {
                    var result = storage.LoadValues(new[] { "en-US" }).Take(100);
                    //Assert.That(result, Is.Not.Null);
                    //Assert.That(result, Is.Not.Empty);
                    Log.Debug($"loaded count: {result.Count()}");
                    Log.Debug($"first: {result.FirstOrDefault().Id}");
                    //result.ForEach(r => Trace.Write(r.Id));
                    //result.ForEach(r => Assert.That(r, Is.Not.Null));
                    result.ForEach(r => Log.Debug(r.Name));
                }
            }

            using (mp.Step("post count"))
            {
                var postCount = storage.Count(new[] { "en-US" });
                Log.Debug($"post count: {postCount}");
                //Assert.That(storage.Count(), Is.GreaterThan(preCount));
            }
            Log.Debug($"trace: {mp.RenderPlainText()}");
            MiniProfiler.Stop();
        }
Beispiel #10
0
        public void FindTest(string connectionName, string databaseName, string schemaName)
        {
            var options = new StorageOptions(new ConnectionStrings().Get(connectionName), databaseName: databaseName, schemaName: schemaName)
            {
                BufferedLoad = false
            };
            var connectionFactory = new SqlConnectionFactory();
            var indexMap          = TestDocumentIndexMap;
            var storage           = new DocStorage <TestDocument>(connectionFactory, options, new SqlBuilder(),
                                                                  new JsonNetSerializer(), new Md5Hasher(), indexMap);

            MiniProfiler.Start();
            var mp = MiniProfiler.Current;

            Log.Debug($"pre count: {storage.Count(new[] {"en-US"})}");
            var key  = DateTime.Now.Epoch() + new Random().Next(10000, 99999) + "c";
            var name = "NEWNAME" + key;
            var sku  = "";

            using (mp.Step("insert "))
            {
                var document = new Fixture().Create <TestDocument>();
                document.Name = name;
                sku           = document.Skus.FirstOrDefault().Sku;
                dynamic dDocument = document;
                dDocument.Dyn = "dynamic property";
                var result1 = storage.Upsert(key, document, new[] { "en-US" });
                Assert.That(result1, Is.EqualTo(StorageAction.Inserted));
                Log.Debug("newDoc: " + document.Name);
            }

            var count = storage.Count(new[] { "en-US" });
            var keys  = storage.LoadKeys(new[] { "en-US" }).ToList();

            Assert.That(keys, Is.Not.Null);
            Assert.That(keys.Any(), Is.True);
            Assert.That(count, Is.EqualTo(keys.Count()));


            5.Times(i =>
            {
                using (mp.Step("find no non-existing by SKU criteria/tags " + i))
                {
                    var criterias = new List <Criteria> {
                        new Criteria("sku", CriteriaOperator.Eq, "XYZ_SKU")
                    };
                    var result = storage.LoadValues(new[] { "en-US" }, criterias).ToList();
                    Assert.That(result, Is.Null.Or.Empty);
                }
            });
            5.Times(i =>
            {
                using (mp.Step("find by KEY/tags " + i))
                {
                    var result = storage.LoadValues(key, new[] { "en-US" }).ToList();
                    Assert.That(result, Is.Not.Null);
                    Assert.That(result.Any(), Is.True);
                    Assert.That(result.FirstOrDefault().Name, Is.EqualTo(name));
                }
            });

            5.Times(i =>
            {
                using (mp.Step("find by NAME criteria/tags " + i))
                {
                    var criterias = new List <Criteria> {
                        new Criteria("name", CriteriaOperator.Eq, name)
                    };
                    var result = storage.LoadValues(new[] { "en-US" }, criterias).ToList();
                    Assert.That(result, Is.Not.Null);
                    Assert.That(result.Any(), Is.True);
                    Assert.That(result.FirstOrDefault().Name, Is.EqualTo(name));
                }
            });

            5.Times(i =>
            {
                using (mp.Step("find by NAME with sql delimiter character " + i))
                {
                    var criterias = new List <Criteria> {
                        new Criteria("name", CriteriaOperator.Eq, "'")
                    };
                    var result = storage.LoadValues(new[] { "en-US" }, criterias).ToList();
                    Assert.That(result, Is.Null.Or.Empty);
                }
            });

            5.Times(i =>
            {
                using (mp.Step("find by SKU criteria/tags " + i))
                {
                    var criterias = new List <Criteria> {
                        new Criteria("sku", CriteriaOperator.Contains, sku)
                    };
                    var result = storage.LoadValues(new[] { "en-US" }, criterias).ToList();
                    Assert.That(result, Is.Not.Null);
                    Assert.That(result.Any(), Is.True);
                    Assert.That(result.FirstOrDefault().Skus.FirstOrDefault().Sku, Is.EqualTo(sku));
                }
            });
            5.Times(i =>
            {
                using (mp.Step("find by timestamp " + i))
                {
                    var result = storage.LoadValues(new[] { "en-US" }, fromDateTime: DateTime.Now.AddMonths(-1), tillDateTime: DateTime.Now).ToList();
                    Assert.That(result, Is.Not.Null);
                    Assert.That(result.Any(), Is.True);
                }
            });

            Log.Debug($"trace: {mp.RenderPlainText()}");
            MiniProfiler.Stop();
        }
Beispiel #11
0
 protected void Application_EndRequest(object sender, EventArgs e)
 {
     HttpContextLifecycle.DisposeAndClearAll();
     MiniProfiler.Stop();
 }
Beispiel #12
0
 void EventsManager_EndRequest(object sender, EventArgs e)
 {
     MiniProfiler.Stop();
 }
 internal void StopProfiler()
 {
     MiniProfiler.Stop(false);
 }
Beispiel #14
0
        public static async Task <ActionResult> SparkSvgAll <T>(Func <Node, Task <List <T> > > getPoints, Func <Node, List <T>, long> getMax, Func <T, double> getVal) where T : IGraphPoint
        {
            MiniProfiler.Stop(true);
            const int width = SparkPoints;

            var nodes         = DashboardModule.AllNodes;
            var overallHeight = nodes.Count * SparkHeight;

            long nowEpoch   = DateTime.UtcNow.ToEpochTime(),
                 startEpoch = SparkStart.ToEpochTime();
            var range       = (nowEpoch - startEpoch) / (float)width;

            var sb = StringBuilderCache.Get()
                     .AppendFormat("<svg version=\"1.1\" baseProfile=\"full\" width=\"{0}\" height=\"{1}\" xmlns=\"http://www.w3.org/2000/svg\" preserveAspectRatio=\"none\">\n", width.ToString(), overallHeight.ToString())
                     .AppendLine("\t<style>")
                     .AppendFormat("\t\tline {{ stroke:{0}; stroke-width:1 }}\n", AxisColor)
                     .AppendFormat("\t\tpath {{ fill:{0}; stroke:none; }}\n", Color)
                     .AppendLine("\t</style>");

            var pointsLookup = new ConcurrentDictionary <string, List <T> >();
            var maxLookup    = new ConcurrentDictionary <string, long>();
            var lookups      = new List <Task>(nodes.Count);

            foreach (var node in nodes)
            {
                lookups.Add(getPoints(node).ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        pointsLookup[node.Id] = t.Result;
                        maxLookup[node.Id]    = getMax(node, t.Result);
                    }
                }));
            }
            await Task.WhenAll(lookups).ConfigureAwait(false);

            int currentYTop = 0;

            foreach (var pl in pointsLookup)
            {
                sb.AppendFormat("\t<view id=\"{0}\" viewBox=\"0 {1} {2} {3}\" />\n", pl.Key, currentYTop, width, SparkHeight)
                .AppendFormat("\t<g transform=\"translate(0, {0})\">\n", currentYTop)
                .AppendFormat("\t\t<line x1=\"0\" y1=\"{0}\" x2=\"{1}\" y2=\"{0}\" />\n", SparkHeight.ToString(), width.ToString())
                .AppendFormat("\t\t<path d=\"M0 {0} L", SparkHeight);

                var  first   = true;
                long divisor = maxLookup[pl.Key] / SparkHeight;
                foreach (var p in pl.Value)
                {
                    var pos = (p.DateEpoch - startEpoch) / range;
                    if (first && pos > 0)
                    {
                        // TODO: Indicate a missing, ungraphed time portion?
                        sb.Append((pos - 1).ToString("f1", CultureInfo.InvariantCulture))
                        .Append(" ")
                        .Append(SparkHeight)
                        .Append(" ");
                        first = false;
                    }
                    sb.Append(pos.ToString("f1", CultureInfo.InvariantCulture)).Append(" ")
                    .Append((SparkHeight - (getVal(p) / divisor)).ToString("f1", CultureInfo.InvariantCulture)).Append(" ");
                }
                sb.Append(width)
                .Append(" ")
                .Append(SparkHeight)
                .Append(@" z""/>\n")
                .Append("\t</g>\n");

                currentYTop += SparkHeight;
            }

            sb.Append("</svg>");
            var bytes = Encoding.UTF8.GetBytes(sb.ToStringRecycle());

            return(new FileContentResult(bytes, "image/svg+xml"));
        }
        protected void Application_EndRequest()
        {
#if DEBUG
            MiniProfiler.Stop();
#endif
        }
Beispiel #16
0
 /// <summary>
 /// Stops the profiler.
 /// </summary>
 /// <param name="logger">The logger.</param>
 public static void StopProfiler(this ILog logger)
 {
     MiniProfiler.Stop();
 }
 private void context_EndRequest(object sender, EventArgs eventArgs)
 {
     MiniProfiler.Stop();
 }
Beispiel #18
0
 /// <summary>
 /// Start the profiler
 /// </summary>
 /// <remarks>
 /// set discardResults to false when you want to abandon all profiling, this is useful for
 /// when someone is not authenticated or you want to clear the results based on some other mechanism.
 /// </remarks>
 public void Stop(bool discardResults = false)
 {
     MiniProfiler.Stop(discardResults);
 }
Beispiel #19
0
 protected void Application_EndRequest()
 {
     MiniProfiler.Stop(); //stop as early as you can, even earlier with MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
 }
Beispiel #20
0
        public string ServiceMethodThatIsNotProfiled()
        {
            MiniProfiler.Stop(true);

            return("Result");
        }
Beispiel #21
0
 public JsonResult Index()
 {
     MiniProfiler.Stop(true);
     return(Json("OK", JsonRequestBehavior.AllowGet));
 }