X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web%2FTraceData.cs;h=8f4c1caf87d1993ee08bfb004bf82e2de9fadff4;hb=9b87d46bdf11e08d30fe313737bd3822dbc21cbd;hp=7ce99c425c3f6f9c8066f7d6dae8e9241b6dd281;hpb=c7ae11abaa7e887078b4613d9d788802c3a91963;p=mono.git diff --git a/mcs/class/System.Web/System.Web/TraceData.cs b/mcs/class/System.Web/System.Web/TraceData.cs index 7ce99c425c3..8f4c1caf87d 100644 --- a/mcs/class/System.Web/System.Web/TraceData.cs +++ b/mcs/class/System.Web/System.Web/TraceData.cs @@ -4,69 +4,137 @@ // Author(s): // Jackson Harper (jackson@ximian.com) // -// (C) 2004 Novell, Inc (http://www.novell.com) +// (C) 2004-2009 Novell, Inc (http://www.novell.com) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.IO; using System.Text; -using System.Data; using System.Web.UI; using System.Web.UI.WebControls; -namespace System.Web { +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, double timeSinceLast, bool isWarning) + { + this.Category = category; + this.Message = message; + this.Exception = exception; + this.TimeSinceFirst = timeSinceFirst; + this.TimeSinceLast = timeSinceLast; + this.IsWarning = isWarning; + } + } - internal class TraceData { + sealed class ControlTraceData + { + public string ControlId; + public Type Type; + public int RenderSize; + public int ViewstateSize; + public int Depth; + public int ControlstateSize; - private bool is_first_time; - private DateTime first_time; - private double prev_time; - - private DataTable info; - private DataTable control_data; - private DataTable cookie_data; - private DataTable header_data; - private DataTable servervar_data; - - 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; + 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; + } + } + + sealed class NameValueTraceData + { + public string Name; + public string Value; + + public NameValueTraceData (string name, string value) + { + this.Name = name; + this.Value = value; + } + } + + sealed class TraceData + { + bool is_first_time; + DateTime first_time; + double prev_time; + Queue info; + Queue control_data; + Queue cookie_data; + Queue header_data; + Queue 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 () { - info = new DataTable (); - info.Columns.Add (new DataColumn ("Category", typeof (string))); - info.Columns.Add (new DataColumn ("Message", typeof (string))); - info.Columns.Add (new DataColumn ("Exception", typeof (string))); - info.Columns.Add (new DataColumn ("TimeSinceFirst", typeof (double))); - info.Columns.Add (new DataColumn ("IsWarning", typeof (bool))); - - control_data = new DataTable (); - control_data.Columns.Add (new DataColumn ("ControlId", typeof (string))); - control_data.Columns.Add (new DataColumn ("Type", typeof (System.Type))); - control_data.Columns.Add (new DataColumn ("RenderSize", typeof (int))); - control_data.Columns.Add (new DataColumn ("ViewstateSize", typeof (int))); - control_data.Columns.Add (new DataColumn ("Depth", typeof (int))); - - cookie_data = new DataTable (); - cookie_data.Columns.Add (new DataColumn ("Name", typeof (string))); - cookie_data.Columns.Add (new DataColumn ("Value", typeof (string))); - - header_data = new DataTable (); - header_data.Columns.Add (new DataColumn ("Name", typeof (string))); - header_data.Columns.Add (new DataColumn ("Value", typeof (string))); - - servervar_data = new DataTable (); - servervar_data.Columns.Add (new DataColumn ("Name", typeof (string))); - servervar_data.Columns.Add (new DataColumn ("Value", typeof (string))); + info = new Queue (); + control_data = new Queue (); + cookie_data = new Queue (); + header_data = new Queue (); + servervar_data = new Queue (); + + /* TODO + viewstate_data = new DataTable (); + viewstate_data.Columns.Add (new DataColumn ("ControlId", typeof (string))); + viewstate_data.Columns.Add (new DataColumn ("Data", typeof (string))); + */ is_first_time = true; } + public TraceMode TraceMode { + get { return _traceMode; } + set { _traceMode = value; } + } + public string RequestPath { get { return request_path; } set { request_path = value; } @@ -105,79 +173,100 @@ namespace System.Web { 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; + } - DataRow r = info.NewRow (); - r ["Category"] = category; - r ["Message"] = HtmlEncode (msg); - r ["Exception"] = (error != null ? error.ToString () : null); - r ["TimeSinceFirst"] = time; - r ["IsWarning"] = Warning; - - info.Rows.Add (r); + info.Enqueue ( + new InfoTraceData (category, + HtmlEncode (msg), + (error != null ? error.ToString () : null), + time, + time_from_last, + Warning)); } static string HtmlEncode (string s) { if (s == null) - return s; + return ""; string res = HttpUtility.HtmlEncode (s); - res = res.Replace ("\n", "
"); + res = res.Replace ("\n", "
"); return res.Replace (" ", " "); } - public void AddControlTree (Page page) + 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); } - private void AddControl (Control c, int control_pos) + Hashtable sizes; + Hashtable ctrl_vs; + void AddControl (Control c, int control_pos) { - DataRow r = control_data.NewRow (); - r ["ControlId"] = c.UniqueID; - r ["Type"] = c.GetType (); - r ["Depth"] = control_pos; + control_data.Enqueue ( + new ControlTraceData ( + c.UniqueID, + 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 ()) { + foreach (Control child in c.Controls) + AddControl (child, control_pos + 1); + } + } - control_data.Rows.Add (r); - - foreach (Control child in c.Controls) - AddControl (child, control_pos + 1); + int GetRenderSize (Control ctrl) + { + if (sizes == null) + return 0; + + object s = sizes [ctrl]; + return s == null ? 0 : (int) s; } - public void AddCookie (string name, string value) + static int GetViewStateSize (Control ctrl, object vs) { - DataRow r = cookie_data.NewRow (); + if (vs == null) + return 0; - r ["Name"] = name; - r ["Value"] = value; + StringWriter sr = new StringWriter (); + LosFormatter fmt = new LosFormatter (); + fmt.Serialize (sr, vs); + return sr.GetStringBuilder ().Length; + } - cookie_data.Rows.Add (r); + public void AddCookie (string name, string value) + { + cookie_data.Enqueue (new NameValueTraceData (name, value)); } public void AddHeader (string name, string value) { - DataRow r = header_data.NewRow (); - - r ["Name"] = name; - r ["Value"] = value; - - header_data.Rows.Add (r); + header_data.Enqueue (new NameValueTraceData (name, value)); } public void AddServerVar (string name, string value) { - DataRow r = servervar_data.NewRow (); - - r ["Name"] = name; - r ["Value"] = value; - - servervar_data.Rows.Add (r); + servervar_data.Enqueue (new NameValueTraceData (name, value)); } public void Render (HtmlTextWriter output) @@ -201,7 +290,7 @@ namespace System.Web { output.RenderEndTag (); } - private void RenderRequestDetails (HtmlTextWriter output) + void RenderRequestDetails (HtmlTextWriter output) { Table table = CreateTable (); @@ -215,7 +304,7 @@ namespace System.Web { table.RenderControl (output); } - private void RenderTraceInfo (HtmlTextWriter output) + void RenderTraceInfo (HtmlTextWriter output) { Table table = CreateTable (); @@ -223,35 +312,57 @@ namespace System.Web { table.Rows.Add (SubHeadRow ("Category", "Message", "From First(s)", "From Lasts(s)")); int pos = 0; - foreach (DataRow r in info.Rows) - RenderTraceInfoRow (table, r, pos++); - + IEnumerable enumerable = info; + + if (TraceMode == TraceMode.SortByCategory) { + List list = new List (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++); table.RenderControl (output); } - private void RenderControlTree (HtmlTextWriter output) + void RenderControlTree (HtmlTextWriter output) { Table table = CreateTable (); + int page_vs_size = page == null ? 0 : GetViewStateSize (page, page.GetSavedViewState ()); table.Rows.Add (AltRow ("Control Tree")); table.Rows.Add (SubHeadRow ("Control Id", "Type", - "Render Size Bytes (including children)", - "View state Size Bytes (excluding children)")); + "Render Size Bytes (including children)", +#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; - foreach (DataRow r in control_data.Rows) { - int depth = (int) r ["Depth"]; - string prefix = String.Empty; - for (int i=0; i"; - close = ""; + if ((bool) i.IsWarning) { + open = ""; + close = ""; } - - double t = (double) r ["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 = "" + i.TimeSinceLast.ToString ("0.000000") + ""; + else + t2 = i.TimeSinceLast.ToString ("0.000000"); } - return RenderAltRow (table, pos, open + (string) r ["Category"] + close, - open + (string) r ["Message"] + close, t1, t2); + RenderAltRow (table, pos, open + (string) i.Category + close, + open + (string) i.Message + close, t1, t2); } internal static TableRow SubHeadRow (params string[] cells) @@ -365,7 +485,7 @@ namespace System.Web { 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 ();