Reputation: 27713
I have an Action as follows that I am trying to track down the execution time in order to eliminate the delay:
public JsonResult DoSomething(IncidentReportSearchCriteria searchCriteria)
{
//search database with searchCriteria
//get the data, do something with it
//return success in JSON format
return Json(new { success = true });
}
Are there any tools in VS2010 to find out how long it takes for Action DoSomething to finish executing? In other words, just before the last }
I write the times to the log, but there is a delay after writing the end time to the log and }
. Bandwidth is not the issue since I am not returning much as you can see.
Upvotes: 0
Views: 185
Reputation: 32758
You can create an action filter to measure the executing time.
public class ProfileAttribute: ActionFilterAttribute
{
private StopWatch timer;
public override void OnActionExecuting(ActionExceutingContext filterContext)
{
timer = StopWatch.StartNew();
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
timer.Stop();
filterContext.HttpContext.Response.Write("Action method elapsed time: " + timer.Elapsed.TotalMilliSeconds.ToString());
}
}
[Profile]
public JsonResult DoSomething(IncidentReportSearchCriteria searchCriteria)
{
}
Upvotes: 1