コード例 #1
0
        public async Task <ActionResult> CallWebApi()
        {
            string result;

            using (MiniProfiler.StepStatic("Mvc: Calling External API"))
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:5462/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "test");

                    // New code:
                    HttpResponseMessage response = await client.SendAsync(request);

                    MiniProfiler.Current.TryAddMiniProfilerResultsFromHeader(response);

                    if (response.IsSuccessStatusCode)
                    {
                        result = await response.Content.ReadAsStringAsync();
                    }
                    else
                    {
                        result = "fail";
                    }
                }
            }


            return(View("Index", (object)result));
        }
コード例 #2
0
        public async Task <string> Get()
        {
            using (MiniProfiler.StepStatic("WebApi: 1.0 Short Action"))
            {
                using (MiniProfiler.Current.CustomTiming("sql", Query))
                {
                    await Task.Delay(50);
                }

                using (MiniProfiler.Current.CustomTiming("redis", "Redis_Get (Key: Key1)"))
                {
                    await Task.Delay(20);
                }

                using (MiniProfiler.StepStatic("WebApi: 1.1 Inner Action"))
                {
                    await Task.Delay(20);
                }

                using (MiniProfiler.StepStatic("WebApi: 1.2 Another Inner Action"))
                {
                    await Task.Delay(20);
                }
            }


            using (MiniProfiler.StepStatic("WebApi: 2.0 Long Action"))
            {
                using (MiniProfiler.Current.CustomTiming("sql", Query2))
                {
                    await Task.Delay(500);
                }

                using (MiniProfiler.Current.CustomTiming("redis", "Redis_Set (Key: Key2)"))
                {
                    await Task.Delay(200);
                }

                using (MiniProfiler.StepStatic("WebApi: 2.1 InnerAction"))
                {
                    await Task.Delay(100);
                }

                using (MiniProfiler.StepStatic("WebApi: 2.2 Another InnerAction"))
                {
                    await Task.Delay(100);
                }
            }

            return("Check out all the MiniProfiler data from this API call");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .AddMiniProfiler()
                         .MinimumLevel.Verbose()
                         .WriteTo.Seq("http://localhost:5341/")
                         .WriteTo.RollingFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs\\log-{Date}.txt"))
                         .CreateLogger();

            MiniProfilerLog.SetUpSerilog();

            MiniProfiler.Start();
            MiniProfiler.StepStatic("SomeStep");
            MiniProfiler.Stop();

            Log.Logger.Debug("Some");


            Log.CloseAndFlush();
        }
コード例 #4
0
        public ActionResult Create(Snippet snippet)
        {
            if (ModelState.IsValid)
            {
                snippet.CreatedAt = DateTime.UtcNow;

                using (MiniProfiler.StepStatic("Web service sync call"))
                {
                    snippet.HighlightedSource = HighlightSource(snippet.Source);
                    snippet.HighlightedAt     = DateTime.UtcNow;
                }

                _db.Snippets.Add(snippet);
                _db.SaveChanges();

                return(RedirectToAction("Snippet", new { id = snippet.Id }));
            }

            return(View("Create", snippet));
        }
コード例 #5
0
 public IDictionary <string, T> FindByKeys <T>(IEnumerable <string> keys) where T : class
 {
     using (MiniProfiler.StepStatic("DictionaryCache_FindByKeys_" + keys.Count() + "_Keys"))
     {
         var values = new Dictionary <string, T>();
         foreach (string key in keys)
         {
             T value = null;
             if (TryGet(key, ref value))
             {
                 values.Add(key, value);
             }
             else
             {
                 values.Add(key, null);
             }
         }
         return(values);
     }
 }
コード例 #6
0
        private static void DoStuff(DbProviderFactory factory)
        {
            // This adapter is created in another layer which knows nothing about MiniProfiler.
            var adapter = factory.CreateDataAdapter();

            MiniProfiler.Start();

            using (MiniProfiler.StepStatic("Phase 2"))
            {
                // Somehow a profiled command ends up in adapter.SelectCommand
                var command = factory.CreateCommand();

                /* Even though type of SelectCommand is DbCommand, an SqlDataAdapter expects a SqlCommand instead of a DbCommand, voiding Liskov Substitution Principle.
                 * An unhandled exception of type 'System.InvalidCastException' occurred in System.Data.dll
                 * Additional information: Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbCommand' to type 'System.Data.SqlClient.SqlCommand'.
                 */
                adapter.SelectCommand = command;
            }

            MiniProfiler.Stop();
        }
コード例 #7
0
        public async Task <ActionResult> Index()
        {
            var person = new Person
            {
                Id        = "1",
                Firstname = "Martijn",
                Lastname  = "Laarman"
            };

            _client.Index(person);
            _client.IndexMany(new List <Person> {
                person, person, person
            });
            _client.Get <Person>("1");
            _client.DeleteIndex("not-existing-index");
            _client.ClusterHealth();

            using (MiniProfiler.StepStatic("Async"))
            {
                await _client.IndexAsync(person);

                using (MiniProfiler.StepStatic("Async inner 1"))
                {
                    await _client.IndexAsync(new List <Person> {
                        person, person, person
                    });
                }
                using (MiniProfiler.StepStatic("Async inner 2"))
                {
                    await _client.IndexManyAsync(new List <Person> {
                        person, person, person
                    });

                    await _client.GetAsync <Person>("1");
                }
            }

            return(View());
        }
コード例 #8
0
 private static void StartOneStep()
 {
     MiniProfiler.Start();
     MiniProfiler.StepStatic("Step");
     MiniProfiler.Stop();
 }
コード例 #9
0
 /// <summary>
 /// Steps for profiler
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="name">The name.</param>
 /// <returns></returns>
 public static IDisposable Step(this ILog logger, string name)
 {
     return(MiniProfiler.StepStatic(name));
 }
コード例 #10
0
 protected override void OnResultExecuting(ResultExecutingContext filterContext)
 {
     this.resultExecuting = MiniProfiler.StepStatic("Result Executing");
     base.OnResultExecuting(filterContext);
 }
コード例 #11
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     this.actionExecuting = MiniProfiler.StepStatic("Action Executing");
     base.OnActionExecuting(filterContext);
 }