private static void EmitCounter(string counterSet, string counter, ref StringBuilder sb) { sb.Append(" [PerformanceCounter(\""); sb.Append(counterSet); sb.Append("\", \""); sb.Append(counter); sb.AppendLine("\")]"); string c = counter .Replace("%", "Percent") .Replace("#", "Count of") .Replace("(", "") .Replace(")", "") .Trim(); string className = NameUtils.CreateIdentifier(c).Trim('_'); sb.Append(" public class "); sb.Append(className); sb.AppendLine(" : PerformanceSample"); sb.AppendLine(" {"); sb.Append(" public "); sb.Append(className); sb.AppendLine("(PerformanceSample other)"); sb.AppendLine(" : base(other)"); sb.AppendLine(" { }"); sb.AppendLine(" }"); sb.AppendLine(); }
public static Dictionary <string, string> Parse(string dataSource) { SortedList <string, SortedSet <string> > allCounters = PdhUtils.Parse(dataSource); var generated = new Dictionary <string, string>(); foreach (string counterSet in allCounters.Keys) { string setName = NameUtils.CreateIdentifier(counterSet); var sb = new StringBuilder("// This code was generated by EtwEventTypeGen"); sb.AppendLine(setName); sb.Append("namespace Tx.Windows.Counters."); sb.AppendLine(setName); sb.AppendLine(); sb.AppendLine("{"); foreach (string counter in allCounters[counterSet]) { EmitCounter(counterSet, counter, ref sb); } sb.AppendLine("}"); generated.Add(setName, sb.ToString()); } return(generated); }
private string LookupOpcodeName(XElement evt, XElement opcodes) { if (opcodes == null) { return(null); } if (evt.Attribute(AttributeNames.Opcode) == null) { return(null); } string name = evt.Attribute(AttributeNames.Opcode).Value; string message = (from o in opcodes.Elements() where o.Attribute(AttributeNames.Name).Value == name && o.Attribute(AttributeNames.Message) != null select o.Attribute(AttributeNames.Message).Value).FirstOrDefault(); if (String.IsNullOrEmpty(message)) { return(NameUtils.CreateIdentifier(name)); } return(NameUtils.CreateIdentifier(LookupResourceString(message))); }
private void EmitDefaultFormatString(ref StringBuilder sb, XElement evt, XElement templates) { if (evt.Attribute(AttributeNames.Template) == null) { return; } IEnumerable <XElement> template = from t in templates.Elements() where t.Attribute(AttributeNames.Tid).Value == evt.Attribute(AttributeNames.Template).Value select t; sb.Append(" [Format(\""); int order = 0; foreach (XElement f in template.Elements(ElementNames.Data)) { if (order > 0) { sb.Append(", "); } order++; sb.Append(NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Name).Value)); sb.Append("=%"); sb.Append(order); } sb.AppendLine("\")]"); }
private void EmitTemplate(ref StringBuilder sb, XElement evt, XElement templates) { if (evt.Attribute(AttributeNames.Template) == null) { return; } IEnumerable <XElement> template = from t in templates.Elements() where t.Attribute(AttributeNames.Tid).Value == evt.Attribute(AttributeNames.Template).Value select t; int order = 0; foreach (XElement f in template.Elements(ElementNames.Data)) { if (order > 0) { sb.AppendLine(); } var length = f.Attribute(AttributeNames.Length); if (null != length) { sb.AppendFormat(" [EventField(\"{0}\", \"{1}\")]", f.Attribute(AttributeNames.InType).Value, length.Value); } else { sb.AppendFormat(" [EventField(\"{0}\")]", f.Attribute(AttributeNames.InType).Value); } sb.AppendLine(); if (f.Attribute(AttributeNames.Map) == null) { sb.AppendFormat(" public {0} {1}", CleanType(f.Attribute(AttributeNames.InType).Value), NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Name).Value)); } else { sb.AppendFormat(" public {0} {1}", NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Map).Value), NameUtils.CreateIdentifier(f.Attribute(AttributeNames.Name).Value)); } sb.AppendLine(" { get; set; }"); order++; } }
private void EmitTaskValue(XElement tasks, StringBuilder sb) { sb.AppendFormat(" public enum EventTask : uint"); sb.AppendLine(" {"); var mapCollection = new Dictionary <string, string>(); foreach (var taskValue in tasks.Elements()) { var taskEnumIdentifier = NameUtils.CreateIdentifier(taskValue.Attribute(AttributeNames.Name).Value); var taskEnumValue = taskValue.Attribute(AttributeNames.Value).Value; sb.AppendFormat(" {0} = {1},", taskEnumIdentifier, taskEnumValue); sb.AppendLine(); } sb.AppendLine(" }"); sb.AppendLine(); }
private void EmitMapValue(XElement maps, StringBuilder sb) { foreach (XElement map in maps.Elements()) { string className = map.Attribute(AttributeNames.Name).Value; bool isInt = map.Elements() .Select(e => e.Attribute(AttributeNames.Value).Value) .All(s => { int val; return(Int32.TryParse(s, out val)); }); string mapType = isInt ? "int" : "uint"; sb.AppendFormat(" public enum {0} : {1}", NameUtils.CreateIdentifier(className), mapType); sb.AppendLine(" {"); var mapCollection = new Dictionary <string, string>(); foreach (var mapValue in map.Elements()) { var mapEnumIdentifier = NameUtils.CreateIdentifier(LookupResourceString(mapValue.Attribute(AttributeNames.Message).Value)); var mapEnumValue = mapValue.Attribute(AttributeNames.Value).Value; if (mapCollection.ContainsKey(mapEnumIdentifier)) { mapCollection[mapEnumIdentifier] += " | " + mapEnumValue; } else { mapCollection[mapEnumIdentifier] = mapEnumValue; } } foreach (var mapValue in mapCollection) { sb.AppendFormat(" {0} = {1},", mapValue.Key, mapValue.Value); sb.AppendLine(); } sb.AppendLine(" }"); sb.AppendLine(); } }