Click here to Skip to main content
13,090,930 members (43,482 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 3 May 2010

Simple MVC profiler

, 3 May 2010
Rate this:
Please Sign up or sign in to vote.
Download source files - 323 Kb Introduction. Background Using the code Screenshot About the Author Introduction. Frequently we need to find bottlenecks in MVC View Pages, but there is no proper free tool ,specially when we need to find problem in View...


Frequently we need to find bottlenecks in MVC View Pages, but there is no proper free tool ,
specially when we need to find problem in View markup full of C# Dynamic anonymous functions.
I decided to write simple profiler , which can be used
to perform simple performance monitor tasks.This is no comprehended and powerful tool,
but is very light and simple to use.


To check the performance of MVC Application we can just put points (Calls of special function) in our code,
both in c# code and MVC ViewPage markup as Dynamic anonymous function.
Profiler calculates period passed between function calls ,
and finally outputs all the information in a table.You can easily find slow functions of Your code.

Using the code

An Idea is very simple.If we need to check the performance we put an AddEvent function call of static Profiler class.
It stores each point at List<profilerevent></profilerevent> as an instance of ProfilerEvent class and
when we want to output profiler results ,
we put call to ProfilerEvents static function in proper place of ViewPage markup.

AddEvent function has two parameters: first is function Name ,and second is comment.Both names are optional.
I use c# 4.0 optional parameters feature to fulfill this function.In MVC View Page Dynamic code blocks we should use distinct name ,
but in ordinary named functions we can omit this parameter ,
because Profiler can extract the function name automatically.

Below are two examples of profile using.First is AddEvent function call from Action
and the second is call from Viewpage markup as Dynamic code block.First point is placed at Action function ,
which happened before Dynamic code call ,so we can trace how much time passed between Action call and Dynamic code block.

 public ActionResult Index()
    //Here we place point in MVC Action c# code:
    SampleClass sc = new SampleClass();
    return View(sc.SomeSlowCalculations());


The screenshot below shows the result of using the Profiler

About the Author

Software developer from Tbilisi ,Georgia. Coding in c# from 2002 ,before c# I worked with Delphi.Hope this tip will help You.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 4 May 2010
Article Copyright 2010 by Alex Onezashvili
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid