Stefan Schuermans commited on 2020-05-23 16:21:02
Showing 1 changed files, with 16 additions and 4 deletions.
| ... | ... |
@@ -54,9 +54,19 @@ class Processes(uproctrace.parse.Visitor): |
| 54 | 54 |
""" |
| 55 | 55 |
super().__init__() |
| 56 | 56 |
self._timeline = dict() # time -> list(parse.BaseEvent) |
| 57 |
- self._current_processes = dict() # pid -> Process |
|
| 57 |
+ self._all_processes = list() # list of all processess |
|
| 58 |
+ self._current_processes = dict() # pid -> process |
|
| 59 |
+ self._toplevel_processes = list() # list of processes without parent |
|
| 58 | 60 |
self._readTrace(proto_file) |
| 59 | 61 |
|
| 62 |
+ def _newProcess(self, pid: int): |
|
| 63 |
+ """ |
|
| 64 |
+ Create new process, set its ID (pid), store it and return it. |
|
| 65 |
+ """ |
|
| 66 |
+ proc = Process(pid) |
|
| 67 |
+ self._all_processes.append(proc) |
|
| 68 |
+ return proc |
|
| 69 |
+ |
|
| 60 | 70 |
def _readTrace(self, proto_file): |
| 61 | 71 |
""" |
| 62 | 72 |
Read events from trace file (proto_file) and add them. |
| ... | ... |
@@ -77,7 +87,7 @@ class Processes(uproctrace.parse.Visitor): |
| 77 | 87 |
""" |
| 78 | 88 |
self._visitBaseEvent(proc_begin) |
| 79 | 89 |
# new process |
| 80 |
- proc = Process(proc_begin.pid) |
|
| 90 |
+ proc = self._newProcess(proc_begin.pid) |
|
| 81 | 91 |
# add process to dict of current processes |
| 82 | 92 |
self._current_processes[proc_begin.pid] = proc |
| 83 | 93 |
# set begin event of process and process of begin event |
| ... | ... |
@@ -88,17 +98,19 @@ class Processes(uproctrace.parse.Visitor): |
| 88 | 98 |
parent = self._current_processes[proc_begin.ppid] |
| 89 | 99 |
proc.setParent(parent) |
| 90 | 100 |
parent.addChild(proc) |
| 101 |
+ else: |
|
| 102 |
+ self._toplevel_processes.append(proc) |
|
| 91 | 103 |
|
| 92 | 104 |
def visitProcEnd(self, proc_end: uproctrace.parse.ProcEnd): |
| 93 | 105 |
""" |
| 94 | 106 |
Process a process end event. |
| 95 | 107 |
""" |
| 96 | 108 |
self._visitBaseEvent(proc_end) |
| 97 |
- # get process (or create it it is not known) |
|
| 109 |
+ # get process (or create it if it is not known) |
|
| 98 | 110 |
if proc_end.pid in self._current_processes: |
| 99 | 111 |
proc = self._current_processes[proc_end.pid] |
| 100 | 112 |
else: |
| 101 |
- proc = Process(proc_end.pid) |
|
| 113 |
+ proc = self._newProcess(proc_end.pid) |
|
| 102 | 114 |
# set end event of process and process of end event |
| 103 | 115 |
proc.setEnd(proc_end) |
| 104 | 116 |
proc_end.setProcess(proc) |
| 105 | 117 |