Skip to content

Commit a87bd19

Browse files
author
Vasileios Karakasis
committed
Use an OrderedDict for Python 3.6 and 3.7
1 parent 4f684ec commit a87bd19

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

reframe/utility/profile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# A lightweight time profiler
77

88
import time
9+
import sys
10+
11+
from collections import OrderedDict
912

1013

1114
class ProfilerError(Exception):
@@ -30,7 +33,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
3033
class TimeProfiler:
3134
def __init__(self):
3235
self._region_stack = ['root']
33-
self._region_times = {}
36+
if sys.version_info[:2] < (3, 8):
37+
self._region_times = OrderedDict()
38+
else:
39+
self._region_times = {}
3440

3541
@property
3642
def current_region(self):
@@ -55,7 +61,7 @@ def exit_region(self):
5561
self._region_stack.pop()
5662

5763
def total_time(self, region_name):
58-
for region in reversed(self._region_times):
64+
for region in reversed(self._region_times.keys()):
5965
if (region == region_name or
6066
region.rsplit(':', maxsplit=1)[-1] == region_name):
6167
timestamp, elapsed = self._region_times[region]

0 commit comments

Comments
 (0)