Fix date parsing when there's not milliseconds in the date
When OSProfiler is converting date string to datetime format "%Y-%m-%dT%H:%M:%S.%f", it will raise a ValueError exception if it receives dates with the following format: "%Y-%m-%dT%H:%M:%S" The "%Y-%m-%dT%H:%M:%S" date format applies when a notification occurs in the exact 0 millisecond of a certain second. Adding a try-except section for catching the exceptions when the date format is "%Y-%m-%dT%H:%M:%S". It will try first to match with "%Y-%m-%dT%H:%M:%S.%f" format and if it fails, it will go with the non-milliseconds date format matching. Closes-Bug: #1472735 Change-Id: I3fd0c3a3b26797f215d2ae7a8acc29c8619c0b68 Signed-off-by: Munoz, Obed N <obed.n.munoz@intel.com>
This commit is contained in:
parent
c2e9a73b3f
commit
5d202d481c
@ -74,8 +74,12 @@ def parse_notifications(notifications):
|
|||||||
if k not in skip_keys:
|
if k not in skip_keys:
|
||||||
result[key]["info"][k] = meta[k]
|
result[key]["info"][k] = meta[k]
|
||||||
|
|
||||||
|
try:
|
||||||
timestamp = datetime.datetime.strptime(n["timestamp"],
|
timestamp = datetime.datetime.strptime(n["timestamp"],
|
||||||
"%Y-%m-%dT%H:%M:%S.%f")
|
"%Y-%m-%dT%H:%M:%S.%f")
|
||||||
|
except ValueError:
|
||||||
|
timestamp = datetime.datetime.strptime(n["timestamp"],
|
||||||
|
"%Y-%m-%dT%H:%M:%S")
|
||||||
|
|
||||||
if meta["name"].endswith("stop"):
|
if meta["name"].endswith("stop"):
|
||||||
result[key]["info"]["finished"] = timestamp
|
result[key]["info"]["finished"] = timestamp
|
||||||
|
Loading…
Reference in New Issue
Block a user