Ejemplo n.º 1
0
        public async Task <ActionResult> Index()
        {
            ProfilingSession.Current.AddTag("index");

            using (ProfilingSession.Current.Step("Handle Request - /"))
            {
                Article[] articles;

                using (ProfilingSession.Current.Step(() => "Load Data"))
                {
                    articles = await dbContext.Articles.OrderByDescending(a => a.Id)
                               .Take(10)
                               .ToArrayAsync();
                }

                // WebTimingAsync() profiles the wrapped action as a web request timing
                var url = this.Request.Scheme + "://" + this.Request.Host + "/home/child";
                await ProfilingSession.Current.WebTimingAsync(url, async (correlationId) =>
                {
                    using (var httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Add(CoreProfilerMiddleware.XCorrelationId, correlationId);

                        var uri    = new Uri(url);
                        var result = await httpClient.GetStringAsync(uri);
                    }
                });

                // test profiling execute command asyncrhonously
                await dbContext.Database.ExecuteSqlCommandAsync("select * from Articles");

                var task1 = dbContext.FindAsync <Article>(100);
                var task2 = dbContext.FindAsync <Article>(101);

                await task1;
                await task2;

                using (ProfilingSession.Current.Step("Render View"))
                {
                    return(View());
                }
            }
        }