static private RICustomData _GetProcessInformation(RICustomData cData, Process process) { RICustomDataCategory cat = cData.AddCategory("Process Information"); cat.AddRow("Process Id", process.Id.ToString()); cat.AddRow("Process Name", process.ProcessName); cat.AddRow("Image", process.MainModule.FileName); cat.AddRow("Machine Name", process.MachineName == "." ? Environment.MachineName : process.MachineName); cat.AddRow("Main Window Handle", process.MainWindowHandle != null ? process.MainWindowHandle.ToString() : null); cat.AddRow("Main Window Title", process.MainWindowTitle); cat.AddRow("Handle", process.Handle != null ? process.Handle.ToString() : null); cat.AddRow("Open Handles", process.HandleCount.ToString()); cat.AddRow("Number of Modules", process.Modules.Count.ToString()); cat = cData.AddCategory("Priority Information"); cat.AddRow("Base Priority", process.BasePriority.ToString()); cat.AddRow("Priority", process.PriorityClass.ToString()); cat.AddRow("Priority Boost", process.PriorityBoostEnabled.ToString()); cat = cData.AddCategory("Memory Information"); cat.AddRow("Non-Paged System Memory", string.Format("{0} KB", (process.NonpagedSystemMemorySize64 / 1024).ToString("N0"))); cat.AddRow("Paged System Memory", string.Format("{0} KB", (process.PagedSystemMemorySize64 / 1024).ToString("N0"))); cat.AddRow("Paged Memory", string.Format("{0} KB", (process.PagedMemorySize64 / 1024).ToString("N0"))); cat.AddRow("Peak Paged Memory", string.Format("{0} KB", (process.PeakPagedMemorySize64 / 1024).ToString("N0"))); cat.AddRow("Peak Virtual Memory", string.Format("{0} KB", (process.PeakVirtualMemorySize64 / 1024).ToString("N0"))); cat.AddRow("Private Memory", string.Format("{0} KB", (process.PrivateMemorySize64 / 1024).ToString("N0"))); return(cData); }
/// <summary> /// Initializes a new instance of the <see cref="TraceMethod"/> class. /// </summary> /// <param name="ri">The ri.</param> /// <param name="message">The message.</param> internal TraceMethod(ReflectInsight ri, String message) { RI = ri; Message = message ?? "(null)"; Disposed = false; ControlValues = RequestManager.GetRequestObject(); TraceStates = ControlValues.GetState <TraceMethodState>("TraceMethodState"); if (TraceStates == null) { // must be parent trace method TraceStates = new TraceMethodState() { TraceLevel = 0, ExceptionHandled = false }; ControlValues.AddState("TraceMethodState", TraceStates); } RICustomData cData = null; if (cData == null) { RI.EnterMethod(Message); } else { FSendMethodInfo.Invoke(RI, new object[] { MessageType.EnterMethod, message, cData, new object[] { } }); } LastIndentLevel = ReflectInsight.IndentLevel; TraceStates.TraceLevel++; }
static public RICustomData GetCollection(IEnumerable enumerator, ObjectScope scope) { RICustomDataFieldIdType fType = RICustomDataFieldIdType.Integer; RICustomDataColumnJustificationType sIndexJustification = RICustomDataColumnJustificationType.Right; string sIndex = "Index"; if (enumerator is IDictionary) { sIndex = "Key"; fType = RICustomDataFieldIdType.String; sIndexJustification = RICustomDataColumnJustificationType.Left; } List <RICustomDataColumn> columns = new List <RICustomDataColumn>(); columns.Add(new RICustomDataColumn(sIndex, fType, null, null, sIndexJustification)); columns.Add(new RICustomDataColumn("Value")); columns.Add(new RICustomDataColumn("Type")); RICustomData cData = new RICustomData(enumerator.GetType().FullName, columns, true, false); cData.AllowSort = true; cData.HasDetails = scope != ObjectScope.None; using (var pool = FastFormatterPool.Pool.Container()) { if (enumerator is IDictionary) { IDictionary collection = (IDictionary)enumerator; foreach (Object key in collection.Keys) { Object value = collection[key]; RICustomDataRow row = cData.AddRow(key != null ? key.ToString() : null, value != null ? value.ToString() : null, value != null ? value.GetType().FullName : null); if (!cData.HasDetails || value == null) { continue; } row.SetExtraData(pool.Instance, ObjectBuilder.BuildObjectPropertyMap(value, scope)); } } else { Int32 index = 0; foreach (Object value in enumerator) { RICustomDataRow row = cData.AddRow(index++, value != null ? value.ToString() : null, value != null ? value.GetType().FullName : null); if (!cData.HasDetails || value == null) { continue; } row.SetExtraData(pool.Instance, ObjectBuilder.BuildObjectPropertyMap(value, scope)); } } } return(cData); }
static public RICustomData GetLoadedAssemblies() { List <RICustomDataColumn> columns = new List <RICustomDataColumn>(); columns.Add(new RICustomDataColumn("Assembly")); columns.Add(new RICustomDataColumn("Version")); columns.Add(new RICustomDataColumn("Culture")); columns.Add(new RICustomDataColumn("Strong Named")); columns.Add(new RICustomDataColumn("GAC")); RICustomData cData = new RICustomData(string.Format("{0}: Loaded Assemblies", AppDomain.CurrentDomain.FriendlyName), columns, true, false) { AllowSort = true }; string tmpStr = string.Empty; foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies()) { RICustomDataRow row = cData.AddRow(); Int32 j = 0; string[] fns1 = assem.FullName.Split(','); foreach (string s1 in fns1) { if (j != 0) { string[] fns2 = s1.Split('='); tmpStr = fns2[1].Trim(); switch (j) { case 1: row.AddField(tmpStr); break; case 2: row.AddField(tmpStr); break; case 3: row.AddField((tmpStr != "null").ToString()); break; } } else { row.AddField(s1.Trim()); } j++; } row.AddField(assem.GlobalAssemblyCache.ToString()); } return(cData); }
static public void AppendCustomData(StringBuilder sb, RICustomData cData) { if (cData != null) { if (cData.TopCategoryCount != 0) { sb.AppendFormat("[{0}]{1}", cData.Caption, Environment.NewLine); AppendCustomDataChild(sb, cData, cData.Children, 5); } else { AppendCollection(sb, cData); } } else { sb.AppendFormat("[Type: (null)]{0}", Environment.NewLine); } }
static public RICustomData GetLoadedProcesses() { List <RICustomDataColumn> columns = new List <RICustomDataColumn>(); columns.Add(new RICustomDataColumn("Image Name")); columns.Add(new RICustomDataColumn("Mem Usage", RICustomDataFieldIdType.Integer, "{0:N0} KB", null, RICustomDataColumnJustificationType.Right)); columns.Add(new RICustomDataColumn("Virtual Mem Usage", RICustomDataFieldIdType.Integer, "{0:N0} KB", null, RICustomDataColumnJustificationType.Right)); columns.Add(new RICustomDataColumn("Peak Mem Usage", RICustomDataFieldIdType.Integer, "{0:N0} KB", null, RICustomDataColumnJustificationType.Right)); columns.Add(new RICustomDataColumn("Thread Count", RICustomDataFieldIdType.Integer, "{0:N0}", null, RICustomDataColumnJustificationType.Right)); RICustomData cData = new RICustomData("Loaded Processes", columns, true, false) { AllowSort = true }; List <Process> processes = new List <Process>(Process.GetProcesses()); processes.Sort(CompareProcess); foreach (Process p in processes) { using (p) { if (p.ProcessName.Trim().ToLower() == "idle") { continue; } RICustomDataRow row = cData.AddRow(); row.AddField(p.ProcessName); row.AddField((Int32)(p.WorkingSet64 / 1024)); row.AddField((Int32)(p.PrivateMemorySize64 / 1024)); row.AddField((Int32)(p.PeakWorkingSet64 / 1024)); row.AddField((Int32)p.Threads.Count); } } processes.Clear(); processes.Capacity = 0; return(cData); }
static private void AppendCustomDataChild(StringBuilder sb, RICustomData cData, List <RICustomDataElement> children, Int32 indent) { foreach (RICustomDataElement ce in children) { if (ce.CustomDataType == RICustomDataElementType.Category) { String catFmt = String.Format("{{0,{0}}}{{1}}{{2}}", indent); RICustomDataCategory cat = (RICustomDataCategory)ce; sb.AppendFormat(catFmt, " ", String.Format("[{0}]", cat.Caption), Environment.NewLine); AppendCustomDataChild(sb, cData, cat.Children, indent + 3); } else // must be Row { String sIndentFmt = String.Format("{{0,{0}}}{{1}}", indent); RICustomDataRow row = (RICustomDataRow)ce; Int32 maxFieldsAllowed = row.Fields.Count < cData.Columns.Length ? row.Fields.Count : cData.Columns.Length; String separator = cData.IsPropertyGrid ? " " : " | "; for (Int32 i = 0; i < maxFieldsAllowed; i++) { if (i > 0) { sb.AppendFormat("{0}{1}", separator, row.Fields[i]); } else { sb.AppendFormat(sIndentFmt, " ", row.Fields[i]); if (cData.IsPropertyGrid) { sb.Append(":"); } } } sb.AppendFormat(Environment.NewLine); } } }
static public RICustomData GetThreadInformation(Thread aThread) { List <RICustomDataColumn> columns = new List <RICustomDataColumn> { new RICustomDataColumn("Property"), new RICustomDataColumn("Value") }; RICustomData cData = new RICustomData("Thread Information", columns, false, true); cData.AddRow("Name", aThread.Name); cData.AddRow("HashCode", aThread.GetHashCode().ToString()); cData.AddRow("IsAlive", aThread.IsAlive.ToString()); cData.AddRow("IsBackground", aThread.IsBackground.ToString()); cData.AddRow("IsThreadPoolThread", aThread.IsThreadPoolThread.ToString()); cData.AddRow("Priority", aThread.Priority.ToString()); cData.AddRow("ThreadState", aThread.ThreadState.ToString()); cData.AddRow("ApartmentState", aThread.GetApartmentState().ToString()); cData.AddRow("CurrentCulture", aThread.CurrentCulture.ToString()); cData.AddRow("CurrentUICulture", aThread.CurrentUICulture.ToString()); return(cData); }
static public void AppendCollection(StringBuilder sb, RICustomData cData) { if (!string.IsNullOrWhiteSpace(cData.Caption)) { sb.AppendFormat("[{0}]{1}", cData.Caption, Environment.NewLine); } RICustomDataColumn[] cols = cData.Columns; String[][] rows = cData.TopRowToStringArray(); // get the largest column width for all columns Int32[] largestColumnWidthSize = new Int32[cols.Length]; for (Int32 i = 0; i < cols.Length; i++) { if (cols[i].Caption.Length > largestColumnWidthSize[i]) { largestColumnWidthSize[i] = cols[i].Caption.Length; } for (Int32 j = 0; j < rows.Length; j++) { if (rows[j][i].Length > largestColumnWidthSize[i]) { largestColumnWidthSize[i] = rows[j][i].Length; } } } StringBuilder line = new StringBuilder(); StringBuilder row = new StringBuilder(); // prepare column formats and line String[] stringColumnFmt = new String[cols.Length]; for (Int32 i = 0; i < largestColumnWidthSize.Length; i++) { stringColumnFmt[i] = String.Format("{{0,-{0}}} ", largestColumnWidthSize[i]); row.AppendFormat(stringColumnFmt[i], cols[i].Caption); line.AppendFormat(String.Format(stringColumnFmt[i], " ").Replace(' ', '-')); // use right justification for numeric fields if (cols[i].Justification == RICustomDataColumnJustificationType.Right) { stringColumnFmt[i] = stringColumnFmt[i].Replace("-", String.Empty); } } if (!string.IsNullOrWhiteSpace(cols[0].Caption)) { sb.AppendLine(row.ToString().TrimEnd(null)); sb.AppendLine(line.ToString()); } // write fields for (Int32 i = 0; i < rows.Length; i++) { row = new StringBuilder(); for (Int32 j = 0; j < cols.Length; j++) { row.AppendFormat(String.Format(stringColumnFmt[j], rows[i][j])); } sb.AppendLine(row.ToString().TrimEnd(null)); } if (!cData.HasDetails) { return; } RICustomData[] extraData = cData.TopRowToExtraDataArray <RICustomData>(); for (Int32 i = 0; i < extraData.Length; i++) { sb.AppendLine(); AppendCustomData(sb, extraData[i]); } }
//--------------------------------------------------------------------- static RICustomData GetCustomData1() { Random rnd = new Random((Int32)DateTime.Now.Ticks); List <RICustomDataColumn> columns = new List <RICustomDataColumn>(); columns.Add(new RICustomDataColumn("Column1")); columns.Add(new RICustomDataColumn("Column2")); columns.Add(new RICustomDataColumn("Column3")); columns.Add(new RICustomDataColumn("Column4")); RICustomData cData = new RICustomData("My Custom Data", columns, true, false); cData.AddRow("Ross", "Test"); RICustomDataCategory cat = cData.AddCategory("Category1"); for (Int32 i = 0; i < 3; i++) { const String crap = "a"; cat.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}{1}", i, crap), String.Format("field3{0}", i)); } cat = cat.AddCategory("Category2"); RICustomDataCategory cat2 = cat; for (Int32 i = 0; i < 3; i++) { const String crap = "b"; cat.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}", i), String.Format("field3{0}", i), String.Format("field4{0}", i)); } cat = cat.AddCategory("Category3"); RICustomDataCategory cat3 = cat.AddCategory("Category3b"); cat3.AddRow("Ross", "Test"); for (Int32 i = 0; i < 3; i++) { const String crap = "c"; cat.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}", i), String.Format("field3{0}", i), String.Format("field4{0}", i)); } for (Int32 i = 0; i < 3; i++) { const String crap = "bx"; cat2.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}", i), String.Format("field3{0}{1}", i, crap)); } cat = cData.AddCategory("Category1a"); for (Int32 i = 0; i < 3; i++) { const String crap = "a1"; cat.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}{1}", i, crap), String.Format("field3{0}", i)); } for (Int32 i = 0; i < 3; i++) { const String crap = "d"; cData.AddRow(String.Format("field1{0}{1}", i, crap), String.Format("field2{0}", i), String.Format("field3{0}{1}", i, crap)); } return(cData); }