tools/profiler/csharp/ProfReport.cs
changeset 1908 318e0a01aef9
child 1910 216ade964e87
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/profiler/csharp/ProfReport.cs	Sun Mar 02 06:40:59 2008 +0000
     1.3 @@ -0,0 +1,157 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Text;
     1.7 +using System.Xml;
     1.8 +
     1.9 +namespace profviewer
    1.10 +{
    1.11 +    enum ProfileType : int
    1.12 +    {
    1.13 +        ProfType_Unknown = 0,
    1.14 +        ProfType_Native,
    1.15 +        ProfType_Callback,
    1.16 +        ProfType_Function
    1.17 +    }
    1.18 +
    1.19 +    class ProfileItem
    1.20 +    {
    1.21 +        public string name;
    1.22 +        public double total_time;
    1.23 +        public uint num_calls;
    1.24 +        public double min_time;
    1.25 +        public double max_time;
    1.26 +        public ProfileType type;
    1.27 +
    1.28 +        public double AverageTime
    1.29 +        {
    1.30 +            get
    1.31 +            {
    1.32 +                return total_time / num_calls;
    1.33 +            }
    1.34 +        }
    1.35 +    }
    1.36 +
    1.37 +    class ProfileReport
    1.38 +    {
    1.39 +        public static string[] TypeStrings;
    1.40 +        private DateTime m_start_time;
    1.41 +        private double m_duration;
    1.42 +        private List<ProfileItem> m_Items;
    1.43 +
    1.44 +        public int Count
    1.45 +        {
    1.46 +            get
    1.47 +            {
    1.48 +                return m_Items.Count;
    1.49 +            }
    1.50 +        }
    1.51 +
    1.52 +        static ProfileReport()
    1.53 +        {
    1.54 +            TypeStrings = new string[4];
    1.55 +
    1.56 +            TypeStrings[0] = "unknown";
    1.57 +            TypeStrings[1] = "native";
    1.58 +            TypeStrings[2] = "callback";
    1.59 +            TypeStrings[3] = "function";
    1.60 +        }
    1.61 +
    1.62 +        public ProfileReport(string file)
    1.63 +        {
    1.64 +            bool in_profile;
    1.65 +            ProfileType type;
    1.66 +            string cur_report;
    1.67 +            XmlTextReader xml;
    1.68 +
    1.69 +            xml = new XmlTextReader(file);
    1.70 +            xml.WhitespaceHandling = WhitespaceHandling.None;
    1.71 +
    1.72 +            m_Items = new List<ProfileItem>();
    1.73 +
    1.74 +            type = ProfileType.ProfType_Unknown;
    1.75 +            in_profile = false;
    1.76 +            cur_report = null;
    1.77 +            while (xml.Read())
    1.78 +            {
    1.79 +                if (xml.NodeType == XmlNodeType.Element)
    1.80 +                {
    1.81 +                    if (xml.Name.CompareTo("profile") == 0)
    1.82 +                    {
    1.83 +                        in_profile = true;
    1.84 +                        m_duration = Double.Parse(xml.GetAttribute("uptime"));
    1.85 +                        m_start_time = new DateTime(1970, 1, 1, 0, 0, 0);
    1.86 +                        m_start_time.AddSeconds(Int32.Parse(xml.GetAttribute("time")));
    1.87 +                    }
    1.88 +                    else if (in_profile)
    1.89 +                    {
    1.90 +                        if (xml.Name.CompareTo("report") == 0)
    1.91 +                        {
    1.92 +                            cur_report = xml.GetAttribute("name");
    1.93 +                            if (cur_report.CompareTo("natives") == 0)
    1.94 +                            {
    1.95 +                                type = ProfileType.ProfType_Native;
    1.96 +                            }
    1.97 +                            else if (cur_report.CompareTo("callbacks") == 0)
    1.98 +                            {
    1.99 +                                type = ProfileType.ProfType_Callback;
   1.100 +                            }
   1.101 +                            else if (cur_report.CompareTo("functions") == 0)
   1.102 +                            {
   1.103 +                                type = ProfileType.ProfType_Function;
   1.104 +                            }
   1.105 +                            else
   1.106 +                            {
   1.107 +                                type = ProfileType.ProfType_Unknown;
   1.108 +                            }
   1.109 +                        }
   1.110 +                        else if (xml.Name.CompareTo("item") == 0 && cur_report != null)
   1.111 +                        {
   1.112 +                            ProfileItem item;
   1.113 +
   1.114 +                            item = new ProfileItem();
   1.115 +                            item.name = xml.GetAttribute("name");
   1.116 +                            item.max_time = Double.Parse(xml.GetAttribute("maxtime"));
   1.117 +                            item.min_time = Double.Parse(xml.GetAttribute("mintime"));
   1.118 +                            item.num_calls = UInt32.Parse(xml.GetAttribute("numcalls"));
   1.119 +                            item.total_time = Double.Parse(xml.GetAttribute("totaltime"));
   1.120 +                            item.type = type;
   1.121 +                            m_Items.Add(item);
   1.122 +                        }
   1.123 +                    }
   1.124 +                }
   1.125 +                else if (xml.NodeType == XmlNodeType.EndElement)
   1.126 +                {
   1.127 +                    if (xml.Name.CompareTo("profile") == 0)
   1.128 +                    {
   1.129 +                        break;
   1.130 +                    }
   1.131 +                    else if (xml.Name.CompareTo("report") == 0)
   1.132 +                    {
   1.133 +                        cur_report = null;
   1.134 +                    }
   1.135 +                }
   1.136 +            }
   1.137 +        }
   1.138 +
   1.139 +        public double Duration
   1.140 +        {
   1.141 +            get
   1.142 +            {
   1.143 +                return m_duration;
   1.144 +            }
   1.145 +        }
   1.146 +
   1.147 +        public DateTime StartTime
   1.148 +        {
   1.149 +            get
   1.150 +            {
   1.151 +                return m_start_time;
   1.152 +            }
   1.153 +        }
   1.154 +
   1.155 +        public ProfileItem GetItem(int i)
   1.156 +        {
   1.157 +            return m_Items[i];
   1.158 +        }
   1.159 +    }
   1.160 +}