diff options
author | Nathan Binkert <binkertn@umich.edu> | 2007-01-03 10:12:55 -0800 |
---|---|---|
committer | Nathan Binkert <binkertn@umich.edu> | 2007-01-03 10:12:55 -0800 |
commit | fc45d42d01fba4f858012740e6a8a43ce5ecad9b (patch) | |
tree | 8f2e15b9f90416aaeb09d6398f91e6396934b57d /src/python/m5 | |
parent | 7d7f3d0e99eca98a5659e73bce56d615f0ed4fc3 (diff) | |
download | gem5-fc45d42d01fba4f858012740e6a8a43ce5ecad9b.tar.xz |
Add 'Time' as a parameter type that can accept various
formats for time (strings, datetime objects, etc.)
Advance system time to 1/1/2009
Clean up time management code a little bit
--HG--
extra : convert_revision : 28ebecc7ea6b12f4345c77a9a6b4bdf2e752c4f8
Diffstat (limited to 'src/python/m5')
-rw-r--r-- | src/python/m5/objects/Tsunami.py | 4 | ||||
-rw-r--r-- | src/python/m5/params.py | 52 |
2 files changed, 53 insertions, 3 deletions
diff --git a/src/python/m5/objects/Tsunami.py b/src/python/m5/objects/Tsunami.py index ac9020b47..18a776a7f 100644 --- a/src/python/m5/objects/Tsunami.py +++ b/src/python/m5/objects/Tsunami.py @@ -13,8 +13,8 @@ class TsunamiCChip(BasicPioDevice): class TsunamiIO(BasicPioDevice): type = 'TsunamiIO' - time = Param.UInt64(1136073600, - "System time to use (0 for actual time, default is 1/1/06)") + time = Param.Time('01/01/2009', + "System time to use ('Now' for actual time)") tsunami = Param.Tsunami(Parent.any, "Tsunami") frequency = Param.Frequency('1024Hz', "frequency of interrupts") diff --git a/src/python/m5/params.py b/src/python/m5/params.py index d83d5f73f..d570804d8 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -44,7 +44,12 @@ # ##################################################################### -import sys, inspect, copy +import copy +import datetime +import inspect +import sys +import time + import convert from util import * @@ -513,6 +518,50 @@ class EthernetAddr(ParamValue): else: return self.value +def parse_time(value): + strings = [ "%a %b %d %H:%M:%S %Z %Y", + "%a %b %d %H:%M:%S %Z %Y", + "%Y/%m/%d %H:%M:%S", + "%Y/%m/%d %H:%M", + "%Y/%m/%d", + "%m/%d/%Y %H:%M:%S", + "%m/%d/%Y %H:%M", + "%m/%d/%Y", + "%m/%d/%y %H:%M:%S", + "%m/%d/%y %H:%M", + "%m/%d/%y"] + + for string in strings: + try: + return time.strptime(value, string) + except ValueError: + pass + + raise ValueError, "Could not parse '%s' as a time" % value + +class Time(ParamValue): + cxx_type = 'time_t' + def __init__(self, value): + if isinstance(value, time.struct_time): + self.value = time.mktime(value) + elif isinstance(value, int): + self.value = value + elif isinstance(value, str): + if value in ('Now', 'Today'): + self.value = time.time() + else: + self.value = time.mktime(parse_time(value)) + elif isinstance(value, (datetime.datetime, datetime.date)): + self.value = time.mktime(value.timetuple()) + else: + raise ValueError, "Could not parse '%s' as a time" % value + + def __str__(self): + return str(int(self.value)) + + def ini_str(self): + return str(int(self.value)) + # Enumerated types are a little more complex. The user specifies the # type as Enum(foo) where foo is either a list or dictionary of # alternatives (typically strings, but not necessarily so). (In the @@ -973,6 +1022,7 @@ __all__ = ['Param', 'VectorParam', 'NetworkBandwidth', 'MemoryBandwidth', 'Range', 'AddrRange', 'TickRange', 'MaxAddr', 'MaxTick', 'AllMemory', + 'Time', 'NextEthernetAddr', 'NULL', 'Port', 'VectorPort'] |