示例#1
0
        public void GetFrameGroupData(int fromFrameIdx, int toFrameIdx, String[] groups, GroupsStats stats)
        {
            for (int i = fromFrameIdx; i <= toFrameIdx; i++)
            {
                FrameRecord fr = FrameRecords[i];

                foreach (string key in fr.Values.Paths)
                {
                    foreach (string group in groups)
                    {
                        if (key.Contains(group))
                        {
                            if (stats.m_groupStats.Count == 0 || !stats.ContainsGroup(group))
                            {
                                stats.m_groupStats.Add(group, new GroupItemStats());
                            }

                            GroupItemStats groupItemStats = stats.GetGroupItemsStats(group);

                            string itemKey = key.Substring(key.LastIndexOf('/') + 1);

                            if (!groupItemStats.ContainsItem(itemKey))
                            {
                                groupItemStats.m_groupItemStats.Add(itemKey, new Stats());
                            }

                            Stats itemStats = groupItemStats.GetItemStats(itemKey);
                            itemStats.m_min  = Math.Min(itemStats.m_min, fr.Values[key]);
                            itemStats.m_max  = Math.Max(itemStats.m_max, fr.Values[key]);
                            itemStats.m_avg += fr.Values[key];
                        }
                    }
                }
            }

            foreach (string group in stats.m_groupStats.Keys)
            {
                foreach (string item in stats.GetGroupItemsStats(group).m_groupItemStats.Keys)
                {
                    Stats itemStats = stats.GetGroupItemsStats(group).GetItemStats(item);
                    itemStats.m_avg /= (toFrameIdx - fromFrameIdx + 1);
                }
            }
        }
示例#2
0
        public void UploadStatsDataPage(PageMetaData pageMetaData, LogData logData, string [] groups, XmlNodeList metrics, bool upload)
        {
            StatisticsRemotePage page = CreateStatisticsPage(pageMetaData, logData, groups);

            if (upload)
            {
                GroupsStats stats = new GroupsStats();
                logData.GetFrameGroupData(0, logData.FrameRecords.Count - 1, groups, stats);
                Random random = new Random();
                foreach (string group in stats.m_groupStats.Keys)
                {
                    page.m_page.content += "\n\n";
                    GroupItemStats groupsStats = stats.GetGroupItemsStats(group);
                    foreach (string item in groupsStats.m_groupItemStats.Keys)
                    {
                        float  target = 0.0f;
                        float  max    = 0.0f;
                        float  min    = 0.0f;
                        float  fail   = 0.0f;
                        string path   = "/" + group + "/" + item;
                        string units  = "";                        // logData.FrameRecords[0].m_units[path];

                        foreach (XmlNode node in metrics)
                        {
                            XmlNode attribute = node.Attributes.GetNamedItem("name");
                            if (attribute.Value == item)
                            {
                                XmlNode metricNode = node.ChildNodes.Item(0);
                                if (metricNode != null)
                                {
                                    if (metricNode.Attributes.GetNamedItem("target") != null)
                                    {
                                        target = (float)int.Parse(metricNode.Attributes.GetNamedItem("target").Value);
                                    }
                                    if (metricNode.Attributes.GetNamedItem("heatMax") != null)
                                    {
                                        max = (float)int.Parse(metricNode.Attributes.GetNamedItem("heatMax").Value) + target;
                                    }
                                    if (metricNode.Attributes.GetNamedItem("heatMin") != null)
                                    {
                                        min = (float)int.Parse(metricNode.Attributes.GetNamedItem("heatMin").Value);
                                    }
                                    if (metricNode.Attributes.GetNamedItem("failure") != null)
                                    {
                                        fail = (float)int.Parse(metricNode.Attributes.GetNamedItem("failure").Value) + target;
                                    }
                                    break;
                                }
                            }
                        }

                        Stats statitem = groupsStats.GetItemStats(item);
                        page.m_page.content += "+*Statistic*: {color:blue}" + group + " - " + item + "{color}+\n\n";
                        page.AddStatOverview(Math.Max(0.0f, statitem.m_min), Math.Max(0.0f, statitem.m_max), Math.Max(0.0f, statitem.m_avg), max, target);
                        page.StartCanvasSection(random.Next());
                        page.AddTimeLineGraph(group, item, statitem, max, target, units);
                        page.EndCanvasSection();
                    }
                }
            }

            StorePage(page.m_page);
            AddAttachment(Compress(pageMetaData.m_contentMetaData.m_logFilename), pageMetaData.m_title, pageMetaData.m_parentTitle, pageMetaData.m_space, "Statoscope Log");
        }
