示例#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
        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);
        }