Code Monkey home page Code Monkey logo

devmentor.performancemonitoring's Introduction

DevMentor.PerformanceMonitoring

ASP.NET MVC Performance Monitoring Helpers

 [PerfMonitorActionFilterAttribute]
    public class HomeController : Controller
    {
        public class IndexViewModel
        {
            public DateTime Date { get; set; }
        }

        public async Task<ActionResult> Index()
        {
            IndexViewModel model = null;

            Session["date"] = DateTime.Now;
            using (var monitor = new PerfMonitor("MyUsing")) 
            {
                try
                {
                    var ctx = System.Web.HttpContext.Current;
                    var id = PerfMonitorContext.Current.Id;
                    var session = Session;
                    var task = Task.Run<IndexViewModel>(() =>
                    {
                        using (var mon = new PerfMonitor("CreateIndexViewModel"))
                        {
                            mon.Line.Id = id;
                            var result = new IndexViewModel();
                            result.Date = (DateTime)session["date"];
                            System.Threading.Thread.Sleep(1000);
                            return result;
                        }
                    });
                    await task.TimeoutAfter(500);
                    model = task.Result;
                }
                catch (TimeoutException ex)
                {
                    //Log.Warning("Timeout");
                    monitor.Line.Message = "TimeoutException "+ex.Message;
                }
            }
            return View(model);
        }

Output in c:\temp\perflog[dt].log

id dt GET / -532462766 666ms MyUsing - TimeoutException Timeout für den Vorgang wurde überschritten.
id dt GET /Home/Index 0 768ms PerfLogActionFilter - 
id dt METHOD HttpContext==null 0 1002ms CreateIndexViewModel - 

devmentor.performancemonitoring's People

Contributors

pmizel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.