15
私は、サーバーがページを生成するのにかかった時間を追跡する方法を探しています。私はこれを追跡するためにトレースを使用することができますが、私はページごとにこれを表示する方法が必要です。ページの生成時間 - ASP.Net MVC
そのASP.Net MVC 2
私は、サーバーがページを生成するのにかかった時間を追跡する方法を探しています。私はこれを追跡するためにトレースを使用することができますが、私はページごとにこれを表示する方法が必要です。ページの生成時間 - ASP.Net MVC
そのASP.Net MVC 2
のようにマスターページにそれを置きます EDIT:完全な実装を追加イオン
public class PerformanceMonitorModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += delegate(object sender, EventArgs e)
{
//Set Page Timer Star
HttpContext requestContext = ((HttpApplication)sender).Context;
Stopwatch timer = new Stopwatch();
requestContext.Items["Timer"] = timer;
timer.Start();
};
context.PostRequestHandlerExecute += delegate(object sender, EventArgs e)
{
HttpContext httpContext = ((HttpApplication)sender).Context;
HttpResponse response = httpContext.Response;
Stopwatch timer = (Stopwatch)httpContext.Items["Timer"];
timer.Stop();
// Don't interfere with non-HTML responses
if (response.ContentType == "text/html")
{
double seconds = (double)timer.ElapsedTicks/Stopwatch.Frequency;
string result_time = string.Format("{0:F4} sec ", seconds);
RenderQueriesToResponse(response,result_time);
}
};
}
void RenderQueriesToResponse(HttpResponse response, string result_time)
{
response.Write("<div style=\"margin: 5px; background-color: #FFFF00\"");
response.Write(string.Format("<b>Page Generated in "+ result_time));
response.Write("</div>");
}
public void Dispose() { /* Not needed */ }
}
あなたもそれにいくつかのスタイルを追加することができます
...
とセクションのHttpModules内のWebConfigで、あなたのモジュールを登録することを忘れないでください:
<add name="Name" type="namespace, dll"/>
完全なリファレンスについては、これについては確認してくださいPro ASP.NET MVCフレームワーク、Steven Sanderson - 第15章 - パフォーマンス、モニタリングページの生成時間。
EDIT:(@Pinoコメント) ここでは、私のプロジェクトのための例です:? alt text http://www.diarioplus.com/files/pictures/example_performance.JPG
ありがとうございます - これは私のページを壊す