public static TimeSpan MakeAggregateReport(ExcelMaster excelMaster, string sheetName, FileInfo sourceLogFile, string fromTime, string toTime) { var duration = new TimeSpan(-1); try { using (_perl = new Process()) { _perl.StartInfo.FileName = "cmd.exe"; _perl.StartInfo.Arguments = " /c \"cd parser && type \"" + sourceLogFile.FullName + "\" | " + AGGREGATE_REPORT_PARSER_NAME + " " + fromTime + " " + toTime + "\""; _perl.StartInfo.RedirectStandardError = false; _perl.StartInfo.RedirectStandardInput = false; _perl.StartInfo.RedirectStandardOutput = true; _perl.StartInfo.CreateNoWindow = true; _perl.StartInfo.StandardOutputEncoding = Encoding.UTF8; _perl.StartInfo.Verb = "Open"; _perl.StartInfo.UseShellExecute = false; _perl.Start(); Thread.Sleep(1000); // время на одупление if (_perl.HasExited && _perl.ExitCode != 0) // если какой-то косяк с парсером (например, неверный формат input-файла) { return duration; } using (var stdout = _perl.StandardOutput) { excelMaster.AddAggregateReportWorksheet(sheetName, stdout); } //excelMaster.AddMainSheet("Main", 3000); duration = _perl.ExitTime - _perl.StartTime; } } catch (InvalidOperationException) { return duration; } catch (FileNotFoundException) { Stop(); return new TimeSpan(-3); } catch (ThreadInterruptedException) { Stop(); return new TimeSpan(-2); } return duration; }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { if (checkBoxTime.Checked) { //string secondline = File.ReadAllLines(@""); var from = fromTime.Text; var to = toTime.Text; } else { var from = fromTime.Text; var to = toTime.Text; } int rumpMin = (int)numericRump.Value; int OneHundPerc = metricsGridView.RowCount * 2 + 7; int OnePerc = (OneHundPerc) / 100; string buff = metricsGridView[0, 0].Value.ToString(); string[] Pieces = buff.Split('\\'); foreach (string str in Pieces) if (str.Contains("app") || str.Contains("db")) { int r = str.IndexOf("(") + 1; int lr = str.LastIndexOf(")"); buff = str.Substring(r, lr - r); buff = buff.ToUpper(); //MessageBox.Show(buff); if (buff.Length > 7) buff = buff.Substring(0, 7); } if (e.Argument.ToString() == "Unix") { if (buff == metricsGridView[0, 0].Value.ToString()) buff = ""; mesStat = "Проверка на существующий Excel-файл"; backgroundWorker.ReportProgress(1); try { if (File.Exists("Результат_Теста_" + (int)numericUpDown1.Value + "_"+"(" + buff.ToLower() + ")" + ".xlsx")) throw new IOException("Файл с таким именем уже существует"); } catch (IOException ex) { Popup.ShowException(ex); return; } mesStat = "Создание нового Excel-файла"; var xlsx = new FileInfo("Результат_Теста_" + (int)numericUpDown1.Value + "_"+"(" + buff.ToLower() + ")" + ".xlsx"); var em = new ExcelMaster(xlsx, excelDictionary); DateTime t1 = new DateTime(); DateTime t2 = new DateTime(); for (int row = 0; row < metricsGridView.RowCount; row++) { try { using (StreamReader sr = new StreamReader(metricsGridView[0, row].Value.ToString())) { string sheetN = getListName(System.IO.Path.GetFullPath(metricsGridView[0, row].Value.ToString())); mesStat = "Обрабатываю " + sheetN; ExcelWorksheet hidden = em.AddMetricWorksheet(sheetN, sr, from, to, ';'); backgroundWorker.ReportProgress((row + 1) * 100 / OneHundPerc); //while (!DateTime.TryParse(to, out t1)) if (!(metricsGridView[0, row].Value.ToString().Contains("sys_info"))) em.AddPivotTables("pivot " + hidden.Name, hidden.Cells[hidden.Dimension.Address]); backgroundWorker.ReportProgress((row + 2) * OnePerc / OneHundPerc); if (metricsGridView[0, row].Value.ToString().Contains("disk")) { em.AddPivotTables("pivot (" + buff.ToLower() + ") disk_io", hidden.Cells[hidden.Dimension.Address]); } } } catch (Exception ex) { Popup.ShowException(ex); } } // toolStripStatusLabel1.Text = "Metrics copied"; mesStat = "Метрики с таблицами добавлены! Создаем графики..."; int i = metricsGridView.RowCount; i++; int minutes = 0; if (DateTime.TryParse(to, out t2) && DateTime.TryParse(from, out t1)) minutes = (int)(t2 - t1).TotalMinutes; try { em.AddCPUTable("CPU_All", rumpMin, minutes, buff); i = changebar("всем ядрам", i * 100 / OneHundPerc, i); em.AddCPUTable("CPU", rumpMin, minutes, buff); i = changebar("процессору", i * 100 / OneHundPerc, i); em.AddMemTable("Mem", rumpMin, minutes, buff); i = changebar("памяти", i * 100 / OneHundPerc, i); em.AddDiskTable("Disk_io", rumpMin, minutes, buff); i = changebar("времени отклику дисков", i * 100 / OneHundPerc, i); em.AddDiskTable("Disk_use", rumpMin, minutes, buff); i = changebar("нагрузке дисков", i * 100 / OneHundPerc, i); em.AddMainSheet("Main", int.Parse(numericEffort.Value.ToString()), from, to, buff); i = changebar("общей информации о системе", i * 100 / OneHundPerc, i); em.hideLists(buff); } catch (Exception ex) { Popup.ShowException(ex); } em.Finish(); backgroundWorker.ReportProgress(100); try { var pi = new ProcessStartInfo(xlsx.FullName); Process.Start(pi); } catch (Win32Exception) { } } }