diff --git a/export.py b/export.py index 27d6e53..5e7cb4a 100644 --- a/export.py +++ b/export.py @@ -3,9 +3,11 @@ import argparse import re import sys from dataclasses import dataclass +from decimal import Decimal from typing import Dict, Iterable, List, Tuple from openpyxl import Workbook +from openpyxl.chart import BarChart, Reference from openpyxl.styles import Font @@ -18,8 +20,10 @@ LINE_RE = re.compile( class ProcessLog: pid: int ppid: int - start: float - finish: float | None = None + start: Decimal + start_text: str + finish: Decimal | None = None + finish_text: str | None = None first_seen_order: int = 0 @@ -65,16 +69,23 @@ def parse_processes(lines: Iterable[str]) -> Dict[int, ProcessLog]: event, pid_s, ppid_s, _depth_s, _l_s, _r_s, ts_s = m.groups() pid = int(pid_s) ppid = int(ppid_s) - ts = float(ts_s) + ts = Decimal(ts_s) if event == "START": processes[pid] = ProcessLog( - pid=pid, ppid=ppid, start=ts, finish=None, first_seen_order=order + pid=pid, + ppid=ppid, + start=ts, + start_text=ts_s, + finish=None, + finish_text=None, + first_seen_order=order, ) order += 1 else: if pid in processes: processes[pid].finish = ts + processes[pid].finish_text = ts_s return processes @@ -113,29 +124,69 @@ def tree_rows(processes: Dict[int, ProcessLog]) -> List[Tuple[int, ProcessLog]]: return ordered +def fmt6(value: Decimal) -> str: + return f"{value.quantize(Decimal('0.000001'))}" + + def export_excel(rows: List[Tuple[int, ProcessLog]], output_path: str) -> None: wb = Workbook() ws = wb.active ws.title = "process_logs" - ws.append(["PPID", "PID", "START", "FINISH", "DURATION"]) + ws.append(["PPID", "PID", "START", "TIME_FROM_START", "FINISH", "DURATION"]) for cell in ws[1]: cell.font = Font(bold=True) + base_start = min((node.start for _, node in rows), default=Decimal("0")) + for depth, node in rows: if node.finish is None: continue + if node.finish_text is None: + continue + + time_from_start = node.start - base_start duration = node.finish - node.start pid_display = f"{' ' * depth}{node.pid}" - ws.append([node.ppid, pid_display, node.start, node.finish, duration]) + ws.append( + [ + node.ppid, + pid_display, + node.start_text, + fmt6(time_from_start), + node.finish_text, + fmt6(duration), + ] + ) ws.column_dimensions["A"].width = 12 ws.column_dimensions["B"].width = 20 ws.column_dimensions["C"].width = 18 ws.column_dimensions["D"].width = 18 - ws.column_dimensions["E"].width = 14 + ws.column_dimensions["E"].width = 18 + ws.column_dimensions["F"].width = 14 ws.freeze_panes = "A2" + last_row = ws.max_row + if last_row >= 2: + chart = BarChart() + chart.type = "bar" + chart.grouping = "stacked" + chart.overlap = 100 + chart.gapWidth = 150 + chart.legend.position = "b" + chart.width = 15 + chart.height = 7.5 + chart.x_axis.scaling.orientation = "maxMin" + + data = Reference(ws, min_col=4, max_col=4, min_row=2, max_row=last_row) + duration = Reference(ws, min_col=6, max_col=6, min_row=2, max_row=last_row) + chart.add_data(data, titles_from_data=False) + chart.add_data(duration, titles_from_data=False) + chart.series[0].graphicalProperties.noFill = True + + ws.add_chart(chart, "D21") + wb.save(output_path) diff --git a/log.txt b/log.txt index 913ac00..36246d9 100644 --- a/log.txt +++ b/log.txt @@ -1,36 +1,36 @@ Before: -61348 28446 8318 49147 24393 15112 24969 66655 3374 5666 48922 778 11600 6589 6406 56105 71867 17651 21741 7869 +53295 80896 89602 86224 55926 84615 87294 48381 55123 61994 34359 93902 43309 3589 29660 26380 61249 28170 39563 82507 -START PID=44192 PPID=44191 depth=0 range=[0,19999] time=1776745157.209104 -START PID=44193 PPID=44192 depth=1 range=[0,9999] time=1776745157.209289 -START PID=44194 PPID=44192 depth=1 range=[10000,19999] time=1776745157.209369 -START PID=44195 PPID=44193 depth=2 range=[0,4999] time=1776745157.209470 -START PID=44197 PPID=44193 depth=2 range=[5000,9999] time=1776745157.209540 -START PID=44196 PPID=44194 depth=2 range=[10000,14999] time=1776745157.209546 -START PID=44198 PPID=44194 depth=2 range=[15000,19999] time=1776745157.209581 -START PID=44199 PPID=44195 depth=3 range=[0,2499] time=1776745157.209631 -START PID=44200 PPID=44197 depth=3 range=[5000,7499] time=1776745157.209689 -START PID=44201 PPID=44196 depth=3 range=[10000,12499] time=1776745157.209717 -START PID=44202 PPID=44195 depth=3 range=[2500,4999] time=1776745157.209722 -START PID=44204 PPID=44197 depth=3 range=[7500,9999] time=1776745157.209779 -START PID=44205 PPID=44196 depth=3 range=[12500,14999] time=1776745157.209848 -START PID=44203 PPID=44198 depth=3 range=[15000,17499] time=1776745157.209874 -END PID=44200 PPID=44197 depth=3 range=[5000,7499] time=1776745157.209961 -END PID=44199 PPID=44195 depth=3 range=[0,2499] time=1776745157.210015 -END PID=44201 PPID=44196 depth=3 range=[10000,12499] time=1776745157.210100 -END PID=44202 PPID=44195 depth=3 range=[2500,4999] time=1776745157.210110 -END PID=44204 PPID=44197 depth=3 range=[7500,9999] time=1776745157.210143 -END PID=44205 PPID=44196 depth=3 range=[12500,14999] time=1776745157.210214 -END PID=44203 PPID=44198 depth=3 range=[15000,17499] time=1776745157.210242 -END PID=44195 PPID=44193 depth=2 range=[0,4999] time=1776745157.210294 -END PID=44197 PPID=44193 depth=2 range=[5000,9999] time=1776745157.210304 -END PID=44196 PPID=44194 depth=2 range=[10000,14999] time=1776745157.210415 -START PID=44206 PPID=44198 depth=3 range=[17500,19999] time=1776745157.210418 -END PID=44193 PPID=44192 depth=1 range=[0,9999] time=1776745157.210535 -END PID=44206 PPID=44198 depth=3 range=[17500,19999] time=1776745157.210718 -END PID=44198 PPID=44194 depth=2 range=[15000,19999] time=1776745157.210864 -END PID=44194 PPID=44192 depth=1 range=[10000,19999] time=1776745157.211079 -END PID=44192 PPID=44191 depth=0 range=[0,19999] time=1776745157.211362 +START PID=53571 PPID=53570 depth=0 range=[0,19999] time=1776746459.289786 +START PID=53572 PPID=53571 depth=1 range=[0,9999] time=1776746459.290028 +START PID=53573 PPID=53571 depth=1 range=[10000,19999] time=1776746459.290119 +START PID=53574 PPID=53572 depth=2 range=[0,4999] time=1776746459.290256 +START PID=53576 PPID=53572 depth=2 range=[5000,9999] time=1776746459.290432 +START PID=53575 PPID=53573 depth=2 range=[10000,14999] time=1776746459.290464 +START PID=53577 PPID=53573 depth=2 range=[15000,19999] time=1776746459.290645 +START PID=53578 PPID=53574 depth=3 range=[0,2499] time=1776746459.290676 +START PID=53580 PPID=53576 depth=3 range=[5000,7499] time=1776746459.290855 +END PID=53578 PPID=53574 depth=3 range=[0,2499] time=1776746459.291082 +END PID=53580 PPID=53576 depth=3 range=[5000,7499] time=1776746459.291298 +START PID=53579 PPID=53574 depth=3 range=[2500,4999] time=1776746459.291487 +START PID=53584 PPID=53577 depth=3 range=[17500,19999] time=1776746459.291494 +START PID=53582 PPID=53577 depth=3 range=[15000,17499] time=1776746459.291486 +START PID=53583 PPID=53575 depth=3 range=[10000,12499] time=1776746459.291497 +START PID=53581 PPID=53576 depth=3 range=[7500,9999] time=1776746459.291592 +END PID=53584 PPID=53577 depth=3 range=[17500,19999] time=1776746459.292012 +END PID=53579 PPID=53574 depth=3 range=[2500,4999] time=1776746459.292020 +END PID=53581 PPID=53576 depth=3 range=[7500,9999] time=1776746459.292094 +END PID=53582 PPID=53577 depth=3 range=[15000,17499] time=1776746459.292094 +END PID=53583 PPID=53575 depth=3 range=[10000,12499] time=1776746459.292159 +END PID=53576 PPID=53572 depth=2 range=[5000,9999] time=1776746459.292532 +START PID=53585 PPID=53575 depth=3 range=[12500,14999] time=1776746459.292517 +END PID=53585 PPID=53575 depth=3 range=[12500,14999] time=1776746459.293104 +END PID=53574 PPID=53572 depth=2 range=[0,4999] time=1776746459.293576 +END PID=53572 PPID=53571 depth=1 range=[0,9999] time=1776746459.294079 +END PID=53577 PPID=53573 depth=2 range=[15000,19999] time=1776746459.294508 +END PID=53575 PPID=53573 depth=2 range=[10000,14999] time=1776746459.294684 +END PID=53573 PPID=53571 depth=1 range=[10000,19999] time=1776746459.295034 +END PID=53571 PPID=53570 depth=0 range=[0,19999] time=1776746459.295429 After: -4 10 13 28 36 40 54 55 59 62 68 78 81 81 83 85 90 91 91 92 +0 5 5 10 16 20 22 22 28 50 56 56 57 59 60 61 77 79 81 83 diff --git a/process_log.xlsx b/process_log.xlsx index 434c964..b1936b0 100644 Binary files a/process_log.xlsx and b/process_log.xlsx differ