diff options
Diffstat (limited to 'sanitizer.py')
| -rw-r--r-- | sanitizer.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sanitizer.py b/sanitizer.py new file mode 100644 index 0000000..79315cc --- /dev/null +++ b/sanitizer.py | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | ############################################################################### | ||
| 2 | # Description | ||
| 3 | ############################################################################### | ||
| 4 | |||
| 5 | # Sanitize input. (There are a number of goofy issues with the sched_trace | ||
| 6 | # output.) | ||
| 7 | |||
| 8 | ############################################################################### | ||
| 9 | # Public functions | ||
| 10 | ############################################################################### | ||
| 11 | |||
| 12 | def sanitizer(stream): | ||
| 13 | |||
| 14 | job_2s_released = [] # list of tasks which have released their job 2s | ||
| 15 | jobs_switched_to = [] | ||
| 16 | |||
| 17 | for record in stream: | ||
| 18 | |||
| 19 | # Ignore records which are not events (e.g. the num_cpus record) | ||
| 20 | if record.record_type != 'event': | ||
| 21 | yield record | ||
| 22 | continue | ||
| 23 | |||
| 24 | # All records with job < 2 are garbage | ||
| 25 | if record.job < 2: | ||
| 26 | continue | ||
| 27 | |||
| 28 | # Some records with job == 2 are garbage | ||
| 29 | if record.job==2: | ||
| 30 | |||
| 31 | # There is a duplicate release of every job 2 | ||
| 32 | # This will throw away the second one | ||
| 33 | if record.type_name == 'release': | ||
| 34 | if record.pid in job_2s_released: | ||
| 35 | continue | ||
| 36 | else: | ||
| 37 | job_2s_released.append(record.pid) | ||
| 38 | |||
| 39 | # Job 2 has a resume that is garbage | ||
| 40 | if record.type_name == 'resume': | ||
| 41 | continue | ||
| 42 | |||
| 43 | # By default, the switch_away for a job (after it has completed) | ||
| 44 | # is maked as being for job+1, which has never been switched to. | ||
| 45 | # We can correct this if we note which jobs really | ||
| 46 | # have been switched to. | ||
| 47 | if record.type_name == 'switch_to': | ||
| 48 | jobs_switched_to.append((record.pid,record.job)) | ||
| 49 | if record.type_name == 'switch_away': | ||
| 50 | if (record.pid,record.job) not in jobs_switched_to: | ||
| 51 | record.job -= 1 | ||
| 52 | |||
| 53 | yield record | ||
