// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using PerfReportTool; using CSVStats; namespace PerfSummaries { class EventSummary : Summary { public EventSummary(XElement element, XmlVariableMappings vars, string baseXmlDirectory) { ReadStatsFromXML(element, vars); title = element.GetSafeAttribute(vars, "title", "Events"); summaryStatName = element.GetRequiredAttribute(vars, "summaryStatName"); events = element.Element("events").Value.Split(','); colourThresholds = ReadColourThresholdsXML(element.Element("colourThresholds"), vars); } public EventSummary() { } public override string GetName() { return "event"; } public override HtmlSection WriteSummaryData(bool bWriteHtml, CsvStats csvStats, CsvStats csvStatsUnstripped, bool bWriteSummaryCsv, SummaryTableRowData rowData, string htmlFileName) { HtmlSection htmlSection = null; Dictionary eventCountsDict = new Dictionary(); int eventCount = 0; foreach (CsvEvent ev in csvStats.Events) { foreach (string eventName in events) { if (CsvStats.DoesSearchStringMatch(ev.Name, eventName)) { int len = eventName.Length; if (eventName.EndsWith("*")) { len--; } string eventContent = ev.Name.Substring(len).Trim(); if (eventCountsDict.ContainsKey(eventContent)) { eventCountsDict[eventContent]++; } else { eventCountsDict.Add(eventContent, 1); } eventCount++; } } } // Sort descending eventCountsDict = eventCountsDict .OrderBy(pair => -pair.Value) .ToDictionary(x => x.Key, x => x.Value); // Output HTML if (bWriteHtml && eventCountsDict.Count > 0) { htmlSection = new HtmlSection(title, bStartCollapsed); htmlSection.WriteLine(" "); htmlSection.WriteLine(" "); foreach (KeyValuePair pair in eventCountsDict.ToList()) { htmlSection.WriteLine(" "); } htmlSection.WriteLine("
NameCount
" + pair.Key + "" + pair.Value + "
"); } // Output summary table row data if (rowData != null) { ColourThresholdList thresholdList = null; if (colourThresholds != null) { thresholdList = new ColourThresholdList(); for (int i = 0; i < colourThresholds.Length; i++) { thresholdList.Add(new ThresholdInfo(colourThresholds[i])); } } rowData.Add(SummaryTableElement.Type.SummaryTableMetric, summaryStatName, (double)eventCount, thresholdList); } return htmlSection; } public override void PostInit(ReportTypeInfo reportTypeInfo, CsvStats csvStats) { } string[] events; double[] colourThresholds; string title; string summaryStatName; }; }