private static void WaitForReport(INodeProfiling profiling, INodeProfileSession session, out INodePerformanceReport report, NodejsVisualStudioApp app, out AutomationElement child) { while (profiling.IsProfiling) { System.Threading.Thread.Sleep(500); } report = session.GetReport(1); var filename = report.Filename; Assert.IsTrue(filename.Contains("NodejsProfileTest")); app.OpenNodejsPerformance(); var pyPerf = app.NodejsPerformanceExplorerTreeView; Assert.AreNotEqual(null, pyPerf); var item = pyPerf.FindItem("NodejsProfileTest *", "Reports"); child = item.FindFirst(System.Windows.Automation.TreeScope.Descendants, Condition.TrueCondition); var childName = child.GetCurrentPropertyValue(AutomationElement.NameProperty) as string; Assert.IsTrue(childName.StartsWith("NodejsProfileTest")); AutomationWrapper.EnsureExpanded(child); }
private static bool[] FindFunctions(INodePerformanceReport report, string[] expectedFunctions) { // run vsperf string[] lines = OpenPerformanceReportAsCsv(report); bool[] expected = new bool[expectedFunctions.Length]; string[] altExpected = new string[expectedFunctions.Length]; for (int i = 0; i < expectedFunctions.Length; i++) { altExpected[i] = expectedFunctions[i] + " (recompiled)"; } // quote the function names so they match the CSV for (int i = 0; i < expectedFunctions.Length; i++) { expectedFunctions[i] = "\"" + expectedFunctions[i] + "\""; altExpected[i] = "\"" + altExpected[i] + "\""; } foreach (var line in lines) { Console.WriteLine(line); for (int i = 0; i < expectedFunctions.Length; i++) { if (line.StartsWith(expectedFunctions[i]) || line.StartsWith(altExpected[i])) { expected[i] = true; } } } return expected; }
private static string[] OpenPerformanceReportAsCsv(INodePerformanceReport report) { var perfReportPath = Path.Combine(GetPerfToolsPath(false), "vsperfreport.exe"); for (int i = 0; i < 11; i++) { string csvFilename; do { csvFilename = Path.Combine(Path.GetTempPath(), "test") + DateTime.Now.Ticks + "_" + _counter++; } while (File.Exists(csvFilename + "_FunctionSummary.csv")); var psi = new ProcessStartInfo(perfReportPath, "\"" + report.Filename + "\"" + " /output:" + csvFilename + " /summary:function"); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; var process = System.Diagnostics.Process.Start(psi); var output = new StringBuilder(); process.OutputDataReceived += (sender, args) => { output.Append(args.Data); }; process.ErrorDataReceived += (sender, args) => { output.Append(args.Data); }; process.WaitForExit(); if (process.ExitCode != 0) { if (i == 10) { string msg = "Output: " + process.StandardOutput.ReadToEnd() + Environment.NewLine + "Error: " + process.StandardError.ReadToEnd() + Environment.NewLine; Assert.Fail(msg); } else { Console.WriteLine("Failed to convert: {0}", output.ToString()); Console.WriteLine("--------------"); System.Threading.Thread.Sleep(1000); continue; } } string[] res = null; for (int j = 0; j < 100; j++) { try { res = File.ReadAllLines(csvFilename + "_FunctionSummary.csv"); break; } catch { System.Threading.Thread.Sleep(100); } } File.Delete(csvFilename + "_FunctionSummary.csv"); return res ?? new string[0]; } Assert.Fail("Unable to convert to CSV"); return null; }
private static void VerifyReportMissing(INodePerformanceReport report, params string[] missingFunctions) { bool[] expected = FindFunctions(report, missingFunctions); foreach (var found in expected) { Assert.IsFalse(found); } }