Exemple #1
0
        private static void RunMonitorProcess(bool isStarting)
        {
            var error      = string.Empty;
            var exitCode   = 0;
            var outputFile = GetOutputName();
            var arguments  = isStarting ? $"/start:coverage /output:{outputFile}" : "/shutdown";
            var timedOut   = false;

            using (var monitorProc = new Process())
            {
                monitorProc.StartInfo.FileName               = CodeCoverageInstrumentation.GetToolPath("VSPerfCmdToolPath", "VSPerfCmd");
                monitorProc.StartInfo.Arguments              = arguments;
                monitorProc.StartInfo.UseShellExecute        = false;
                monitorProc.StartInfo.RedirectStandardOutput = true;
                monitorProc.StartInfo.RedirectStandardError  = true;
                monitorProc.Start();

                Output.WriteLine($"... {(isStarting ? "Starting" : "Shutting down")} code coverage monitor");

                // timedOut can only become true on shutdown (non-infinite timeout value)
                timedOut = !monitorProc.WaitForExit(isStarting ? Timeout.Infinite : 5000);
                if (!timedOut)
                {
                    exitCode = monitorProc.ExitCode;
                    if (exitCode != 0)
                    {
                        error = monitorProc.StandardError.ReadToEnd();
                    }
                }
            }

            if (exitCode != 0 || error.Length > 0)
            {
                if (error.Length == 0)
                {
                    error = "<no error message returned>";
                }

                Output.WriteLine($"Warning: 'VSPerfCmd {arguments}' exit code {exitCode}: {error}");
            }

            if (!isStarting)
            {
                if (timedOut)
                {
                    Output.WriteLine($"Warning: VsPerfCmd timed out on shutdown");
                }

                if (File.Exists(outputFile))
                {
                    var fileInfo = new FileInfo(outputFile);
                    Output.WriteLine($"..... Created {outputFile}");
                }
                else
                {
                    Output.WriteLine($"Warning: Code coverage output file {outputFile} was not created");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Emits the testing traces.
        /// </summary>
        private void EmitTraces()
        {
            string file = Path.GetFileNameWithoutExtension(this.Configuration.AssemblyToBeAnalyzed);

            file += "_" + this.Configuration.TestingProcessId;

            // If this is a separate (sub-)process, CodeCoverageInstrumentation.OutputDirectory may not have been set up.
            CodeCoverageInstrumentation.SetOutputDirectory(this.Configuration, makeHistory: false);

            Output.WriteLine($"... Emitting task {this.Configuration.TestingProcessId} traces:");
            this.TestingEngine.TryEmitTraces(CodeCoverageInstrumentation.OutputDirectory, file);
        }