ds@1952: using System; ds@1952: using System.Collections.Generic; ds@1952: using System.Text; ds@1952: using System.Xml; ds@1952: ds@1952: namespace profviewer ds@1952: { ds@1952: enum ProfileType : int ds@1952: { ds@1952: ProfType_Unknown = 0, ds@1952: ProfType_Native, ds@1952: ProfType_Callback, ds@1952: ProfType_Function ds@1952: } ds@1952: ds@1952: class ProfileItem ds@1952: { ds@1952: public string name; ds@1952: public double total_time; ds@1952: public uint num_calls; ds@1952: public double min_time; ds@1952: public double max_time; ds@1952: public ProfileType type; ds@1952: ds@1952: public double AverageTime ds@1952: { ds@1952: get ds@1952: { ds@1952: return total_time / num_calls; ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: class ProfileReport ds@1952: { ds@1952: public static string[] TypeStrings; ds@1952: private DateTime m_start_time; ds@1952: private double m_duration; ds@1952: private List m_Items; ds@1952: ds@1952: public int Count ds@1952: { ds@1952: get ds@1952: { ds@1952: return m_Items.Count; ds@1952: } ds@1952: } ds@1952: ds@1952: static ProfileReport() ds@1952: { ds@1952: TypeStrings = new string[4]; ds@1952: ds@1952: TypeStrings[0] = "unknown"; ds@1952: TypeStrings[1] = "native"; ds@1952: TypeStrings[2] = "callback"; ds@1952: TypeStrings[3] = "function"; ds@1952: } ds@1952: ds@1952: public ProfileReport(string file) ds@1952: { ds@1952: bool in_profile; ds@1952: ProfileType type; ds@1952: string cur_report; ds@1952: XmlTextReader xml; ds@1952: ds@1952: xml = new XmlTextReader(file); ds@1952: xml.WhitespaceHandling = WhitespaceHandling.None; ds@1952: ds@1952: m_Items = new List(); ds@1952: ds@1952: type = ProfileType.ProfType_Unknown; ds@1952: in_profile = false; ds@1952: cur_report = null; ds@1952: while (xml.Read()) ds@1952: { ds@1952: if (xml.NodeType == XmlNodeType.Element) ds@1952: { ds@1952: if (xml.Name.CompareTo("profile") == 0) ds@1952: { ds@1952: int t; ds@1952: in_profile = true; ds@1952: m_duration = Double.Parse(xml.GetAttribute("uptime")); ds@1952: m_start_time = new DateTime(1970, 1, 1, 0, 0, 0); ds@1952: t = Int32.Parse(xml.GetAttribute("time")); ds@1952: m_start_time = m_start_time.AddSeconds(t); ds@1952: } ds@1952: else if (in_profile) ds@1952: { ds@1952: if (xml.Name.CompareTo("report") == 0) ds@1952: { ds@1952: cur_report = xml.GetAttribute("name"); ds@1952: if (cur_report.CompareTo("natives") == 0) ds@1952: { ds@1952: type = ProfileType.ProfType_Native; ds@1952: } ds@1952: else if (cur_report.CompareTo("callbacks") == 0) ds@1952: { ds@1952: type = ProfileType.ProfType_Callback; ds@1952: } ds@1952: else if (cur_report.CompareTo("functions") == 0) ds@1952: { ds@1952: type = ProfileType.ProfType_Function; ds@1952: } ds@1952: else ds@1952: { ds@1952: type = ProfileType.ProfType_Unknown; ds@1952: } ds@1952: } ds@1952: else if (xml.Name.CompareTo("item") == 0 && cur_report != null) ds@1952: { ds@1952: ProfileItem item; ds@1952: ds@1952: item = new ProfileItem(); ds@1952: item.name = xml.GetAttribute("name"); ds@1952: item.max_time = Double.Parse(xml.GetAttribute("maxtime")); ds@1952: item.min_time = Double.Parse(xml.GetAttribute("mintime")); ds@1952: item.num_calls = UInt32.Parse(xml.GetAttribute("numcalls")); ds@1952: item.total_time = Double.Parse(xml.GetAttribute("totaltime")); ds@1952: item.type = type; ds@1952: m_Items.Add(item); ds@1952: } ds@1952: } ds@1952: } ds@1952: else if (xml.NodeType == XmlNodeType.EndElement) ds@1952: { ds@1952: if (xml.Name.CompareTo("profile") == 0) ds@1952: { ds@1952: break; ds@1952: } ds@1952: else if (xml.Name.CompareTo("report") == 0) ds@1952: { ds@1952: cur_report = null; ds@1952: } ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: public double Duration ds@1952: { ds@1952: get ds@1952: { ds@1952: return m_duration; ds@1952: } ds@1952: } ds@1952: ds@1952: public DateTime StartTime ds@1952: { ds@1952: get ds@1952: { ds@1952: return m_start_time; ds@1952: } ds@1952: } ds@1952: ds@1952: public ProfileItem GetItem(int i) ds@1952: { ds@1952: return m_Items[i]; ds@1952: } ds@1952: } ds@1952: }