public static void RunWrapper(string exe, string args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            var progress = new Progress <ProcessProgressDataload>();

            progress.ProgressChanged += (s, e) => {
                //Console.SetCursorPosition(Console.CursorTop + 2, 0);
                Console.WriteLine($"From process: {e.Message}");
            };

            try
            {
                Task <Process> t = ProcessAsyncRunner.Run(exe, args, cts.Token, progress);

                bool processRunning = true;
                t.ContinueWith((p) => { processRunning = false; });

                while (processRunning)
                {
                    // TODO: Find a less obstrusive way to report (that works on VSCode channels and console stdout)
                    // Console.Write(".");
                }
                t.Wait();
            }
            catch (OperationCanceledException ce)
            {
                Console.WriteLine($"Operation was cancelled with message: {ce.Message}");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string dwjsonDir = "";

            var parser = new Parser(config => {
                config.EnableDashDash = true;
            });

            var res = parser.ParseArguments <ProgramOptions>(args)
                      .WithParsed <ProgramOptions>(opts => {
                if (opts.CallStackFNameToParse != null)
                {
                    // TODO: test /tmp/results_20180314/r_stacks_0004.csv
#if false
                    ParseStackReport(opts.CallStackFNameToParse);
#endif
                    Environment.Exit(0);
                }

                string vtuneExec = "";
                try {
                    vtuneExec = VTuneInvoker.VTunePath();
                } catch (VTuneNotInstalledException ex) {
                    Console.WriteLine($"VTune not found in expected path: {ex.Message}");
                    Environment.Exit(1);
                }

                if (opts.ReportVTunePath)
                {
                    Console.WriteLine($"The path of VTune is: {vtuneExec}");
                    Environment.Exit(0);
                }

                var RestArgs = opts.Rest.ToList();
                VTuneCollectHotspotsSpec spec = new VTuneCollectHotspotsSpec()
                {
                    WorkloadSpec = String.Join(" ", RestArgs)
                };
                string vtuneCollectArgs = spec.FullCLI();

                VTuneReportCallstacksSpec repspec = new VTuneReportCallstacksSpec();
                string vtuneReportArgs            = repspec.FullCLI();

                VTuneCPUUtilizationSpec reptimespec = new VTuneCPUUtilizationSpec();
                string vtuneReportTimeArgs          = reptimespec.FullCLI();

                // If output directory requested and it does not exist, create it

                if (!opts.DryRunRequested)
                {
                    if (opts.DWJsonOutDir == null)
                    {
                        Console.WriteLine($"Need an output directory unless in dry run.");
                        Environment.Exit(1);
                    }
                    else
                    {
                        if (!Directory.Exists(opts.DWJsonOutDir))
                        {
                            try {
                                Directory.CreateDirectory(opts.DWJsonOutDir);
                            } catch (Exception ex) {
                                Console.WriteLine($"Couldn't create specified directory [{opts.DWJsonOutDir}]: {ex.Message}");
                                Environment.Exit(1);
                            }
                        }
                        dwjsonDir = opts.DWJsonOutDir;
                    }
                }

                if (!opts.DryRunRequested)
                {
                    Console.WriteLine($"Collect command line is: [ {vtuneExec} {vtuneCollectArgs} ]");
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneCollectArgs);

                    Console.WriteLine($"Report callstacks line: [ {vtuneExec} {vtuneReportArgs} ]");
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneReportArgs);

                    Console.WriteLine($"Report timing line: [ {vtuneExec} {vtuneReportTimeArgs} ]");
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneReportTimeArgs);
                }
                else
                {
                    Console.WriteLine($"Collect command line is: [ {vtuneExec} {vtuneCollectArgs} ]");
                    Console.WriteLine("Report command lines");
                    Console.WriteLine($"[ {vtuneExec} {vtuneReportArgs} ]");
                    Console.WriteLine($"[ {vtuneExec} {vtuneReportTimeArgs} ]");

                    Environment.Exit(0);
                }

                /*
                 * Console.WriteLine($"Please check for generated file: [{repspec.ReportOutputFile}]");
                 * Console.WriteLine($"\tand also [{reptimespec.ReportOutputFile}]");
                 * Console.WriteLine($"(Which I should process and dump at directory [{dwjsonDir}]");
                 */

                double runtime = VTuneToDWJSON.CSReportToDWJson(repspec.ReportOutputFile, Path.Combine(dwjsonDir, "Sample.dwjson"));
                VTuneToDWJSON.CPUReportToDWJson(reptimespec.ReportOutputFile, Path.Combine(dwjsonDir, "Session.counters"), runtime);

                Console.WriteLine($"Which I dumped at directory [{dwjsonDir}]");

#if false
                var stackReportFName = repspec.ReportOutputFile;
                if (!File.Exists(stackReportFName))
                {
                    Console.WriteLine("Cannot find the VTune report, something went wrong with the profiler process.");
                    Environment.Exit(1);
                }
#endif
            })
                      .WithNotParsed(errors => {
                Console.WriteLine("Incorrect command line.");
                Environment.Exit(1);
            });

            Environment.Exit(0);
        }