diff options
Diffstat (limited to 'parse/sched.py')
| -rw-r--r-- | parse/sched.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/parse/sched.py b/parse/sched.py index 1033989..5a36da9 100644 --- a/parse/sched.py +++ b/parse/sched.py | |||
| @@ -26,9 +26,11 @@ ScaleData = namedtuple('ScaleData', ['reg_tasks', 'base_tasks']) | |||
| 26 | 26 | ||
| 27 | class TimeTracker: | 27 | class TimeTracker: |
| 28 | '''Store stats for durations of time demarcated by sched_trace records.''' | 28 | '''Store stats for durations of time demarcated by sched_trace records.''' |
| 29 | def __init__(self): | 29 | def __init__(self, join_job = False): |
| 30 | self.begin = self.avg = self.max = self.num = self.next_job = 0 | 30 | self.begin = self.avg = self.max = self.num = self.next_job = 0 |
| 31 | 31 | ||
| 32 | self.join_job = join_job | ||
| 33 | |||
| 32 | # Count of times the job in start_time matched that in store_time | 34 | # Count of times the job in start_time matched that in store_time |
| 33 | self.matches = 0 | 35 | self.matches = 0 |
| 34 | # And the times it didn't | 36 | # And the times it didn't |
| @@ -39,9 +41,12 @@ class TimeTracker: | |||
| 39 | # any task is always skipped | 41 | # any task is always skipped |
| 40 | self.last_record = None | 42 | self.last_record = None |
| 41 | 43 | ||
| 44 | self.stored_dur = 0 | ||
| 45 | |||
| 42 | def store_time(self, next_record): | 46 | def store_time(self, next_record): |
| 43 | '''End duration of time.''' | 47 | '''End duration of time.''' |
| 44 | dur = (self.last_record.when - self.begin) if self.last_record else -1 | 48 | dur = (self.last_record.when - self.begin) if self.last_record else -1 |
| 49 | dur += self.stored_dur | ||
| 45 | 50 | ||
| 46 | if self.next_job == next_record.job: | 51 | if self.next_job == next_record.job: |
| 47 | self.last_record = next_record | 52 | self.last_record = next_record |
| @@ -49,13 +54,16 @@ class TimeTracker: | |||
| 49 | if self.last_record: | 54 | if self.last_record: |
| 50 | self.matches += 1 | 55 | self.matches += 1 |
| 51 | 56 | ||
| 52 | if dur > 0: | 57 | if self.join_job and self.next_job == self.last_record.job: |
| 58 | self.stored_dur += dur | ||
| 59 | elif dur > 0: | ||
| 53 | self.max = max(self.max, dur) | 60 | self.max = max(self.max, dur) |
| 54 | self.avg *= float(self.num / (self.num + 1)) | 61 | self.avg *= float(self.num / (self.num + 1)) |
| 55 | self.num += 1 | 62 | self.num += 1 |
| 56 | self.avg += dur / float(self.num) | 63 | self.avg += dur / float(self.num) |
| 57 | 64 | ||
| 58 | self.begin = 0 | 65 | self.begin = 0 |
| 66 | self.stored_dur = 0 | ||
| 59 | self.next_job = 0 | 67 | self.next_job = 0 |
| 60 | else: | 68 | else: |
| 61 | self.disjoints += 1 | 69 | self.disjoints += 1 |
| @@ -70,7 +78,6 @@ class TimeTracker: | |||
| 70 | 78 | ||
| 71 | self.next_job = record.job | 79 | self.next_job = record.job |
| 72 | 80 | ||
| 73 | |||
| 74 | class LeveledArray(object): | 81 | class LeveledArray(object): |
| 75 | """Groups statistics by the level of the task to which they apply""" | 82 | """Groups statistics by the level of the task to which they apply""" |
| 76 | def __init__(self): | 83 | def __init__(self): |
