Skip to content

Commit

Permalink
Merge pull request #170 from rosswhitfield/event_time
Browse files Browse the repository at this point in the history
Include event time in portal data
  • Loading branch information
rosswhitfield authored Sep 1, 2022
2 parents 7b6d6aa + e7281a1 commit b328a33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ipsframework/ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
from ipsframework.eventService import EventService
from ipsframework.cca_es_spec import initialize_event_service
from ipsframework.ips_es_spec import eventManager
from ipsframework.ipsutil import getTimeString
from ipsframework._version import get_versions

if sys.version[0] != '3': # noqa: E402
Expand Down Expand Up @@ -593,6 +594,7 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
whether the event indicates normal simulation execution, or an
error condition.
"""
event_time = time.time()
if self.verbose_debug:
self.debug('_send_monitor_event(%s - %s)', sim_name, eventType)
portal_data = {}
Expand All @@ -601,7 +603,9 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
portal_data['eventtype'] = eventType
portal_data['ok'] = ok
portal_data['comment'] = comment
portal_data['walltime'] = '%.2f' % (time.time() - self.start_time)
portal_data['walltime'] = '%.2f' % (event_time - self.start_time)
portal_data['time'] = getTimeString(time.localtime(event_time))

topic_name = '_IPS_MONITOR'
# portal_data['phystimestamp'] = self.timeStamp
get_config = self.config_manager.get_config_parameter
Expand Down Expand Up @@ -643,16 +647,14 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
portal_data['sim_runid'] = get_config(sim_name, 'RUN_ID')
except KeyError:
pass
portal_data['startat'] = time.strftime('%Y-%m-%d|%H:%M:%S%Z',
time.localtime(self.start_time))
portal_data['startat'] = getTimeString(time.localtime(self.start_time))
portal_data['ips_version'] = get_versions()['version']
elif eventType == 'IPS_END':
portal_data['state'] = 'Completed'
portal_data['stopat'] = time.strftime('%Y-%m-%d|%H:%M:%S%Z',
time.localtime())
portal_data['stopat'] = getTimeString(time.localtime(event_time))
# Zipkin json format
portal_data['trace'] = {"timestamp": int(self.start_time*1e6),
"duration": int((time.time() - self.start_time)*1e6),
"duration": int((event_time - self.start_time)*1e6),
"localEndpoint": {
"serviceName": str(self.component_id)
},
Expand Down
1 change: 1 addition & 0 deletions ipsframework/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def _send_monitor_event(self,
if event_time is None:
event_time = time.time()
portal_data['walltime'] = '%.2f' % (event_time - self.component_ref.start_time)
portal_data['time'] = ipsutil.getTimeString(time.localtime(event_time))

trace = {} # Zipkin json format
if start_time is not None and (elapsed_time is not None or end_time is not None) and target is not None and operation is not None:
Expand Down
2 changes: 2 additions & 0 deletions tests/helloworld/test_helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def handle(self):
assert event['sim_name'] == 'Hello_world_1'
assert event['seqnum'] == 0
assert 'ips_version' in event
assert 'time' in event

# get last event to check
event = json.loads(data[-1].split('\r\n')[-1])
Expand All @@ -364,6 +365,7 @@ def handle(self):
assert event['comment'] == 'Target = Hello_world_1@HelloWorker@2:init(0.000)'
assert event['state'] == 'Running'
assert event['sim_name'] == 'Hello_world_1'
assert 'time' in event
assert 'trace' in event
trace = event['trace']
assert 'duration' in trace
Expand Down

0 comments on commit b328a33

Please sign in to comment.