示例#3
0
        static bool WriteXMLForLog(string logFilename, string[] groups)
        {
            FileLogProcessor logProcessor = new FileLogProcessor(logFilename);
            LogData          logData      = logProcessor.ProcessLog();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = ("    ");

            char[]   delims           = { '.' };
            string[] fileNameElements = logFilename.Split(delims);
            if (fileNameElements.Length < 2)
            {
                Console.WriteLine("Input file name not parseable {0} : Canceling XML Write", logFilename);
                return(false);
            }

            string outputFile = fileNameElements[0] + ".xml";

            Console.WriteLine("Writing XML output: {0}", outputFile);

            using (XmlWriter writer = XmlWriter.Create(outputFile, settings))
            {
                writer.WriteStartElement("testsuites");
                CultureInfo decimalCulture = new CultureInfo("en-US");

                UserMarkerLocation currentStartMarker = null;
                writer.WriteStartElement("testsuite");
                writer.WriteAttributeString("name", "BasicPerformance");

                foreach (FrameRecord fr in logData.FrameRecords)
                {
                    foreach (UserMarkerLocation markerLocation in fr.UserMarkers)
                    {
                        if (markerLocation.m_name.Split(' ')[0].EndsWith("_start"))
                        {
                            if (currentStartMarker != null)
                            {
                                //Warn about unmatched start marker
                                Console.WriteLine("Warning: Performance Marker End Not Found For {0} at frame index: {1} : Skipping", currentStartMarker.m_name, currentStartMarker.m_fr.Index);
                            }
                            currentStartMarker = markerLocation;
                            continue;
                        }

                        if (markerLocation.m_name.EndsWith("_end"))
                        {
                            if (currentStartMarker == null)
                            {
                                //Warn and skip if we didn't have a start marker we were looking for
                                Console.WriteLine("Warning: Performance Marker End Found With No Matching Start For {0} at frame index: {1} : Skipping", currentStartMarker != null ? currentStartMarker.m_name : "invalid start marker", currentStartMarker != null ? currentStartMarker.m_fr.Index : 0);
                                continue;
                            }

                            string markerNameStart  = currentStartMarker.m_name.Replace("_start", "").Split(' ')[0];
                            string markerExportName = currentStartMarker.m_name.Replace("_start", "");
                            string markerNameEnd    = markerLocation.m_name.Replace("_end", "");

                            if (markerNameStart != markerNameEnd)
                            {
                                Console.WriteLine("Warning: Performance Marker End: {0} Does not Match Start Marker {1}: Skipping", markerNameStart, markerNameEnd);
                                currentStartMarker = null;
                                continue;
                            }

                            int startIdx = currentStartMarker.m_fr.Index;
                            int endIdx   = markerLocation.m_fr.Index;
                            currentStartMarker = null;

                            writer.WriteStartElement("phase");
                            writer.WriteAttributeString("name", markerExportName);
                            writer.WriteAttributeString("duration", (logData.FrameRecords[endIdx].FrameTimeInS - logData.FrameRecords[startIdx].FrameTimeInS).ToString(decimalCulture));
                            {
                                float minFrameTime, maxFrameTime, avgFrameTime;
                                logData.GetFrameTimeData(startIdx, endIdx, out minFrameTime, out maxFrameTime, out avgFrameTime);

                                writer.WriteStartElement("metrics");
                                writer.WriteAttributeString("name", "frameTimes");

                                writer.WriteStartElement("metric");
                                writer.WriteAttributeString("name", "min");
                                writer.WriteAttributeString("value", minFrameTime.ToString(decimalCulture));
                                writer.WriteEndElement();

                                writer.WriteStartElement("metric");
                                writer.WriteAttributeString("name", "max");
                                writer.WriteAttributeString("value", maxFrameTime.ToString(decimalCulture));
                                writer.WriteEndElement();

                                writer.WriteStartElement("metric");
                                writer.WriteAttributeString("name", "avg");
                                writer.WriteAttributeString("value", avgFrameTime.ToString(decimalCulture));
                                writer.WriteEndElement();

                                writer.WriteEndElement();
                            }
                            writer.WriteEndElement();
                        }
                    }
                }
                //End testsuite block
                writer.WriteEndElement();

                if (groups != null)
                {
                    currentStartMarker = null;
                    writer.WriteStartElement("testsuite");
                    writer.WriteAttributeString("name", "GroupStatistics");

                    foreach (FrameRecord fr in logData.FrameRecords)
                    {
                        foreach (UserMarkerLocation markerLocation in fr.UserMarkers)
                        {
                            if (markerLocation.m_name.Split(' ')[0].EndsWith("_start"))
                            {
                                if (currentStartMarker != null)
                                {
                                    //Warn about unmatched start marker
                                    Console.WriteLine("Warning: Performance Marker End Not Found For {0} at frame index: {1} : Skipping", currentStartMarker.m_name, currentStartMarker.m_fr.Index);
                                }
                                currentStartMarker = markerLocation;
                                continue;
                            }

                            if (markerLocation.m_name.EndsWith("_end"))
                            {
                                if (currentStartMarker == null)
                                {
                                    //Warn and skip if we didn't have a start marker we were looking for
                                    Console.WriteLine("Warning: Performance Marker End Found With No Matching Start For {0} at frame index: {1} : Skipping", currentStartMarker != null ? currentStartMarker.m_name : "invalid start marker", currentStartMarker != null ? currentStartMarker.m_fr.Index : 0);
                                    continue;
                                }

                                string markerNameStart  = currentStartMarker.m_name.Replace("_start", "").Split(' ')[0];
                                string markerExportName = currentStartMarker.m_name.Replace("_start", "");
                                string markerNameEnd    = markerLocation.m_name.Replace("_end", "");

                                if (markerNameStart != markerNameEnd)
                                {
                                    Console.WriteLine("Warning: Performance Marker End: {0} Does not Match Start Marker {1}: Skipping", markerNameStart, markerNameEnd);
                                    currentStartMarker = null;
                                    continue;
                                }

                                int startIdx = currentStartMarker.m_fr.Index;
                                int endIdx   = markerLocation.m_fr.Index;
                                currentStartMarker = null;

                                writer.WriteStartElement("phase");
                                writer.WriteAttributeString("name", markerExportName);
                                writer.WriteAttributeString("duration", (logData.FrameRecords[endIdx].FrameTimeInS - logData.FrameRecords[startIdx].FrameTimeInS).ToString(decimalCulture));
                                {
                                    GroupsStats stats = new GroupsStats();
                                    logData.GetFrameGroupData(startIdx, endIdx, groups, stats);
                                    foreach (string group in stats.m_groupStats.Keys)
                                    {
                                        GroupItemStats groupsStats = stats.GetGroupItemsStats(group);
                                        foreach (string item in groupsStats.m_groupItemStats.Keys)
                                        {
                                            Stats itemStats = groupsStats.GetItemStats(item);
                                            writer.WriteStartElement("metrics");
                                            writer.WriteAttributeString("name", item);

                                            writer.WriteStartElement("metric");
                                            writer.WriteAttributeString("name", "min");
                                            writer.WriteAttributeString("value", itemStats.m_min.ToString(decimalCulture));
                                            writer.WriteEndElement();

                                            writer.WriteStartElement("metric");
                                            writer.WriteAttributeString("name", "max");
                                            writer.WriteAttributeString("value", itemStats.m_max.ToString(decimalCulture));
                                            writer.WriteEndElement();

                                            writer.WriteStartElement("metric");
                                            writer.WriteAttributeString("name", "avg");
                                            writer.WriteAttributeString("value", itemStats.m_avg.ToString(decimalCulture));
                                            writer.WriteEndElement();

                                            writer.WriteEndElement();
                                        }
                                    }
                                }
                                writer.WriteEndElement();
                            }
                        }
                    }
                    //End testsuite block
                    writer.WriteEndElement();
                }

                //End testsuites block
                writer.WriteEndElement();
                writer.Flush();

                return(true);
            }
        }