private static void ConfigureProgressOutput(PythonAnalyzer analyzer) { int cLine = Console.CursorTop; int cChar = Console.CursorLeft, lastChar = 0; var start = DateTime.UtcNow; analyzer.SetQueueReporting(i => { Console.SetCursorPosition(cChar, cLine); if (lastChar > cChar) { Console.Write(new string(' ', lastChar - cChar)); Console.SetCursorPosition(cChar, cLine); } Console.Write($"{i} in queue; {DateTime.UtcNow - start} taken... "); lastChar = Console.CursorLeft; }, 50); }
private static void RunCommand( string cmd, string args, PythonAnalyzer analyzer, Dictionary <string, IPythonProjectEntry> modules, State state ) { switch (cmd.ToLower()) { case "print": Console.WriteLine(args); break; case "module": foreach (var mod in GetModules(args)) { IPythonProjectEntry entry; if (!modules.TryGetValue(mod.ModuleName, out entry)) { Console.WriteLine("Creating module {0}", mod.ModuleName); modules[mod.ModuleName] = entry = analyzer.AddModule(mod.ModuleName, mod.SourceFile); } else { Console.WriteLine("Reusing module {0}", mod.ModuleName); } using (var file = File.OpenText(mod.SourceFile)) { var parser = Parser.CreateParser( file, analyzer.LanguageVersion, new ParserOptions() { BindReferences = true } ); using (var p = entry.BeginParse()) { p.Tree = parser.ParseFile(); p.Complete(); } } } break; case "enqueue": if (args == "*") { foreach (var entry in modules.Values) { entry.Analyze(CancellationToken.None, true); } } else { IPythonProjectEntry entry; foreach (var modName in args.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrEmpty(s))) { if (!modules.TryGetValue(modName, out entry)) { Console.WriteLine("Could not enqueue {0}", modName); } else { entry.Analyze(CancellationToken.None, true); } } } break; case "analyze": Console.Write("Waiting for complete analysis... "); if (!Console.IsOutputRedirected) { int cLine = Console.CursorTop; int cChar = Console.CursorLeft, lastChar = 0; var start = DateTime.UtcNow; analyzer.SetQueueReporting(i => { Console.SetCursorPosition(cChar, cLine); if (lastChar > cChar) { Console.Write(new string(' ', lastChar - cChar)); Console.SetCursorPosition(cChar, cLine); } Console.Write($"{i} in queue; {DateTime.UtcNow - start} taken... "); lastChar = Console.CursorLeft; }, 500); } analyzer.AnalyzeQueuedEntries(CancellationToken.None); Console.WriteLine("done!"); break; case "pause": Console.Write("Press enter to continue..."); Console.ReadKey(true); Console.WriteLine(); break; case "debugbreak": if (!args.Equals("ifattached", StringComparison.CurrentCultureIgnoreCase) || Debugger.IsAttached) { Console.WriteLine("Breaking into the debugger"); Debugger.Break(); } break; case "gc": Console.WriteLine("Collecting garbage"); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.WaitForFullGCComplete(); GC.WaitForPendingFinalizers(); break; case "dump": { var fullPath = Path.GetFullPath(args); var length = WriteDump(Process.GetCurrentProcess(), fullPath, MiniDumpType.FullDump); Console.WriteLine( "Dump written to {0} at {1:F1}MB ({2} bytes)", fullPath, length / (1024.0 * 1024.0), length ); if (state.LastDumpSize > 0 && state.LastDumpSize != length) { var delta = Math.Abs(length - state.LastDumpSize); var direction = (length > state.LastDumpSize) ? "larger" : "smaller"; Console.WriteLine( "Dump is {0:F1}MB ({1} bytes) {2} than previous", delta / (1024.0 * 1024.0), delta, direction ); } state.LastDumpSize = length; break; } default: Console.WriteLine("Command not available: {0}", cmd); break; } }