| author | Scott Ehlert <ds@alliedmods.net> |
| Sun Sep 14 02:59:26 2008 -0500 (2008-09-14) | |
| changeset 2288 | 15c77b21589a |
| parent 1952 | b7aa2b626807 |
| child 2289 | 44045ead61cd |
| permissions | -rw-r--r-- |
| ds@1952 | 1 |
using System; |
| ds@1952 | 2 |
using System.Collections.Generic; |
| ds@1952 | 3 |
using System.Text; |
| ds@1952 | 4 |
using System.Xml; |
| ds@1952 | 5 |
|
| ds@1952 | 6 |
namespace profviewer |
| ds@1952 | 7 |
{ |
| ds@1952 | 8 |
enum ProfileType : int |
| ds@1952 | 9 |
{ |
| ds@1952 | 10 |
ProfType_Unknown = 0, |
| ds@1952 | 11 |
ProfType_Native, |
| ds@1952 | 12 |
ProfType_Callback, |
| ds@1952 | 13 |
ProfType_Function |
| ds@1952 | 14 |
} |
| ds@1952 | 15 |
|
| ds@1952 | 16 |
class ProfileItem |
| ds@1952 | 17 |
{ |
| ds@1952 | 18 |
public string name; |
| ds@1952 | 19 |
public double total_time; |
| ds@1952 | 20 |
public uint num_calls; |
| ds@1952 | 21 |
public double min_time; |
| ds@1952 | 22 |
public double max_time; |
| ds@1952 | 23 |
public ProfileType type; |
| ds@1952 | 24 |
|
| ds@1952 | 25 |
public double AverageTime |
| ds@1952 | 26 |
{ |
| ds@1952 | 27 |
get |
| ds@1952 | 28 |
{ |
| ds@1952 | 29 |
return total_time / num_calls; |
| ds@1952 | 30 |
} |
| ds@1952 | 31 |
} |
| ds@1952 | 32 |
} |
| ds@1952 | 33 |
|
| ds@1952 | 34 |
class ProfileReport |
| ds@1952 | 35 |
{ |
| ds@1952 | 36 |
public static string[] TypeStrings; |
| ds@1952 | 37 |
private DateTime m_start_time; |
| ds@1952 | 38 |
private double m_duration; |
| ds@1952 | 39 |
private List<ProfileItem> m_Items; |
| ds@1952 | 40 |
|
| ds@1952 | 41 |
public int Count |
| ds@1952 | 42 |
{ |
| ds@1952 | 43 |
get |
| ds@1952 | 44 |
{ |
| ds@1952 | 45 |
return m_Items.Count; |
| ds@1952 | 46 |
} |
| ds@1952 | 47 |
} |
| ds@1952 | 48 |
|
| ds@1952 | 49 |
static ProfileReport() |
| ds@1952 | 50 |
{ |
| ds@1952 | 51 |
TypeStrings = new string[4]; |
| ds@1952 | 52 |
|
| ds@1952 | 53 |
TypeStrings[0] = "unknown"; |
| ds@1952 | 54 |
TypeStrings[1] = "native"; |
| ds@1952 | 55 |
TypeStrings[2] = "callback"; |
| ds@1952 | 56 |
TypeStrings[3] = "function"; |
| ds@1952 | 57 |
} |
| ds@1952 | 58 |
|
| ds@1952 | 59 |
public ProfileReport(string file) |
| ds@1952 | 60 |
{ |
| ds@1952 | 61 |
bool in_profile; |
| ds@1952 | 62 |
ProfileType type; |
| ds@1952 | 63 |
string cur_report; |
| ds@1952 | 64 |
XmlTextReader xml; |
| ds@1952 | 65 |
|
| ds@1952 | 66 |
xml = new XmlTextReader(file); |
| ds@1952 | 67 |
xml.WhitespaceHandling = WhitespaceHandling.None; |
| ds@1952 | 68 |
|
| ds@1952 | 69 |
m_Items = new List<ProfileItem>(); |
| ds@1952 | 70 |
|
| ds@1952 | 71 |
type = ProfileType.ProfType_Unknown; |
| ds@1952 | 72 |
in_profile = false; |
| ds@1952 | 73 |
cur_report = null; |
| ds@1952 | 74 |
while (xml.Read()) |
| ds@1952 | 75 |
{ |
| ds@1952 | 76 |
if (xml.NodeType == XmlNodeType.Element) |
| ds@1952 | 77 |
{ |
| ds@1952 | 78 |
if (xml.Name.CompareTo("profile") == 0) |
| ds@1952 | 79 |
{ |
| ds@1952 | 80 |
int t; |
| ds@1952 | 81 |
in_profile = true; |
| ds@1952 | 82 |
m_duration = Double.Parse(xml.GetAttribute("uptime")); |
| ds@1952 | 83 |
m_start_time = new DateTime(1970, 1, 1, 0, 0, 0); |
| ds@1952 | 84 |
t = Int32.Parse(xml.GetAttribute("time")); |
| ds@1952 | 85 |
m_start_time = m_start_time.AddSeconds(t); |
| ds@1952 | 86 |
} |
| ds@1952 | 87 |
else if (in_profile) |
| ds@1952 | 88 |
{ |
| ds@1952 | 89 |
if (xml.Name.CompareTo("report") == 0) |
| ds@1952 | 90 |
{ |
| ds@1952 | 91 |
cur_report = xml.GetAttribute("name"); |
| ds@1952 | 92 |
if (cur_report.CompareTo("natives") == 0) |
| ds@1952 | 93 |
{ |
| ds@1952 | 94 |
type = ProfileType.ProfType_Native; |
| ds@1952 | 95 |
} |
| ds@1952 | 96 |
else if (cur_report.CompareTo("callbacks") == 0) |
| ds@1952 | 97 |
{ |
| ds@1952 | 98 |
type = ProfileType.ProfType_Callback; |
| ds@1952 | 99 |
} |
| ds@1952 | 100 |
else if (cur_report.CompareTo("functions") == 0) |
| ds@1952 | 101 |
{ |
| ds@1952 | 102 |
type = ProfileType.ProfType_Function; |
| ds@1952 | 103 |
} |
| ds@1952 | 104 |
else |
| ds@1952 | 105 |
{ |
| ds@1952 | 106 |
type = ProfileType.ProfType_Unknown; |
| ds@1952 | 107 |
} |
| ds@1952 | 108 |
} |
| ds@1952 | 109 |
else if (xml.Name.CompareTo("item") == 0 && cur_report != null) |
| ds@1952 | 110 |
{ |
| ds@1952 | 111 |
ProfileItem item; |
| ds@1952 | 112 |
|
| ds@1952 | 113 |
item = new ProfileItem(); |
| ds@1952 | 114 |
item.name = xml.GetAttribute("name"); |
| ds@1952 | 115 |
item.max_time = Double.Parse(xml.GetAttribute("maxtime")); |
| ds@1952 | 116 |
item.min_time = Double.Parse(xml.GetAttribute("mintime")); |
| ds@1952 | 117 |
item.num_calls = UInt32.Parse(xml.GetAttribute("numcalls")); |
| ds@1952 | 118 |
item.total_time = Double.Parse(xml.GetAttribute("totaltime")); |
| ds@1952 | 119 |
item.type = type; |
| ds@1952 | 120 |
m_Items.Add(item); |
| ds@1952 | 121 |
} |
| ds@1952 | 122 |
} |
| ds@1952 | 123 |
} |
| ds@1952 | 124 |
else if (xml.NodeType == XmlNodeType.EndElement) |
| ds@1952 | 125 |
{ |
| ds@1952 | 126 |
if (xml.Name.CompareTo("profile") == 0) |
| ds@1952 | 127 |
{ |
| ds@1952 | 128 |
break; |
| ds@1952 | 129 |
} |
| ds@1952 | 130 |
else if (xml.Name.CompareTo("report") == 0) |
| ds@1952 | 131 |
{ |
| ds@1952 | 132 |
cur_report = null; |
| ds@1952 | 133 |
} |
| ds@1952 | 134 |
} |
| ds@1952 | 135 |
} |
| ds@1952 | 136 |
} |
| ds@1952 | 137 |
|
| ds@1952 | 138 |
public double Duration |
| ds@1952 | 139 |
{ |
| ds@1952 | 140 |
get |
| ds@1952 | 141 |
{ |
| ds@1952 | 142 |
return m_duration; |
| ds@1952 | 143 |
} |
| ds@1952 | 144 |
} |
| ds@1952 | 145 |
|
| ds@1952 | 146 |
public DateTime StartTime |
| ds@1952 | 147 |
{ |
| ds@1952 | 148 |
get |
| ds@1952 | 149 |
{ |
| ds@1952 | 150 |
return m_start_time; |
| ds@1952 | 151 |
} |
| ds@1952 | 152 |
} |
| ds@1952 | 153 |
|
| ds@1952 | 154 |
public ProfileItem GetItem(int i) |
| ds@1952 | 155 |
{ |
| ds@1952 | 156 |
return m_Items[i]; |
| ds@1952 | 157 |
} |
| ds@1952 | 158 |
} |
| ds@1952 | 159 |
} |