On-demand warm-up based on system reboot. The warm-up function is run once after reboot for every benchmark key. The keys are cached in a file in cache/v8_perf. This relies on the caller creating this directory.
| 801 | |
| 802 | |
| 803 | class CachedWarmupManager(WarmupManager): |
| 804 | """On-demand warm-up based on system reboot. |
| 805 | |
| 806 | The warm-up function is run once after reboot for every benchmark key. |
| 807 | The keys are cached in a file in cache/v8_perf. This relies on the caller |
| 808 | creating this directory. |
| 809 | """ |
| 810 | def __init__(self): |
| 811 | self.cache_handler = CacheHandler(WARMUP_CACHE_FILE) |
| 812 | self.cache = self.cache_handler.read_cache() |
| 813 | self.last_reboot = psutil.boot_time() |
| 814 | self.trim_cache() |
| 815 | # Ensure the trimmed version is on disk. |
| 816 | self.cache_handler.write_cache(self.cache) |
| 817 | |
| 818 | def is_warmed_up(self, timestamp): |
| 819 | return timestamp > self.last_reboot |
| 820 | |
| 821 | def trim_cache(self): |
| 822 | """Prevent obsolete entries occupying the cache file.""" |
| 823 | self.cache = dict( |
| 824 | (k, v) for k, v in self.cache.items() if self.is_warmed_up(v)) |
| 825 | |
| 826 | def maybe_warm_up(self, name, warmup_fun): |
| 827 | if self.is_warmed_up(self.cache.get(name, 0)): |
| 828 | return |
| 829 | |
| 830 | logging.info(f'Warm-up run of {name} - disregarding output.') |
| 831 | try: |
| 832 | warmup_fun() |
| 833 | finally: |
| 834 | self.cache[name] = time.time() |
| 835 | self.cache_handler.write_cache(self.cache) |
| 836 | logging.info(f'Warm-up done.') |
| 837 | |
| 838 | |
| 839 | class Platform(object): |