RT
一个程序,有一个页面运行起来很慢,想知道怎么统计这个页面的程序运行占用的时间,最好还有占用内存的统计方法
是有软件直接就可以统计,还是要在程序里加代码?
希望能说的越详细越好,因为我是菜鸟,谢谢!
在网上搜相关的资料,看到都是一些代码
有一个代码如下:想问下,这个代码怎么用呢?回答越详细越好!
//开始计时
DateTime stardt= DateTime.Now;//执行代码段
/**/
//统计所运行的时间
TimeSpan ts= DateTime.Now.Subtract( stardt);
double count= ts.TotalMilliseconds;
一个程序,有一个页面运行起来很慢,想知道怎么统计这个页面的程序运行占用的时间,最好还有占用内存的统计方法
是有软件直接就可以统计,还是要在程序里加代码?
希望能说的越详细越好,因为我是菜鸟,谢谢!
在网上搜相关的资料,看到都是一些代码
有一个代码如下:想问下,这个代码怎么用呢?回答越详细越好!
//开始计时
DateTime stardt= DateTime.Now;//执行代码段
/**/
//统计所运行的时间
TimeSpan ts= DateTime.Now.Subtract( stardt);
double count= ts.TotalMilliseconds;
sw.start();
....Your Operation...
sw.stop();
sw.TimeSpan();.....
楼主做的几层的应用?
可以用SQL Profile检查一下DB Call.
还有就是是否Call中间层服务器太多了,这个东西可以用Wair Shark这样的通信捕捉工具来检查~
这个代码怎么用呢?放到哪里?
是用的treeview做的循环,输入的结点越多运行越慢,看资源管理器里,IE占用的内存比较多
Global.asax.cs中:
protected void Application_BeginRequest(Object sender, EventArgs e) {
Application["StartTime"] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime = (System.DateTime)Application["StartTime"];
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan ts = endTime - startTime;
Response.Write("<table border=0' width='100%'><tr><td align='center' width='100%'><img border='0' src='Css/Image/bg1.gif'></td></tr><tr><td align='center' width='100%'><font size=1 color='Silver'>页面执行耗时:" + ts + "秒<font></td></tr></table>");
}
public class BasePage : Page
{
protected string tracInfo = string.Empty;
#region 计算页面加载时间 protected override void OnPreInit(EventArgs e)
{
dtExecuteTime = DateTime.Now;
base.OnPreInit(e);
} protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e); ts = DateTime.Now - dtExecuteTime;
tracInfo = ts.TotalMilliseconds.ToString();
} #endregion}
ServerOS = Environment.OSVersion.ToString(); //操作系统:
CpuSum = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"); //CPU个数:
CpuType = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER"); //CPU类型:
ServerSoft = Request.ServerVariables["SERVER_SOFTWARE"]; //信息服务软件:
MachineName = Server.MachineName; //服务器名
ServerName = Request.ServerVariables["SERVER_NAME"]; //服务器域名
ServerPath = Request.ServerVariables["APPL_PHYSICAL_PATH"]; //虚拟服务绝对路径
ServerNet = ".NET CLR " + Environment.Version.ToString(); //DotNET 版本
ServerArea = (DateTime.Now - DateTime.UtcNow).TotalHours > 0 ? "+" + (DateTime.Now - DateTime.UtcNow).TotalHours.ToString() : (DateTime.Now - DateTime.UtcNow).TotalHours.ToString(); //服务器时区
ServerTimeOut = Server.ScriptTimeout.ToString(); //脚本超时时间
ServerStart = ((Double)System.Environment.TickCount / 3600000).ToString("N2"); //开机运行时长
PrStart = GetPrStart(); //进程开始时间
AspNetN = GetAspNetN(); //AspNet 内存占用
AspNetCpu = GetAspNetCpu(); //AspNet CPU时间
ServerSessions = Session.Contents.Count.ToString(); / ssion总数
ServerApp = Application.Contents.Count.ToString(); //Application总数
ServerCache = Cache.Count.ToString(); //应用程序缓存总数
ServerAppN = GetServerAppN(); //应用程序占用内存
ServerFso = Check("Scripting.FileSystemObject"); //FSO 文本文件读写
ServerTimeOut = Server.ScriptTimeout.ToString() + "毫秒"; //本页执行时间