///<summary> /// Get Connections count /// </summary> public static double GetConnectionsCount(LrAnalysis lrAnalysis) { double connectionsCount = 0; try { Graph g; // check if Connections graph has data if (lrAnalysis.Session.Runs[0].Graphs.TryGetValue("Connections", out g) != true) { throw new Exception("Failed to retrieve values from Connections graph"); } if (g.Series.Count == 0) { throw new Exception("No data exists in Connections graph"); } g.Granularity = 1; foreach (FilterItem fi in g.Filter) { fi.ClearValues(); fi.IsActive = false; g.ApplyFilterAndGroupBy(); } g.ApplyFilterAndGroupBy(); connectionsCount = g.Series["Connections"].GraphStatistics.Maximum; if (!HasValue(connectionsCount)) { connectionsCount = -1; } } catch (Exception ex) { Console.Write(Resources.Helper_GetConnectionsCount_ + ex.Message); } return connectionsCount; }
///<summary> /// Get Connections count /// </summary> public static double GetConnectionsCount(LrAnalysis lrAnalysis) { double connectionsCount = 0; try { Graph g; // check if Connections graph has data if (lrAnalysis.Session.Runs[0].Graphs.TryGetValue("Connections", out g) != true) { throw new Exception("Failed to retrieve values from Connections graph"); } if (g.Series.Count == 0) { throw new Exception("No data exists in Connections graph"); } g.Granularity = 1; foreach (FilterItem fi in g.Filter) { fi.ClearValues(); fi.IsActive = false; g.ApplyFilterAndGroupBy(); } g.ApplyFilterAndGroupBy(); connectionsCount = g.Series["Connections"].GraphStatistics.Maximum; if (!HasValue(connectionsCount)) { connectionsCount = -1; } } catch (Exception ex) { Console.Write(Resources.Helper_GetConnectionsCount_ + ex.Message); } return(connectionsCount); }
/// <summary> /// Calculating the number of transactions by status /// </summary> /// <returns>Transactions by status</returns> public static Dictionary<string, Dictionary<string, double>> CalcFailedTransPercent(LrAnalysis lrAnalysis) { var transDictionary = new Dictionary<string, Dictionary<string, double>>(); //Console.WriteLine("Adding Transaction statistics"); //var transactionGraph = lrAnalysis.Session.OpenGraph("TransactionSummary"); //if (transactionGraph == null) //{ // return transDictionary; //} //transactionGraph.Filter.Reset(); //transactionGraph.Granularity = 4; //FilterItem filterDimension; //if (!transactionGraph.Filter.TryGetValue("Transaction End Status", out filterDimension)) //{ // return transDictionary; //} //foreach (var series in transactionGraph.Series) //{ // SeriesAttributeValue a; // if (!series.Attributes.TryGetValue("Event Name", out a)) continue; // SeriesAttributeValue transEndStatusAttr; // if (!series.Attributes.TryGetValue("Transaction End Status", out transEndStatusAttr)) continue; // Dictionary<string, double> value; // if (!transDictionary.TryGetValue(a.Value.ToString(), out value)) // { // transDictionary.Add(a.Value.ToString(), // new Dictionary<string, double>() {{"Pass", 0}, {"Fail", 0}, {"Stop", 0}}); // } // (transDictionary[a.Value.ToString()])[transEndStatusAttr.Value.ToString()] = series.Points[0].Value; //} return transDictionary; }
static int Main(string[] args) { log("starting analysis launcher"); int iPassed = (int)Launcher.ExitCodeEnum.Passed;//variable to keep track of whether all of the SLAs passed try { if (args.Length != 3) { ShowHelp(); return (int)Launcher.ExitCodeEnum.Aborted; } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; log("creating analysis COM object"); LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; log("creating analysis session"); if (session.Create(lralocation, lrrlocation)) { log("analysis session created"); log("creating HTML reports"); HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); log("HTML reports created"); XmlDocument xmlDoc = new XmlDocument(); log("loading errors, if any"); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { log("error count: " + session.ErrorMessages.Count); if (session.ErrorMessages.Count > 1000) { log("more then 1000 error during scenario run, analyzing only the first 1000."); } log(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); int limit = 1000; ErrorMessage[] errors = session.ErrorMessages.ToArray(); //foreach (ErrorMessage err in session.ErrorMessages) for (int i = 0; i < limit && i < errors.Length; i++) { ErrorMessage err = errors[i]; XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); log("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); log (""); } log("closing session"); session.Close(); log(Resources.SLAReportTitle); log("calculating SLA"); SlaResult slaResult = Session.CalculateSla(lralocation, true); log("SLA calculation done"); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); int iCounter = 0; // set counter log("WholeRunRules : " + slaResult.WholeRunRules.Count); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { log(Resources.DoubleLineSeperator); XmlElement elem; if (a.Measurement.Equals(SlaMeasurement.PercentileTRT)) { SlaPercentileRuleResult b = slaResult.TransactionRules.PercentileRules[iCounter]; elem = xmlDoc.CreateElement(b.RuleName.Replace(" ", "_")); //no white space in the element name log("Transaction Name : " + b.TransactionName); elem.SetAttribute("TransactionName", b.TransactionName.ToString()); log("Percentile : " + b.Percentage); elem.SetAttribute("Percentile", b.Percentage.ToString()); elem.SetAttribute("FullName", b.RuleUiName); log("Full Name : " + b.RuleUiName); log("Measurement : " + b.Measurement); elem.SetAttribute("Measurement", b.Measurement.ToString()); log("Goal Value : " + b.GoalValue); elem.SetAttribute("GoalValue", b.GoalValue.ToString()); log("Actual value : " + b.ActualValue); elem.SetAttribute("ActualValue", b.ActualValue.ToString()); log("status : " + b.Status); elem.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { elem = xmlDoc.CreateElement(a.RuleName.Replace(" ", "_")); //no white space in the element name elem.SetAttribute("FullName", a.RuleUiName); log("Full Name : " + a.RuleUiName); log("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); log("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); log("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); log("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(elem); log(Resources.DoubleLineSeperator); } iCounter = 0; // reset counter log("TimeRangeRules : " + slaResult.TimeRangeRules.Count); foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { log(Resources.DoubleLineSeperator); XmlElement rule; if (a.Measurement.Equals(SlaMeasurement.AverageTRT)) { SlaTransactionTimeRangeRuleResult b = slaResult.TransactionRules.TimeRangeRules[iCounter]; rule = xmlDoc.CreateElement(b.RuleName.Replace(" ", "_")); //no white space in the element name log("Transaction Name: " + b.TransactionName); rule.SetAttribute("TransactionName", b.TransactionName); log("Full Name : " + b.RuleUiName); rule.SetAttribute("FullName", b.RuleUiName); log("Measurement : " + b.Measurement); rule.SetAttribute("Measurement", b.Measurement.ToString()); log("SLA Load Threshold Value : " + b.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", b.CriteriaMeasurement.ToString()); log("LoadThresholds : " + b.LoadThresholds.Count); foreach (SlaLoadThreshold slat in b.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + b.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in b.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + b.Status); rule.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { rule = xmlDoc.CreateElement(a.RuleName.Replace(" ", "_")); //no white space in the element name log("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); log("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); log("SLA Load Threshold Value : " + a.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", a.CriteriaMeasurement.ToString()); log("LoadThresholds : " + a.LoadThresholds.Count); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + a.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(rule); log(Resources.DoubleLineSeperator); } //write XML to location: log("saving SLA.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { log(Resources.CannotCreateSession); return (int)Launcher.ExitCodeEnum.Aborted; } log("closing analysis session"); session.Close(); } catch (TypeInitializationException ex) { if (ex.InnerException is UnauthorizedAccessException) log("UnAuthorizedAccessException: Please check the account privilege of current user, LoadRunner tests should be run by administrators."); else { log(ex.Message); log(ex.StackTrace); } return (int)Launcher.ExitCodeEnum.Aborted; } catch (Exception e) { log(e.Message); log(e.StackTrace); return (int)Launcher.ExitCodeEnum.Aborted; } // return SLA status code, if any SLA fails return a fail here. // writer.Flush(); // writer.Close(); return iPassed; }
static int Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.GetEncoding("utf-8"); log("starting analysis launcher"); int iPassed = (int)Launcher.ExitCodeEnum.Passed;//variable to keep track of whether all of the SLAs passed try { if (args.Length != 3) { ShowHelp(); return((int)Launcher.ExitCodeEnum.Aborted); } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; log("creating analysis COM object"); LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; log("creating analysis session"); if (session.Create(lralocation, lrrlocation)) { log("analysis session created"); log("creating HTML reports"); HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); log("HTML reports created"); XmlDocument xmlDoc = new XmlDocument(); log("loading errors, if any"); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { log("error count: " + session.ErrorMessages.Count); if (session.ErrorMessages.Count > 1000) { log("more then 1000 error during scenario run, analyzing only the first 1000."); } log(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); int limit = 1000; ErrorMessage[] errors = session.ErrorMessages.ToArray(); //foreach (ErrorMessage err in session.ErrorMessages) for (int i = 0; i < limit && i < errors.Length; i++) { ErrorMessage err = errors[i]; XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); log("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); log(""); } log("closing session"); session.Close(); log(Resources.SLAReportTitle); log("calculating SLA"); SlaResult slaResult = Session.CalculateSla(lralocation, true); log("SLA calculation done"); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); int iCounter = 0; // set counter log("WholeRunRules : " + slaResult.WholeRunRules.Count); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { log(Resources.DoubleLineSeperator); XmlElement elem; if (a.Measurement.Equals(SlaMeasurement.PercentileTRT)) { SlaPercentileRuleResult b = slaResult.TransactionRules.PercentileRules[iCounter]; elem = xmlDoc.CreateElement(b.RuleName.Replace(" ", "_")); //no white space in the element name log("Transaction Name : " + b.TransactionName); elem.SetAttribute("TransactionName", b.TransactionName.ToString()); log("Percentile : " + b.Percentage); elem.SetAttribute("Percentile", b.Percentage.ToString()); elem.SetAttribute("FullName", b.RuleUiName); log("Full Name : " + b.RuleUiName); log("Measurement : " + b.Measurement); elem.SetAttribute("Measurement", b.Measurement.ToString()); log("Goal Value : " + b.GoalValue); elem.SetAttribute("GoalValue", b.GoalValue.ToString()); log("Actual value : " + b.ActualValue); elem.SetAttribute("ActualValue", b.ActualValue.ToString()); log("status : " + b.Status); elem.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { elem = xmlDoc.CreateElement(a.RuleName.Replace(" ", "_")); //no white space in the element name elem.SetAttribute("FullName", a.RuleUiName); log("Full Name : " + a.RuleUiName); log("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); log("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); log("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); log("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(elem); log(Resources.DoubleLineSeperator); } iCounter = 0; // reset counter log("TimeRangeRules : " + slaResult.TimeRangeRules.Count); foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { log(Resources.DoubleLineSeperator); XmlElement rule; if (a.Measurement.Equals(SlaMeasurement.AverageTRT)) { SlaTransactionTimeRangeRuleResult b = slaResult.TransactionRules.TimeRangeRules[iCounter]; rule = xmlDoc.CreateElement(b.RuleName.Replace(" ", "_")); //no white space in the element name log("Transaction Name: " + b.TransactionName); rule.SetAttribute("TransactionName", b.TransactionName); log("Full Name : " + b.RuleUiName); rule.SetAttribute("FullName", b.RuleUiName); log("Measurement : " + b.Measurement); rule.SetAttribute("Measurement", b.Measurement.ToString()); log("SLA Load Threshold Value : " + b.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", b.CriteriaMeasurement.ToString()); log("LoadThresholds : " + b.LoadThresholds.Count); foreach (SlaLoadThreshold slat in b.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + b.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in b.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + b.Status); rule.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { rule = xmlDoc.CreateElement(a.RuleName.Replace(" ", "_")); //no white space in the element name log("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); log("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); log("SLA Load Threshold Value : " + a.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", a.CriteriaMeasurement.ToString()); log("LoadThresholds : " + a.LoadThresholds.Count); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + a.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(rule); log(Resources.DoubleLineSeperator); } //write XML to location: log("saving SLA.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { log(Resources.CannotCreateSession); return((int)Launcher.ExitCodeEnum.Aborted); } log("closing analysis session"); session.Close(); } catch (TypeInitializationException ex) { if (ex.InnerException is UnauthorizedAccessException) { log("UnAuthorizedAccessException: Please check the account privilege of current user, LoadRunner tests should be run by administrators."); } else { log(ex.Message); log(ex.StackTrace); } return((int)Launcher.ExitCodeEnum.Aborted); } catch (Exception e) { log(e.Message); log(e.StackTrace); return((int)Launcher.ExitCodeEnum.Aborted); } // return SLA status code, if any SLA fails return a fail here. // writer.Flush(); // writer.Close(); return(iPassed); }
static int Main(string[] args) { HpToolsLauncher.ConsoleQuickEdit.Disable(); Console.OutputEncoding = System.Text.Encoding.GetEncoding("utf-8"); log("starting analysis launcher"); int iPassed = (int)Launcher.ExitCodeEnum.Passed;//variable to keep track of whether all of the SLAs passed try { //The app uses 3 default arguments, a 4th optional one can be used to specify the path to an analysis template if (args.Length != 3 && args.Length != 4) { ShowHelp(); return((int)Launcher.ExitCodeEnum.Aborted); } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; string analysisTemplateLocation = (args.Length == 4 ? args[3] : ""); log("creating analysis COM object"); LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; log("creating analysis session"); //Apply a template and create LRA folder if (session.CreateWithTemplateFile(lralocation, lrrlocation, analysisTemplateLocation)) { log("analysis session created"); log("creating HTML reports"); HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.AddGraph("Connections"); reportMaker.AddGraph("ConnectionsPerSecond"); reportMaker.CreateDefaultHtmlReport( Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport( Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); log("HTML reports created"); XmlDocument xmlDoc = new XmlDocument(); log("loading errors, if any"); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { log("error count: " + session.ErrorMessages.Count); if (session.ErrorMessages.Count > 1000) { log("more then 1000 error during scenario run, analyzing only the first 1000."); } log(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); int limit = 1000; ErrorMessage[] errors = session.ErrorMessages.ToArray(); //foreach (ErrorMessage err in session.ErrorMessages) for (int i = 0; i < limit && i < errors.Length; i++) { ErrorMessage err = errors[i]; XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); log("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); log(""); } XmlDocument runReprotDoc = new XmlDocument(); log("Gathering Run statistics"); XmlElement runsRoot = runReprotDoc.CreateElement("Runs"); runReprotDoc.AppendChild(runsRoot); XmlElement general = runReprotDoc.CreateElement("General"); runsRoot.AppendChild(general); XmlElement durationElement = runReprotDoc.CreateElement("Time"); durationElement.SetAttribute("End", "-1"); durationElement.SetAttribute("Start", "-1"); durationElement.SetAttribute("Duration", "-1"); Stopper stopper = new Stopper(10000); stopper.Start(); //foreach (Run currentRun in analysis.Session.Runs) //{ // stopper.Start(); // log("Gathering Duration statistics"); // stopper.Start(); //DateTime startTime = Helper.FromUnixTime(currentRun.StartTime); //DateTime endTime = Helper.FromUnixTime(currentRun.EndTime); //durationElement.SetAttribute("End", endTime.ToString()); //durationElement.SetAttribute("Start", startTime.ToString()); //durationElement.SetAttribute("Duration", Helper.GetScenarioDuration(currentRun)); //} general.AppendChild(durationElement); XmlElement vUsers = runReprotDoc.CreateElement("VUsers"); //log("Adding VUser statistics"); Dictionary <string, int> vuserCountDictionary = new Dictionary <string, int>(4) { { "Passed", 0 }, { "Stopped", 0 }, { "Failed", 0 }, { "Error", 0 } }; //vuserCountDictionary = Helper.GetVusersCountByStatus(analysis); foreach (KeyValuePair <string, int> kvp in vuserCountDictionary) { //log(msg: String.Format("{0} vUsers: {1}", kvp.Key, kvp.Value)); vUsers.SetAttribute(kvp.Key, kvp.Value.ToString()); } vUsers.SetAttribute("Count", session.VUsers.Count.ToString()); general.AppendChild(vUsers); XmlElement transactions = runReprotDoc.CreateElement("Transactions"); Dictionary <string, double> transactionSumStatusDictionary = new Dictionary <string, double>() { { "Count", 0 }, { "Pass", 0 }, { "Fail", 0 }, { "Stop", 0 } }; Dictionary <string, Dictionary <string, double> > transactionDictionary = Helper.CalcFailedTransPercent(analysis); foreach (KeyValuePair <string, Dictionary <string, double> > kvp in transactionDictionary) { XmlElement transaction = runReprotDoc.CreateElement("Transaction"); foreach (var transStatus in kvp.Value) { transaction.SetAttribute(transStatus.Key, transStatus.Value.ToString()); transactionSumStatusDictionary[transStatus.Key] += transStatus.Value; transactionSumStatusDictionary["Count"] += transStatus.Value; } transaction.SetAttribute("Name", kvp.Key); transactions.AppendChild(transaction); } foreach (var transStatus in transactionSumStatusDictionary) { transactions.SetAttribute(transStatus.Key, transStatus.Value.ToString()); //log(msg: String.Format("{0} transaction: {1}", transStatus.Key, transStatus.Value)); } general.AppendChild(transactions); string connectionsMaximum = "0"; //connectionsMaximum = Helper.GetConnectionsCount(analysis).ToString(); XmlElement connections = runReprotDoc.CreateElement("Connections"); connections.SetAttribute("MaxCount", connectionsMaximum); general.AppendChild(connections); log(""); log("closing session"); session.Close(); log(Resources.SLAReportTitle); log("calculating SLA"); SlaResult slaResult = Session.CalculateSla(lralocation, true); log("SLA calculation done"); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); int iCounter = 0; // set counter log("WholeRunRules : " + slaResult.WholeRunRules.Count); CultureInfo formatProvider = new CultureInfo("en-US"); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { log(Resources.DoubleLineSeperator); XmlElement elem; if (a.Measurement.Equals(SlaMeasurement.PercentileTRT)) { SlaPercentileRuleResult b = slaResult.TransactionRules.PercentileRules[iCounter]; elem = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Transaction Name : " + b.TransactionName); elem.SetAttribute("TransactionName", b.TransactionName.ToString()); log("Percentile : " + b.Percentage); elem.SetAttribute("Percentile", b.Percentage.ToString(formatProvider)); elem.SetAttribute("FullName", b.RuleUiName); log("Full Name : " + b.RuleUiName); log("Measurement : " + b.Measurement); elem.SetAttribute("Measurement", b.Measurement.ToString()); log("Goal Value : " + b.GoalValue); elem.SetAttribute("GoalValue", b.GoalValue.ToString(formatProvider)); log("Actual value : " + b.ActualValue); elem.SetAttribute("ActualValue", b.ActualValue.ToString(formatProvider)); log("status : " + b.Status); elem.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { elem = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name elem.SetAttribute("FullName", a.RuleUiName); log("Full Name : " + a.RuleUiName); log("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); log("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString(formatProvider)); log("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString(formatProvider)); log("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(elem); log(Resources.DoubleLineSeperator); } iCounter = 0; // reset counter log("TimeRangeRules : " + slaResult.TimeRangeRules.Count); foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { log(Resources.DoubleLineSeperator); XmlElement rule; if (a.Measurement.Equals(SlaMeasurement.AverageTRT)) { SlaTransactionTimeRangeRuleResult b = slaResult.TransactionRules.TimeRangeRules[iCounter]; rule = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Transaction Name: " + b.TransactionName); rule.SetAttribute("TransactionName", b.TransactionName); log("Full Name : " + b.RuleUiName); rule.SetAttribute("FullName", b.RuleUiName); log("Measurement : " + b.Measurement); rule.SetAttribute("Measurement", b.Measurement.ToString()); log("SLA Load Threshold Value : " + b.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", b.CriteriaMeasurement.ToString()); log("LoadThresholds : " + b.LoadThresholds.Count); foreach (SlaLoadThreshold slat in b.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString(formatProvider)); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString(formatProvider)); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString(formatProvider)); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + b.TimeRanges.Count); int passed = 0; int failed = 0; int noData = 0; foreach (SlaTimeRangeInfo slatri in b.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString(formatProvider)); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString(formatProvider)); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString(formatProvider)); subsubelem.InnerText = slatri.Status.ToString(); switch (slatri.Status) { case SlaRuleStatus.Failed: failed++; break; case SlaRuleStatus.Passed: passed++; break; case SlaRuleStatus.NoData: noData++; break; default: break; } timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); SlaRuleStatus currentRuleStatus = b.Status; if (currentRuleStatus.Equals(SlaRuleStatus.NoData) && (passed > noData)) { currentRuleStatus = SlaRuleStatus.Passed; } log("status : " + currentRuleStatus); rule.AppendChild(xmlDoc.CreateTextNode(currentRuleStatus.ToString())); if (currentRuleStatus.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { rule = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); log("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); log("SLA Load Threshold Value : " + a.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", a.CriteriaMeasurement.ToString()); log("LoadThresholds : " + a.LoadThresholds.Count); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString(formatProvider)); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString(formatProvider)); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString(formatProvider)); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + a.TimeRanges.Count); int passed = 0; int failed = 0; int noData = 0; foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString(formatProvider)); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString(formatProvider)); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString(formatProvider)); subsubelem.InnerText = slatri.Status.ToString(); switch (slatri.Status) { case SlaRuleStatus.Failed: failed++; break; case SlaRuleStatus.Passed: passed++; break; case SlaRuleStatus.NoData: noData++; break; default: break; } timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); SlaRuleStatus currentRuleStatus = a.Status; if (currentRuleStatus.Equals(SlaRuleStatus.NoData) && (passed > noData)) { currentRuleStatus = SlaRuleStatus.Passed; } log("status : " + currentRuleStatus); rule.AppendChild(xmlDoc.CreateTextNode(currentRuleStatus.ToString())); if (currentRuleStatus.Equals(SlaRuleStatus.Failed)) { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(rule); log(Resources.DoubleLineSeperator); } XmlNode slaNode = runReprotDoc.ImportNode(root, true); runsRoot.AppendChild(slaNode); log("saving RunReport.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "RunReport.xml")); runReprotDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "RunReport.xml")); runReprotDoc.RemoveAll(); //write XML to location: log("saving SLA.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { log(Resources.CannotCreateSession); return((int)Launcher.ExitCodeEnum.Aborted); } log("closing analysis session"); session.Close(); } catch (TypeInitializationException ex) { if (ex.InnerException is UnauthorizedAccessException) { log( "UnAuthorizedAccessException: Please check the account privilege of current user, LoadRunner tests should be run by administrators."); } else { log(ex.Message); log(ex.StackTrace); } return((int)Launcher.ExitCodeEnum.Aborted); } catch (Exception e) { log(e.Message); log(e.StackTrace); return((int)Launcher.ExitCodeEnum.Aborted); } // return SLA status code, if any SLA fails return a fail here. // writer.Flush(); // writer.Close(); return(iPassed); }
/// <summary> /// Returns the number of run vusers from VuserStateGraph graph /// </summary> /// <returns>Number of run vusers per catagory</returns> public static Dictionary <string, int> GetVusersCountByStatus(LrAnalysis lrAnalysis) { var vuserDictionary = new Dictionary <string, int>(4) { { "Passed", 0 }, { "Stopped", 0 }, { "Failed", 0 }, { "Error", 0 } }; lrAnalysis.Session.VUsers.LoadValuesIfNeeded(); Graph vUserGraph = lrAnalysis.Session.OpenGraph("VuserStateGraph"); if (vUserGraph == null) { return(vuserDictionary); } List <String> vUserStates = new List <String>() { { "Passed" }, { "Stopped" }, { "Failed" }, { "Error" } }; try { Console.Write("Counting vUser Results for this scenario from "); FilterItem filterDimensionVUser; FilterItem item; Series vuserRanSeries; vUserGraph.Filter.Reset(); Console.Write(vUserGraph.Name); if (vUserGraph.Filter.TryGetValue("Vuser Status", out filterDimensionVUser) && vUserGraph.Filter.TryGetValue("Vuser End Status", out item)) { filterDimensionVUser.ClearValues(); item.ClearValues(); Console.Write(" by "); foreach (string vUserEndStatus in item.AvailableValues.DiscreteValues) { item.ClearValues(); Console.Write(vUserEndStatus + " "); item.AddDiscreteValue(vUserEndStatus); vUserGraph.ApplyFilterAndGroupBy(); if (vUserGraph.Series.TryGetValue("Quit", out vuserRanSeries)) { if (!vuserRanSeries.GraphStatistics.IsFunctionAvailable(StatisticsFunctionKind.Maximum)) { continue; } double vUserTypeMax = vuserRanSeries.GraphStatistics.Maximum; if (!HasValue(vUserTypeMax)) { continue; } vuserDictionary[vUserEndStatus] = (int)Math.Round(vUserTypeMax); } } Console.WriteLine(""); } ConsoleWriter.WriteLine("Getting maximum ran vUsers this scenarion"); var vUserStateGraph = lrAnalysis.Session.OpenGraph("VuserStateGraph"); if (vUserStateGraph == null) { return(vuserDictionary); } vUserStateGraph.Granularity = 4; if (vUserStateGraph.Filter.TryGetValue("Vuser Status", out filterDimensionVUser) && vUserStateGraph.Series.TryGetValue("Run", out vuserRanSeries)) { filterDimensionVUser.ClearValues(); vUserGraph.ApplyFilterAndGroupBy(); double vUserMax = vuserRanSeries.GraphStatistics.Maximum; if (!HasValue(vUserMax)) { vUserMax = -1; } vuserDictionary.Add("MaxVuserRun", (int)Math.Round(vUserMax)); ConsoleWriter.WriteLine(String.Format("{0} maximum vUser ran per {1} seconds", vUserMax, vUserStateGraph.Granularity)); } } catch (StackOverflowException exception) { ConsoleWriter.WriteLine(String.Format("Debug: Error on getting VUsers from Analysis" + exception)); } return(vuserDictionary); }
/// <summary> /// Calculating the number of transactions by status /// </summary> /// <returns>Transactions by status</returns> public static Dictionary <string, Dictionary <string, double> > CalcFailedTransPercent(LrAnalysis lrAnalysis) { var transDictionary = new Dictionary <string, Dictionary <string, double> >(); //Console.WriteLine("Adding Transaction statistics"); //var transactionGraph = lrAnalysis.Session.OpenGraph("TransactionSummary"); //if (transactionGraph == null) //{ // return transDictionary; //} //transactionGraph.Filter.Reset(); //transactionGraph.Granularity = 4; //FilterItem filterDimension; //if (!transactionGraph.Filter.TryGetValue("Transaction End Status", out filterDimension)) //{ // return transDictionary; //} //foreach (var series in transactionGraph.Series) //{ // SeriesAttributeValue a; // if (!series.Attributes.TryGetValue("Event Name", out a)) continue; // SeriesAttributeValue transEndStatusAttr; // if (!series.Attributes.TryGetValue("Transaction End Status", out transEndStatusAttr)) continue; // Dictionary<string, double> value; // if (!transDictionary.TryGetValue(a.Value.ToString(), out value)) // { // transDictionary.Add(a.Value.ToString(), // new Dictionary<string, double>() {{"Pass", 0}, {"Fail", 0}, {"Stop", 0}}); // } // (transDictionary[a.Value.ToString()])[transEndStatusAttr.Value.ToString()] = series.Points[0].Value; //} return(transDictionary); }
//args: lrr location, lra location, html report location static int Main(string[] args) { //Console.WriteLine("in LrAnlysisLauncher"); try { if (args.Length != 3) { ShowHelp(); return((int)Launcher.ExitCodeEnum.Aborted); } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; if (session.Create(lralocation, lrrlocation)) { HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); XmlDocument xmlDoc = new XmlDocument(); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { Console.WriteLine(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); foreach (ErrorMessage err in session.ErrorMessages) { XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); Console.WriteLine("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); Console.WriteLine(""); } session.Close(); Console.WriteLine(Resources.SLAReportTitle); SlaResult slaResult = Session.CalculateSla(lralocation, true); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { XmlElement elem = xmlDoc.CreateElement(a.RuleName); Console.WriteLine(Resources.DoubleLineSeperator); elem.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Full Name : " + a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); Console.WriteLine("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); Console.WriteLine("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); Console.WriteLine(Resources.DoubleLineSeperator); root.AppendChild(elem); } foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { XmlElement rule = xmlDoc.CreateElement(a.RuleName); Console.WriteLine(Resources.DoubleLineSeperator); Console.WriteLine("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("CriteriaMeasurement Value : " + a.CriteriaMeasurement); rule.SetAttribute("CriteriaMeasurementValue", a.CriteriaMeasurement.ToString()); Console.WriteLine("LoadThresholds value : "); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); Console.WriteLine("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); root.AppendChild(rule); Console.WriteLine(Resources.DoubleLineSeperator); } //write XML to location: xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { Console.WriteLine(Resources.CannotCreateSession); return((int)Launcher.ExitCodeEnum.Aborted); } session.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return((int)Launcher.ExitCodeEnum.Aborted); } finally { //close analysis? } return((int)Launcher.ExitCodeEnum.Passed); }
/// <summary> /// Returns the number of run vusers from VuserStateGraph graph /// </summary> /// <returns>Number of run vusers per catagory</returns> public static Dictionary<string, int> GetVusersCountByStatus(LrAnalysis lrAnalysis) { var vuserDictionary = new Dictionary<string, int>(4) { {"Passed", 0}, {"Stopped", 0}, {"Failed", 0}, {"Error", 0} }; lrAnalysis.Session.VUsers.LoadValuesIfNeeded(); Graph vUserGraph = lrAnalysis.Session.OpenGraph("VuserStateGraph"); if (vUserGraph == null) { return vuserDictionary; } List<String> vUserStates = new List<String>() { {"Passed"}, {"Stopped"}, {"Failed"}, {"Error"} }; try { Console.Write("Counting vUser Results for this scenario from "); FilterItem filterDimensionVUser; FilterItem item; Series vuserRanSeries; vUserGraph.Filter.Reset(); Console.Write(vUserGraph.Name); if (vUserGraph.Filter.TryGetValue("Vuser Status", out filterDimensionVUser) && vUserGraph.Filter.TryGetValue("Vuser End Status", out item)) { filterDimensionVUser.ClearValues(); item.ClearValues(); Console.Write(" by "); foreach (string vUserEndStatus in item.AvailableValues.DiscreteValues) { item.ClearValues(); Console.Write(vUserEndStatus + " "); item.AddDiscreteValue(vUserEndStatus); vUserGraph.ApplyFilterAndGroupBy(); if (vUserGraph.Series.TryGetValue("Quit", out vuserRanSeries)) { if (!vuserRanSeries.GraphStatistics.IsFunctionAvailable(StatisticsFunctionKind.Maximum)) { continue; } double vUserTypeMax = vuserRanSeries.GraphStatistics.Maximum; if (!HasValue(vUserTypeMax)) { continue; } vuserDictionary[vUserEndStatus] = (int)Math.Round(vUserTypeMax); } } Console.WriteLine(""); } ConsoleWriter.WriteLine("Getting maximum ran vUsers this scenarion"); var vUserStateGraph = lrAnalysis.Session.OpenGraph("VuserStateGraph"); if (vUserStateGraph == null) { return vuserDictionary; } vUserStateGraph.Granularity = 4; if (vUserStateGraph.Filter.TryGetValue("Vuser Status", out filterDimensionVUser) && vUserStateGraph.Series.TryGetValue("Run", out vuserRanSeries)) { filterDimensionVUser.ClearValues(); vUserGraph.ApplyFilterAndGroupBy(); double vUserMax = vuserRanSeries.GraphStatistics.Maximum; if (!HasValue(vUserMax)) { vUserMax = -1; } vuserDictionary.Add("MaxVuserRun", (int)Math.Round(vUserMax)); ConsoleWriter.WriteLine(String.Format("{0} maximum vUser ran per {1} seconds", vUserMax, vUserStateGraph.Granularity)); } } catch (StackOverflowException exception) { ConsoleWriter.WriteLine(String.Format("Debug: Error on getting VUsers from Analysis" + exception)); } return vuserDictionary; }
static int Main(string[] args) { HpToolsLauncher.ConsoleQuickEdit.Disable(); Console.OutputEncoding = System.Text.Encoding.GetEncoding("utf-8"); log("starting analysis launcher"); int iPassed = (int)Launcher.ExitCodeEnum.Passed;//variable to keep track of whether all of the SLAs passed try { if (args.Length != 3) { ShowHelp(); return (int) Launcher.ExitCodeEnum.Aborted; } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; log("creating analysis COM object"); LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; log("creating analysis session"); if (session.Create(lralocation, lrrlocation)) { log("analysis session created"); log("creating HTML reports"); HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.AddGraph("Connections"); reportMaker.AddGraph("ConnectionsPerSecond"); reportMaker.CreateDefaultHtmlReport( Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport( Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); log("HTML reports created"); XmlDocument xmlDoc = new XmlDocument(); log("loading errors, if any"); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { log("error count: " + session.ErrorMessages.Count); if (session.ErrorMessages.Count > 1000) { log("more then 1000 error during scenario run, analyzing only the first 1000."); } log(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); int limit = 1000; ErrorMessage[] errors = session.ErrorMessages.ToArray(); //foreach (ErrorMessage err in session.ErrorMessages) for (int i = 0; i < limit && i < errors.Length; i++) { ErrorMessage err = errors[i]; XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); log("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); log(""); } XmlDocument runReprotDoc = new XmlDocument(); log("Gathering Run statistics"); XmlElement runsRoot = runReprotDoc.CreateElement("Runs"); runReprotDoc.AppendChild(runsRoot); XmlElement general = runReprotDoc.CreateElement("General"); runsRoot.AppendChild(general); XmlElement durationElement = runReprotDoc.CreateElement("Time"); durationElement.SetAttribute("End", "-1"); durationElement.SetAttribute("Start", "-1"); durationElement.SetAttribute("Duration", "-1"); Stopper stopper = new Stopper(10000); stopper.Start(); //foreach (Run currentRun in analysis.Session.Runs) //{ // stopper.Start(); // log("Gathering Duration statistics"); // stopper.Start(); //DateTime startTime = Helper.FromUnixTime(currentRun.StartTime); //DateTime endTime = Helper.FromUnixTime(currentRun.EndTime); //durationElement.SetAttribute("End", endTime.ToString()); //durationElement.SetAttribute("Start", startTime.ToString()); //durationElement.SetAttribute("Duration", Helper.GetScenarioDuration(currentRun)); //} general.AppendChild(durationElement); XmlElement vUsers = runReprotDoc.CreateElement("VUsers"); //log("Adding VUser statistics"); Dictionary<string, int> vuserCountDictionary = new Dictionary<string, int>(4) { {"Passed", 0}, {"Stopped", 0}, {"Failed", 0}, {"Error", 0} }; //vuserCountDictionary = Helper.GetVusersCountByStatus(analysis); foreach (KeyValuePair<string, int> kvp in vuserCountDictionary) { //log(msg: String.Format("{0} vUsers: {1}", kvp.Key, kvp.Value)); vUsers.SetAttribute(kvp.Key, kvp.Value.ToString()); } vUsers.SetAttribute("Count", session.VUsers.Count.ToString()); general.AppendChild(vUsers); XmlElement transactions = runReprotDoc.CreateElement("Transactions"); Dictionary<string, double> transactionSumStatusDictionary = new Dictionary<string, double>() { {"Count", 0}, {"Pass", 0}, {"Fail", 0}, {"Stop", 0} }; Dictionary<string, Dictionary<string, double>> transactionDictionary = Helper.CalcFailedTransPercent(analysis); foreach (KeyValuePair<string, Dictionary<string, double>> kvp in transactionDictionary) { XmlElement transaction = runReprotDoc.CreateElement("Transaction"); foreach (var transStatus in kvp.Value) { transaction.SetAttribute(transStatus.Key, transStatus.Value.ToString()); transactionSumStatusDictionary[transStatus.Key] += transStatus.Value; transactionSumStatusDictionary["Count"] += transStatus.Value; } transaction.SetAttribute("Name", kvp.Key); transactions.AppendChild(transaction); } foreach (var transStatus in transactionSumStatusDictionary) { transactions.SetAttribute(transStatus.Key, transStatus.Value.ToString()); //log(msg: String.Format("{0} transaction: {1}", transStatus.Key, transStatus.Value)); } general.AppendChild(transactions); string connectionsMaximum = "0"; //connectionsMaximum = Helper.GetConnectionsCount(analysis).ToString(); XmlElement connections = runReprotDoc.CreateElement("Connections"); connections.SetAttribute("MaxCount", connectionsMaximum); general.AppendChild(connections); log(""); log("closing session"); session.Close(); log(Resources.SLAReportTitle); log("calculating SLA"); SlaResult slaResult = Session.CalculateSla(lralocation, true); log("SLA calculation done"); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); int iCounter = 0; // set counter log("WholeRunRules : " + slaResult.WholeRunRules.Count); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { log(Resources.DoubleLineSeperator); XmlElement elem; if (a.Measurement.Equals(SlaMeasurement.PercentileTRT)) { SlaPercentileRuleResult b = slaResult.TransactionRules.PercentileRules[iCounter]; elem = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Transaction Name : " + b.TransactionName); elem.SetAttribute("TransactionName", b.TransactionName.ToString()); log("Percentile : " + b.Percentage); elem.SetAttribute("Percentile", b.Percentage.ToString()); elem.SetAttribute("FullName", b.RuleUiName); log("Full Name : " + b.RuleUiName); log("Measurement : " + b.Measurement); elem.SetAttribute("Measurement", b.Measurement.ToString()); log("Goal Value : " + b.GoalValue); elem.SetAttribute("GoalValue", b.GoalValue.ToString()); log("Actual value : " + b.ActualValue); elem.SetAttribute("ActualValue", b.ActualValue.ToString()); log("status : " + b.Status); elem.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int) Launcher.ExitCodeEnum.Failed; } iCounter++; } else { elem = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name elem.SetAttribute("FullName", a.RuleUiName); log("Full Name : " + a.RuleUiName); log("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); log("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); log("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); log("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int) Launcher.ExitCodeEnum.Failed; } } root.AppendChild(elem); log(Resources.DoubleLineSeperator); } iCounter = 0; // reset counter log("TimeRangeRules : " + slaResult.TimeRangeRules.Count); foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { log(Resources.DoubleLineSeperator); XmlElement rule; if (a.Measurement.Equals(SlaMeasurement.AverageTRT)) { SlaTransactionTimeRangeRuleResult b = slaResult.TransactionRules.TimeRangeRules[iCounter]; rule = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Transaction Name: " + b.TransactionName); rule.SetAttribute("TransactionName", b.TransactionName); log("Full Name : " + b.RuleUiName); rule.SetAttribute("FullName", b.RuleUiName); log("Measurement : " + b.Measurement); rule.SetAttribute("Measurement", b.Measurement.ToString()); log("SLA Load Threshold Value : " + b.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", b.CriteriaMeasurement.ToString()); log("LoadThresholds : " + b.LoadThresholds.Count); foreach (SlaLoadThreshold slat in b.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + b.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in b.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + b.Status); rule.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (b.Status.Equals(SlaRuleStatus.Failed)) // 0 = failed { iPassed = (int) Launcher.ExitCodeEnum.Failed; } iCounter++; } else { rule = xmlDoc.CreateElement("SLA_GOAL"); //no white space in the element name log("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); log("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); log("SLA Load Threshold Value : " + a.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", a.CriteriaMeasurement.ToString()); log("LoadThresholds : " + a.LoadThresholds.Count); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); log("TimeRanges : " + a.TimeRanges.Count); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); log("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (a.Status.Equals(SlaRuleStatus.Failed)) { iPassed = (int) Launcher.ExitCodeEnum.Failed; } } root.AppendChild(rule); log(Resources.DoubleLineSeperator); } XmlNode slaNode = runReprotDoc.ImportNode(root, true); runsRoot.AppendChild(slaNode); log("saving RunReport.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "RunReport.xml")); runReprotDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "RunReport.xml")); runReprotDoc.RemoveAll(); //write XML to location: log("saving SLA.xml to " + Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { log(Resources.CannotCreateSession); return (int) Launcher.ExitCodeEnum.Aborted; } log("closing analysis session"); session.Close(); } catch (TypeInitializationException ex) { if (ex.InnerException is UnauthorizedAccessException) log( "UnAuthorizedAccessException: Please check the account privilege of current user, LoadRunner tests should be run by administrators."); else { log(ex.Message); log(ex.StackTrace); } return (int) Launcher.ExitCodeEnum.Aborted; } catch (Exception e) { log(e.Message); log(e.StackTrace); return (int) Launcher.ExitCodeEnum.Aborted; } // return SLA status code, if any SLA fails return a fail here. // writer.Flush(); // writer.Close(); return iPassed; }
//args: lrr location, lra location, html report location static int Main(string[] args) { //Console.WriteLine("in LrAnlysisLauncher"); try { if (args.Length != 3) { ShowHelp(); return (int)Launcher.ExitCodeEnum.Aborted; } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; if (session.Create(lralocation, lrrlocation)) { HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); XmlDocument xmlDoc = new XmlDocument(); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { Console.WriteLine(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); foreach (ErrorMessage err in session.ErrorMessages) { XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); Console.WriteLine("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); Console.WriteLine(""); } session.Close(); Console.WriteLine(Resources.SLAReportTitle); SlaResult slaResult = Session.CalculateSla(lralocation, true); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { XmlElement elem = xmlDoc.CreateElement(a.RuleName); Console.WriteLine(Resources.DoubleLineSeperator); elem.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Full Name : " + a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); Console.WriteLine("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); Console.WriteLine("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); Console.WriteLine(Resources.DoubleLineSeperator); root.AppendChild(elem); } foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { XmlElement rule = xmlDoc.CreateElement(a.RuleName); Console.WriteLine(Resources.DoubleLineSeperator); Console.WriteLine("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("CriteriaMeasurement Value : " + a.CriteriaMeasurement); rule.SetAttribute("CriteriaMeasurementValue", a.CriteriaMeasurement.ToString()); Console.WriteLine("LoadThresholds value : "); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); Console.WriteLine("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); root.AppendChild(rule); Console.WriteLine(Resources.DoubleLineSeperator); } //write XML to location: xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { Console.WriteLine(Resources.CannotCreateSession); return (int)Launcher.ExitCodeEnum.Aborted; } session.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return (int)Launcher.ExitCodeEnum.Aborted; } finally { //close analysis? } return (int)Launcher.ExitCodeEnum.Passed; }
//args: lrr location, lra location, html report location static int Main(string[] args) { Console.WriteLine("starting analysis launcher"); int iPassed = (int)Launcher.ExitCodeEnum.Passed;//variable to keep track of whether all of the SLAs passed try { if (args.Length != 3) { ShowHelp(); return((int)Launcher.ExitCodeEnum.Aborted); } string lrrlocation = args[0]; string lralocation = args[1]; string htmlLocation = args[2]; LrAnalysis analysis = new LrAnalysis(); Session session = analysis.Session; if (session.Create(lralocation, lrrlocation)) { HtmlReportMaker reportMaker = session.CreateHtmlReportMaker(); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "IE", Path.GetFileName(htmlLocation)), ApiBrowserType.IE); reportMaker.CreateDefaultHtmlReport(Path.Combine(Path.GetDirectoryName(htmlLocation), "Netscape", Path.GetFileName(htmlLocation)), ApiBrowserType.Netscape); XmlDocument xmlDoc = new XmlDocument(); session.ErrorMessages.LoadValuesIfNeeded(); if (session.ErrorMessages.Count != 0) { if (session.ErrorMessages.Count > 1000) { Console.WriteLine("more then 1000 error during scenario run, analyzing only the first 1000."); } Console.WriteLine(Resources.ErrorsReportTitle); XmlElement errorRoot = xmlDoc.CreateElement("Errors"); xmlDoc.AppendChild(errorRoot); int limit = 1000; ErrorMessage[] errors = session.ErrorMessages.ToArray(); //foreach (ErrorMessage err in session.ErrorMessages) for (int i = 0; i < limit && i < errors.Length; i++) { ErrorMessage err = errors[i]; XmlElement elem = xmlDoc.CreateElement("Error"); elem.SetAttribute("ID", err.ID.ToString()); elem.AppendChild(xmlDoc.CreateTextNode(err.Name)); Console.WriteLine("ID: " + err.ID + " Name: " + err.Name); errorRoot.AppendChild(elem); } xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "Errors.xml")); xmlDoc.RemoveAll(); Console.WriteLine(""); } session.Close(); Console.WriteLine(Resources.SLAReportTitle); SlaResult slaResult = Session.CalculateSla(lralocation, true); XmlElement root = xmlDoc.CreateElement("SLA"); xmlDoc.AppendChild(root); int iCounter = 0; // set counter foreach (SlaWholeRunRuleResult a in slaResult.WholeRunRules) { Console.WriteLine(Resources.DoubleLineSeperator); XmlElement elem; if (a.Measurement.Equals(SlaMeasurement.PercentileTRT)) { SlaPercentileRuleResult b = slaResult.TransactionRules.PercentileRules[iCounter]; elem = xmlDoc.CreateElement(b.RuleName); Console.WriteLine("Transaction Name : " + b.TransactionName); elem.SetAttribute("TransactionName", b.TransactionName.ToString()); Console.WriteLine("Percentile : " + b.Percentage); elem.SetAttribute("Percentile", b.Percentage.ToString()); elem.SetAttribute("FullName", b.RuleUiName); Console.WriteLine("Full Name : " + b.RuleUiName); Console.WriteLine("Measurement : " + b.Measurement); elem.SetAttribute("Measurement", b.Measurement.ToString()); Console.WriteLine("Goal Value : " + b.GoalValue); elem.SetAttribute("GoalValue", b.GoalValue.ToString()); Console.WriteLine("Actual value : " + b.ActualValue); elem.SetAttribute("ActualValue", b.ActualValue.ToString()); Console.WriteLine("status : " + b.Status); elem.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (!b.Status.Equals(SlaRuleStatus.Passed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { elem = xmlDoc.CreateElement(a.RuleName); elem.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Full Name : " + a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); elem.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("Goal Value : " + a.GoalValue); elem.SetAttribute("GoalValue", a.GoalValue.ToString()); Console.WriteLine("Actual value : " + a.ActualValue); elem.SetAttribute("ActualValue", a.ActualValue.ToString()); Console.WriteLine("status : " + a.Status); elem.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (!a.Status.Equals(SlaRuleStatus.Passed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(elem); Console.WriteLine(Resources.DoubleLineSeperator); } iCounter = 0; // reset counter foreach (SlaTimeRangeRuleResult a in slaResult.TimeRangeRules) { Console.WriteLine(Resources.DoubleLineSeperator); XmlElement rule; if (a.Measurement.Equals(SlaMeasurement.AverageTRT)) { SlaTransactionTimeRangeRuleResult b = slaResult.TransactionRules.TimeRangeRules[iCounter]; rule = xmlDoc.CreateElement(b.RuleName); Console.WriteLine("Transaction Name: " + b.TransactionName); rule.SetAttribute("TransactionName", b.TransactionName); Console.WriteLine("Full Name : " + b.RuleUiName); rule.SetAttribute("FullName", b.RuleUiName); Console.WriteLine("Measurement : " + b.Measurement); rule.SetAttribute("Measurement", b.Measurement.ToString()); Console.WriteLine("SLA Load Threshold Value : " + b.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", b.CriteriaMeasurement.ToString()); foreach (SlaLoadThreshold slat in b.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); foreach (SlaTimeRangeInfo slatri in b.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); Console.WriteLine("status : " + b.Status); rule.AppendChild(xmlDoc.CreateTextNode(b.Status.ToString())); if (!b.Status.Equals(SlaRuleStatus.Passed)) // 0 = failed { iPassed = (int)Launcher.ExitCodeEnum.Failed; } iCounter++; } else { rule = xmlDoc.CreateElement(a.RuleName); Console.WriteLine("Full Name : " + a.RuleUiName); rule.SetAttribute("FullName", a.RuleUiName); Console.WriteLine("Measurement : " + a.Measurement); rule.SetAttribute("Measurement", a.Measurement.ToString()); Console.WriteLine("SLA Load Threshold Value : " + a.CriteriaMeasurement); rule.SetAttribute("SLALoadThresholdValue", a.CriteriaMeasurement.ToString()); foreach (SlaLoadThreshold slat in a.LoadThresholds) { XmlElement loadThr = xmlDoc.CreateElement("SlaLoadThreshold"); loadThr.SetAttribute("StartLoadValue", slat.StartLoadValue.ToString()); loadThr.SetAttribute("EndLoadValue", slat.EndLoadValue.ToString()); loadThr.SetAttribute("ThresholdValue", slat.ThresholdValue.ToString()); rule.AppendChild(loadThr); } XmlElement timeRanges = xmlDoc.CreateElement("TimeRanges"); foreach (SlaTimeRangeInfo slatri in a.TimeRanges) { XmlElement subsubelem = xmlDoc.CreateElement("TimeRangeInfo"); subsubelem.SetAttribute("StartTime", slatri.StartTime.ToString()); subsubelem.SetAttribute("EndTime", slatri.EndTime.ToString()); subsubelem.SetAttribute("GoalValue", slatri.GoalValue.ToString()); subsubelem.SetAttribute("ActualValue", slatri.ActualValue.ToString()); subsubelem.SetAttribute("LoadValue", slatri.LoadValue.ToString()); subsubelem.InnerText = slatri.Status.ToString(); timeRanges.AppendChild(subsubelem); } rule.AppendChild(timeRanges); Console.WriteLine("status : " + a.Status); rule.AppendChild(xmlDoc.CreateTextNode(a.Status.ToString())); if (!a.Status.Equals(SlaRuleStatus.Passed)) { iPassed = (int)Launcher.ExitCodeEnum.Failed; } } root.AppendChild(rule); Console.WriteLine(Resources.DoubleLineSeperator); } //write XML to location: xmlDoc.Save(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(lrrlocation)), "SLA.xml")); } else { Console.WriteLine(Resources.CannotCreateSession); return((int)Launcher.ExitCodeEnum.Aborted); } session.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return((int)Launcher.ExitCodeEnum.Aborted); } // return SLA status code, if any SLA fails return a fail here. return(iPassed); }