// Author(s):
// Jackson Harper (jackson@ximian.com)
//
-// (C) 2004 Novell, Inc (http://www.novell.com)
+// (C) 2004-2009 Novell, Inc (http://www.novell.com)
//
//
using System;
using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
-#if NET_2_0
-using System.Collections.Generic;
-#endif
-
-namespace System.Web {
-
- class InfoTraceData
+namespace System.Web
+{
+ sealed class InfoTraceData
{
public string Category;
public string Message;
public string Exception;
public double TimeSinceFirst;
+ public double TimeSinceLast;
public bool IsWarning;
- public InfoTraceData (string category, string message, string exception, double timeSinceFirst, bool isWarning)
+ public InfoTraceData (string category, string message, string exception, double timeSinceFirst, double timeSinceLast, bool isWarning)
{
this.Category = category;
this.Message = message;
this.Exception = exception;
this.TimeSinceFirst = timeSinceFirst;
+ this.TimeSinceLast = timeSinceLast;
this.IsWarning = isWarning;
}
}
- class ControlTraceData
+ sealed class ControlTraceData
{
public string ControlId;
public Type Type;
public int RenderSize;
public int ViewstateSize;
public int Depth;
+ public int ControlstateSize;
- public ControlTraceData (string controlId, Type type, int renderSize, int viewstateSize, int depth)
+ public ControlTraceData (string controlId, Type type, int renderSize, int viewstateSize, int controlstateSize, int depth)
{
this.ControlId = controlId;
this.Type = type;
this.RenderSize = renderSize;
this.ViewstateSize = viewstateSize;
this.Depth = depth;
+ this.ControlstateSize = controlstateSize;
}
}
- class NameValueTraceData
+ sealed class NameValueTraceData
{
public string Name;
public string Value;
}
}
- internal class TraceData {
-
- private bool is_first_time;
- private DateTime first_time;
- private double prev_time;
-
-#if NET_2_0
- private Queue <InfoTraceData> info;
- private Queue <ControlTraceData> control_data;
- private Queue <NameValueTraceData> cookie_data;
- private Queue <NameValueTraceData> header_data;
- private Queue <NameValueTraceData> servervar_data;
-#else
- private Queue info;
- private Queue control_data;
- private Queue cookie_data;
- private Queue header_data;
- private Queue servervar_data;
- //private DataTable viewstate_data;
-#endif
-
- private string request_path;
- private string session_id;
- private DateTime request_time;
- private Encoding request_encoding;
- private Encoding response_encoding;
- private string request_type;
- private int status_code;
- private Page page;
+ sealed class TraceData
+ {
+ bool is_first_time;
+ DateTime first_time;
+ double prev_time;
+ Queue <InfoTraceData> info;
+ Queue <ControlTraceData> control_data;
+ Queue <NameValueTraceData> cookie_data;
+ Queue <NameValueTraceData> header_data;
+ Queue <NameValueTraceData> servervar_data;
+ Hashtable ctrl_cs;
+ string request_path;
+ string session_id;
+ DateTime request_time;
+ Encoding request_encoding;
+ Encoding response_encoding;
+ string request_type;
+ int status_code;
+ Page page;
+ TraceMode _traceMode = HttpRuntime.TraceManager.TraceMode;
public TraceData ()
{
-#if NET_2_0
info = new Queue <InfoTraceData> ();
control_data = new Queue <ControlTraceData> ();
cookie_data = new Queue <NameValueTraceData> ();
header_data = new Queue <NameValueTraceData> ();
servervar_data = new Queue <NameValueTraceData> ();
-#else
- info = new Queue ();
- control_data = new Queue ();
- cookie_data = new Queue ();
- header_data = new Queue ();
- servervar_data = new Queue ();
-#endif
/* TODO
viewstate_data = new DataTable ();
is_first_time = true;
}
+ public TraceMode TraceMode {
+ get { return _traceMode; }
+ set { _traceMode = value; }
+ }
+
public string RequestPath {
get { return request_path; }
set { request_path = value; }
public void Write (string category, string msg, Exception error, bool Warning)
{
double time;
+ double time_from_last;
if (is_first_time) {
time = 0;
+ time_from_last = 0;
+ prev_time = 0;
is_first_time = false;
first_time = DateTime.Now;
- } else
+ }
+ else {
time = (DateTime.Now - first_time).TotalSeconds;
+ time_from_last = time - prev_time;
+ prev_time = time;
+ }
info.Enqueue (
new InfoTraceData (category,
HtmlEncode (msg),
(error != null ? error.ToString () : null),
time,
+ time_from_last,
Warning));
}
return res.Replace (" ", " ");
}
- public void AddControlTree (Page page, Hashtable ctrl_vs, Hashtable sizes)
+ public void AddControlTree (Page page, Hashtable ctrl_vs, Hashtable ctrl_cs, Hashtable sizes)
{
this.page = page;
this.ctrl_vs = ctrl_vs;
this.sizes = sizes;
+ this.ctrl_cs = ctrl_cs;
AddControl (page, 0);
}
c.GetType (),
GetRenderSize (c),
GetViewStateSize (c, (ctrl_vs != null) ? ctrl_vs [c] : null),
+ GetViewStateSize (c, (ctrl_cs != null) ? ctrl_cs [c] : null),
control_pos));
if (c.HasControls ()) {
output.RenderEndTag ();
}
- private void RenderRequestDetails (HtmlTextWriter output)
+ void RenderRequestDetails (HtmlTextWriter output)
{
Table table = CreateTable ();
table.RenderControl (output);
}
- private void RenderTraceInfo (HtmlTextWriter output)
+ void RenderTraceInfo (HtmlTextWriter output)
{
Table table = CreateTable ();
table.Rows.Add (SubHeadRow ("Category", "Message", "From First(s)", "From Lasts(s)"));
int pos = 0;
-#if NET_2_0
- foreach (InfoTraceData i in info)
+ IEnumerable<InfoTraceData> enumerable = info;
+
+ if (TraceMode == TraceMode.SortByCategory) {
+ List<InfoTraceData> list = new List<InfoTraceData> (info);
+ list.Sort (delegate (InfoTraceData x, InfoTraceData y) { return String.Compare (x.Category, y.Category, StringComparison.Ordinal); });
+ enumerable = list;
+ }
+
+ foreach (InfoTraceData i in enumerable)
RenderTraceInfoRow (table, i, pos++);
-#else
- foreach (object o in info)
- RenderTraceInfoRow (table, o as InfoTraceData, pos++);
-#endif
table.RenderControl (output);
}
- private void RenderControlTree (HtmlTextWriter output)
+ void RenderControlTree (HtmlTextWriter output)
{
Table table = CreateTable ();
table.Rows.Add (AltRow ("Control Tree"));
table.Rows.Add (SubHeadRow ("Control Id", "Type",
"Render Size Bytes (including children)",
- String.Format ("View state Size (total: {0} bytes)(excluding children)",
- page_vs_size)));
+#if TARGET_J2EE
+ "ViewState Size (excluding children)"
+#else
+ String.Format ("ViewState Size (total: {0} bytes)(excluding children)",
+ page_vs_size)
+#endif
+ ,"ControlState Size (excluding children)"
+ ));
int pos = 0;
-#if NET_2_0
foreach (ControlTraceData r in control_data)
RenderControlTraceDataRow (table, r, pos++);
-#else
- foreach (object o in control_data)
- RenderControlTraceDataRow (table, o as ControlTraceData, pos++);
-#endif
table.RenderControl (output);
}
prefix += " ";
RenderAltRow (table, pos, prefix + r.ControlId,
r.Type.ToString (), r.RenderSize.ToString (),
- r.ViewstateSize.ToString ());
+ r.ViewstateSize.ToString (), r.ControlstateSize.ToString ());
}
- private void RenderCookies (HtmlTextWriter output)
+ void RenderCookies (HtmlTextWriter output)
{
Table table = CreateTable ();
table.Rows.Add (SubHeadRow ("Name", "Value", "Size"));
int pos = 0;
-#if NET_2_0
foreach (NameValueTraceData r in cookie_data)
RenderCookieDataRow (table, r, pos++);
-#else
- foreach (object o in cookie_data)
- RenderCookieDataRow (table, o as NameValueTraceData, pos++);
-#endif
table.RenderControl (output);
}
RenderAltRow (table, pos++, r.Name, r.Value, length.ToString ());
}
- private void RenderHeaders (HtmlTextWriter output)
+ void RenderHeaders (HtmlTextWriter output)
{
Table table = CreateTable ();
table.Rows.Add (SubHeadRow ("Name", "Value"));
int pos = 0;
-#if NET_2_0
foreach (NameValueTraceData r in header_data)
RenderAltRow (table, pos++, r.Name, r.Value);
-#else
- NameValueTraceData r;
- foreach (object o in header_data) {
- r = o as NameValueTraceData;
- if (r == null)
- continue;
-
- RenderAltRow (table, pos++, r.Name, r.Value);
- }
-#endif
table.RenderControl (output);
}
- private void RenderServerVars (HtmlTextWriter output)
+ void RenderServerVars (HtmlTextWriter output)
{
Table table = CreateTable ();
table.Rows.Add (SubHeadRow ("Name", "Value"));
int pos = 0;
-#if NET_2_0
foreach (NameValueTraceData r in servervar_data)
RenderAltRow (table, pos++, r.Name, r.Value);
-#else
- NameValueTraceData r;
- foreach (object o in servervar_data) {
- r = o as NameValueTraceData;
- if (r == null)
- continue;
-
- RenderAltRow (table, pos++, r.Name, r.Value);
- }
-#endif
table.RenderControl (output);
}
return row;
}
- private void RenderTraceInfoRow (Table table, InfoTraceData i, int pos)
+ void RenderTraceInfoRow (Table table, InfoTraceData i, int pos)
{
if (i == null)
return;
string open, close;
open = close = String.Empty;
if ((bool) i.IsWarning) {
- open = "<font color=\"Red\">";
- close = "</font>";
+ open = "<span style=\"color:red\">";
+ close = "</span>";
}
-
- double t = (double) i.TimeSinceFirst;
+
string t1, t2;
- if (t == 0) {
+#if !TARGET_J2EE
+ if (i.TimeSinceFirst == 0) {
t1 = t2 = String.Empty;
- prev_time = 0;
- } else {
- t1 = t.ToString ("0.000000");
- t2 = (t - prev_time).ToString ("0.000000");
- prev_time = t;
+ } else
+#endif
+ {
+ t1 = i.TimeSinceFirst.ToString ("0.000000");
+ if (i.TimeSinceLast >= 0.1)
+ t2 = "<span style=\"color:red;font-weight:bold\">" + i.TimeSinceLast.ToString ("0.000000") + "</span>";
+ else
+ t2 = i.TimeSinceLast.ToString ("0.000000");
}
RenderAltRow (table, pos, open + (string) i.Category + close,
return row;
}
- private TableRow InfoRow2 (string title1, string info1, string title2, string info2)
+ TableRow InfoRow2 (string title1, string info1, string title2, string info2)
{
TableRow row = new TableRow ();
TableHeaderCell header1 = new TableHeaderCell ();