示例#1
0
        private static void ParseStackReport(string fname)
        {
            string possibleFn = fname;

            if (!File.Exists(possibleFn))
            {
                // The [old] argument parsing library chokes on absolute Linux paths (it gets confused apparently by leading '/')
                possibleFn = Path.DirectorySeparatorChar + possibleFn;
                if (!File.Exists(possibleFn))
                {
                    Console.WriteLine($"Cannot find {fname}");
                    return;
                }
            }

            try {
                var samples        = VTuneToDWJSON.ParseFromFile(possibleFn);
                int sample_counter = 1;
                foreach (var s in samples.Take(5))
                {
                    int current_top = sample_counter;
                    //Console.WriteLine("{0}, {1}", s.TOSFrame.Function, s.TOSFrame.CPUTime);
                    Console.WriteLine($"<tr data-tt-id=\"{current_top}\"><td>{s.TOSFrame.Function}</td><td>{s.TOSFrame.CPUTime}</td><td>{s.TOSFrame.Module}</td><td>{s.TOSFrame.FunctionFull}</td><td>{s.TOSFrame.SourceFile}</td><td>{s.TOSFrame.StartAddress}</td></tr>");
                    foreach (var ss in s.Stacks.Take(1))
                    {
                        foreach (var p in ss.Take(5))
                        {
                            sample_counter += 1;
                            //Console.WriteLine($"\t{p.Function}");
                            Console.WriteLine($"<tr data-tt-id=\"{sample_counter}\" data-tt-parent-id=\"{current_top}\"><td>{p.Function}</td><td>{p.CPUTime}</td><td>{p.Module}</td><td>{p.FunctionFull}</td><td>{p.SourceFile}</td><td>{p.StartAddress}</td></tr>");
                        }
                    }
                }
                Console.WriteLine($"Got {samples.Count()} samples.");
            } catch (Exception ex) {
                Console.WriteLine($"Caught an error, with message: [{ex.StackTrace}]");
            }
        }
示例#2
0
文件: Program.cs 项目: yepeiwen/PTVS
        static void Main(string[] args)
        {
            string dwjsonDir = "";

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

            var res = parser.ParseArguments <ProgramOptions>(args)
                      .WithParsed <ProgramOptions>(opts => {
                string vtuneExec = "";
                try {
                    vtuneExec = VTuneInvoker.VTunePath();
                } catch (VTuneNotInstalledException ex) {
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.VTuneNotFoundInExpectedPath, ex.Message));
                    Environment.Exit(1);
                }

                if (opts.ReportVTunePath)
                {
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.VTuneFoundInPath, vtuneExec));
                    Environment.Exit(0);
                }

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

                if (opts.SymbolPath != string.Empty)
                {
                    Console.WriteLine(Strings.SymbolPathSpecifiedNotification);
                    spec.SymbolPath = opts.SymbolPath;
                }

                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(Strings.OutputDirRequired);
                        Environment.Exit(1);
                    }
                    else
                    {
                        if (!Directory.Exists(opts.DWJsonOutDir))
                        {
                            try {
                                Directory.CreateDirectory(opts.DWJsonOutDir);
                            } catch (Exception ex) {
                                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.DirCreationFailed, opts.DWJsonOutDir, ex.Message));
                                Environment.Exit(1);
                            }
                        }
                        dwjsonDir = opts.DWJsonOutDir;
                    }
                }

                if (!opts.DryRunRequested)
                {
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CollectCmdLineDump, vtuneExec, vtuneCollectArgs));
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneCollectArgs);

                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CallstackReportCmdLineDump, vtuneExec, vtuneReportArgs));
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneReportArgs);

                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.TimingReportCmdLineDump, vtuneExec, vtuneReportTimeArgs));
                    ProcessAsyncRunner.RunWrapper(vtuneExec, vtuneReportTimeArgs);
                }
                else
                {
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CollectCmdLineDump, vtuneExec, vtuneCollectArgs));
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.CallstackReportCmdLineDump, vtuneExec, vtuneReportArgs));
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, Strings.TimingReportCmdLineDump, vtuneExec, vtuneReportTimeArgs));

                    Environment.Exit(0);
                }

                double runtime = VTuneToDWJSON.CSReportToDWJson(repspec.ReportOutputFile, Path.Combine(dwjsonDir, "Sample.dwjson"));
                VTuneToDWJSON.CPUReportToDWJson(reptimespec.ReportOutputFile, Path.Combine(dwjsonDir, "Session.counters"), runtime);
            })
                      .WithNotParsed(errors => {
                Console.WriteLine(Strings.IncorrectCommandLine);
                Environment.Exit(1);
            });

            Environment.Exit(0);
        }