public static List <string> CallCompiler(string compiler, string args, out long CompileTimeMs) { Stopwatch watch = new Stopwatch(); using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "compile_parent.py"; process.StartInfo.Arguments = compiler + " " + args; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; watch.Start(); process.Start(); //process.PriorityClass = ProcessPriorityClass.AboveNormal; OutputReader output = new OutputReader(process.StandardOutput, 100); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError, 100); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); watch.Stop(); CompileTimeMs = watch.ElapsedMilliseconds; errorReader.Join(5000); outputReader.Join(5000); List <string> compOutput = new List <string>(); compOutput.Add(output.Output); compOutput.Add(error.Output); return(compOutput); } }
List <string> CallCompiler(string compiler, string args) { Stopwatch watch = new Stopwatch(); using (Process process = new Process()) { process.StartInfo.FileName = compiler; process.StartInfo.Arguments = args; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; watch.Start(); process.Start(); OutputReader output = new OutputReader(process.StandardOutput, 100); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError, 100); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); watch.Stop(); CompileTimeMs = watch.ElapsedMilliseconds; errorReader.Join(5000); outputReader.Join(5000); List <string> compOutput = new List <string>(); compOutput.Add(output.Output); compOutput.Add(error.Output); return(compOutput); } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)CompileTimeMs/(double)1000), 2); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length && Int32.TryParse(error.Output.Substring(index+1), out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); } } odata.Errors = error.Output; odata.Output = output.Output; } watch.Stop(); if(idata.Lang != Languages.Python) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec", Math.Round((double)CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } else { odata.Stats = string.Format("Absolute running time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }
List<string> CallCompiler(string compiler, string args) { Stopwatch watch = new Stopwatch(); using(Process process = new Process()) { process.StartInfo.FileName = compiler; process.StartInfo.Arguments = args; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; watch.Start(); process.Start(); OutputReader output = new OutputReader(process.StandardOutput, 100); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError, 100); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); watch.Stop(); CompileTimeMs = watch.ElapsedMilliseconds; errorReader.Join(5000); outputReader.Join(5000); List<string> compOutput = new List<string>(); compOutput.Add(output.Output); compOutput.Add(error.Output); return compOutput; } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if (!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2)); return(odata); } if (!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "parent.py"; //process.StartInfo.FileName = "/home/ren/a.out"; process.StartInfo.Arguments = cdata.Executor + (string.IsNullOrEmpty(cdata.Executor) ? "" : " ") + cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); if (!string.IsNullOrEmpty(idata.Input)) { InputWriter input = new InputWriter(process.StandardInput, idata.Input); Thread inputWriter = new Thread(new ThreadStart(input.Writeinput)); inputWriter.Start(); } OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if (!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if (index != -1 && index + 1 < error.Output.Length) { string[] info = error.Output.Substring(index + 1).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (info.Length > 0 && Int32.TryParse(info[0], out exitcode)) { odata.ExitCode = exitcode; switch (exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); if (info.Length > 1) { double cpuTime; Double.TryParse(info[1], out cpuTime); CpuTimeInSec = cpuTime; } if (info.Length > 2) { int memory; Int32.TryParse(info[2], out memory); MemoryPickInKilobytes = memory; } } } } odata.Errors = error.Output; odata.Output = output.Output; if (idata.Lang == Languages.Octave) { string bad_err = "error: No such file or directory" + Environment.NewLine + "error: ignoring octave_execution_exception while preparing to exit"; if (odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if (string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } List <FileData> files = new List <FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } if (idata.Lang == Languages.R) { string bad_err = "sh: /bin/rm: Permission denied"; if (odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if (string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } if (File.Exists(Path.Combine(cdata.CleanThis, "Rplots.pdf"))) { using (var p = new Process()) { process.StartInfo.FileName = "pdftoppm"; process.StartInfo.WorkingDirectory = cdata.CleanThis; process.StartInfo.Arguments = "-png Rplots.pdf plots"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } List <FileData> files = new List <FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } } } watch.Stop(); if (Utils.IsCompiled(idata.Lang)) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, memory peak: {3} Mb", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes / 1024); } else { odata.Stats = string.Format("Absolute running time: {0} sec, cpu time: {1} sec, memory peak: {2} Mb", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes / 1024); } return(odata); } catch (Exception ex) { return(new OutputData() { System_Error = ex.Message }); } finally { if (cdata != null) { Cleanup(cdata.CleanThis); } } }
public static DiffResult GetDiff(string left, string right) { string diff_dir = ""; try { int r = Utils.GetUniqueRandom().Next(1, Int32.MaxValue); diff_dir = ParentRootPath+"diff/"+r+"/"; Directory.CreateDirectory(diff_dir); using(TextWriter tw = new StreamWriter(diff_dir+"left")) { tw.Write(left); } using(TextWriter tw = new StreamWriter(diff_dir+"right")) { tw.Write(right); } using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"codediff.py"; process.StartInfo.Arguments = diff_dir+"left "+diff_dir+"right "+"-o "+diff_dir+"result "+"-w 80"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(20000); if(!process.HasExited) process.Kill(); errorReader.Join(5000); string result = ""; if(string.IsNullOrEmpty(error.Output)) using(TextReader tr = new StreamReader(diff_dir+"result")) { result = tr.ReadToEnd(); } if(!string.IsNullOrEmpty(error.Output)) { return new DiffResult() { IsError = true, Result = error.Output }; } return new DiffResult() { Result = result }; } } catch(Exception e) { return new DiffResult() { IsError = true, Result = e.Message }; } finally { try { //cleanup Directory.Delete(diff_dir, true); } catch(Exception){} } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if (!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)CompileTimeMs / (double)1000), 2); return(odata); } if (!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "parent.py"; process.StartInfo.Arguments = cdata.Executor + (string.IsNullOrEmpty(cdata.Executor) ? "" : " ") + cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if (!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if (index != -1 && index + 1 < error.Output.Length && Int32.TryParse(error.Output.Substring(index + 1), out exitcode)) { odata.ExitCode = exitcode; switch (exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); } } odata.Errors = error.Output; odata.Output = output.Output; } watch.Stop(); if (idata.Lang != Languages.Python) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec", Math.Round((double)CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } else { odata.Stats = string.Format("Absolute running time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } return(odata); } catch (Exception ex) { return(new OutputData() { System_Error = ex.Message }); } finally { if (cdata != null) { Cleanup(cdata.CleanThis); } } }
public static DiffResult GetDiff(string left, string right) { string diff_dir = ""; try { int r = Utils.GetUniqueRandom().Next(1, Int32.MaxValue); diff_dir = ParentRootPath + "diff/" + r + "/"; Directory.CreateDirectory(diff_dir); using (TextWriter tw = new StreamWriter(diff_dir + "left")) { tw.Write(left); } using (TextWriter tw = new StreamWriter(diff_dir + "right")) { tw.Write(right); } using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "codediff.py"; process.StartInfo.Arguments = diff_dir + "left " + diff_dir + "right " + "-o " + diff_dir + "result " + "-w 80"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(20000); if (!process.HasExited) { process.Kill(); } errorReader.Join(5000); string result = ""; if (string.IsNullOrEmpty(error.Output)) { using (TextReader tr = new StreamReader(diff_dir + "result")) { result = tr.ReadToEnd(); } } if (!string.IsNullOrEmpty(error.Output)) { return(new DiffResult() { IsError = true, Result = error.Output }); } return(new DiffResult() { Result = result }); } } catch (Exception e) { return(new DiffResult() { IsError = true, Result = e.Message }); } finally { try { //cleanup Directory.Delete(diff_dir, true); } catch (Exception) {} } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)cdata.CompileTimeMs/(double)1000, 2)); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; //process.StartInfo.FileName = "/home/ren/a.out"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); if (!string.IsNullOrEmpty(idata.Input)) { InputWriter input = new InputWriter(process.StandardInput, idata.Input); Thread inputWriter = new Thread(new ThreadStart(input.Writeinput)); inputWriter.Start(); } OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length) { string[] info = error.Output.Substring(index+1).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if(info.Length > 0 && Int32.TryParse(info[0], out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); if(info.Length > 1) { double cpuTime; Double.TryParse(info[1], out cpuTime); CpuTimeInSec = cpuTime; } if(info.Length > 2) { int memory; Int32.TryParse(info[2], out memory); MemoryPickInKilobytes = memory; } } } } odata.Errors = error.Output; odata.Output = output.Output; if(idata.Lang == Languages.Octave) { string bad_err = "error: No such file or directory"+Environment.NewLine+"error: ignoring octave_execution_exception while preparing to exit"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } if(idata.Lang == Languages.R) { string bad_err = "sh: /bin/rm: Permission denied"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } if(File.Exists(Path.Combine(cdata.CleanThis, "Rplots.pdf"))) { using(var p = new Process()) { process.StartInfo.FileName = "pdftoppm"; process.StartInfo.WorkingDirectory = cdata.CleanThis; process.StartInfo.Arguments = "-png Rplots.pdf plots"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } } } watch.Stop(); if(Utils.IsCompiled(idata.Lang)) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, memory peak: {3} Mb", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } else { odata.Stats = string.Format("Absolute running time: {0} sec, cpu time: {1} sec, memory peak: {2} Mb", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }
public static List<string> CallCompiler(string compiler, string args, out long CompileTimeMs) { Stopwatch watch = new Stopwatch(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"compile_parent.py"; process.StartInfo.Arguments = compiler+" "+args; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; watch.Start(); process.Start(); //process.PriorityClass = ProcessPriorityClass.AboveNormal; OutputReader output = new OutputReader(process.StandardOutput, 100); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError, 100); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); watch.Stop(); CompileTimeMs = watch.ElapsedMilliseconds; errorReader.Join(5000); outputReader.Join(5000); List<string> compOutput = new List<string>(); compOutput.Add(output.Output); compOutput.Add(error.Output); return compOutput; } }