Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Pass processId as first parameter and outputPath as second parameter");
            }
            else
            {
                string outputFilePath = args[1];
                if (!Directory.Exists(outputFilePath))
                {
                    Console.WriteLine($"Outputpath '{outputFilePath}' does not exist");
                    return;
                }
                else
                {
                    outputFilePath = Path.Combine(outputFilePath, "stacks.json");
                }

                bool processFound = Int32.TryParse(args[0], out int processId);
                if (processFound)
                {
                    DateTime dtStart = DateTime.Now;
                    var      threads = Debugger.CollectTraces(processId);
                    Console.WriteLine($"Found {threads.Count} threads in process {processId}");

                    if (threads.Count > 0)
                    {
                        using (StreamWriter file = File.CreateText(outputFilePath))
                        {
                            JsonSerializer serializer = new JsonSerializer();
                            serializer.Formatting = Formatting.Indented;
                            serializer.Serialize(file, threads);
                        }

                        Console.WriteLine($"Saved file {outputFilePath} successfully");
                    }
                }
                else
                {
                    Console.WriteLine($"Failed to parse '{args[0]}' as processId");
                }
            }
        }