Skip to content

Commit 6231d33

Browse files
committed
Move start_time to store in SimulationData and add sim_name to Framework trace name
1 parent e36dffb commit 6231d33

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

ipsframework/configurationManager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import uuid
1010
import logging
1111
import socket
12+
import time
1213
from multiprocessing import Queue, Process, set_start_method
1314
from .configobj import ConfigObj
1415
from . import ipsLogging
@@ -40,7 +41,8 @@ class SimulationData:
4041
entry in the configurationManager class
4142
"""
4243

43-
def __init__(self, sim_name):
44+
def __init__(self, sim_name, start_time=time.time()):
45+
self.start_time = start_time
4446
self.sim_name = sim_name
4547
self.portal_sim_name = None
4648
self.sim_root = None
@@ -281,7 +283,7 @@ def initialize(self, data_mgr, resource_mgr, task_mgr):
281283
sim_name_list.append(sim_name)
282284
sim_root_list.append(sim_root)
283285
log_file_list.append(log_file)
284-
new_sim = self.SimulationData(sim_name)
286+
new_sim = self.SimulationData(sim_name, self.fwk.start_time)
285287
conf['__PORTAL_SIM_NAME'] = sim_name
286288
new_sim.sim_conf = conf
287289
new_sim.config_file = conf_file
@@ -301,7 +303,7 @@ def initialize(self, data_mgr, resource_mgr, task_mgr):
301303
if not self.fwk_sim_name:
302304
fwk_sim_conf = conf.dict()
303305
fwk_sim_conf['SIM_NAME'] = '_'.join([conf['SIM_NAME'], 'FWK'])
304-
fwk_sim = self.SimulationData(fwk_sim_conf['SIM_NAME'])
306+
fwk_sim = self.SimulationData(fwk_sim_conf['SIM_NAME'], self.fwk.start_time)
305307
fwk_sim.sim_conf = fwk_sim_conf
306308
fwk_sim.sim_root = new_sim.sim_root
307309
fwk_sim.log_file = self.fwk.log_file # sys.stdout
@@ -502,7 +504,6 @@ def _create_component(self, comp_conf, sim_data):
502504

503505
# SIMYAN: removed else conditional, copying files in runspaceInit
504506
# component now
505-
506507
svc_response_q = Queue(0)
507508
invocation_q = Queue(0)
508509
component_id = ComponentID(class_name, sim_name)
@@ -512,7 +513,7 @@ def _create_component(self, comp_conf, sim_data):
512513
services_proxy = ServicesProxy(self.fwk, fwk_inq, svc_response_q,
513514
sim_data.sim_conf, log_pipe_name)
514515
new_component = component_class(services_proxy, comp_conf)
515-
new_component.__initialize__(component_id, invocation_q, self.fwk.start_time)
516+
new_component.__initialize__(component_id, invocation_q, sim_data.start_time)
516517
services_proxy.__initialize__(new_component)
517518
self.comp_registry.addEntry(component_id, svc_response_q,
518519
invocation_q, new_component,
@@ -643,7 +644,7 @@ def create_simulation(self, sim_name, config_file, override, sub_workflow=False)
643644
self.sim_name_list.append(sim_name)
644645
self.sim_root_list.append(sim_root)
645646
self.log_file_list.append(log_file)
646-
new_sim = self.SimulationData(sim_name)
647+
new_sim = self.SimulationData(sim_name, start_time=self.fwk.start_time if sub_workflow else time.time())
647648
new_sim.sim_conf = conf
648649
new_sim.config_file = config_file
649650
new_sim.sim_root = sim_root

ipsframework/ips.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
603603
portal_data['eventtype'] = eventType
604604
portal_data['ok'] = ok
605605
portal_data['comment'] = comment
606-
portal_data['walltime'] = '%.2f' % (event_time - self.start_time)
606+
portal_data['walltime'] = '%.2f' % (event_time - self.config_manager.sim_map[sim_name].start_time)
607607
portal_data['time'] = getTimeString(time.localtime(event_time))
608608

609609
topic_name = '_IPS_MONITOR'
@@ -647,7 +647,7 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
647647
portal_data['sim_runid'] = get_config(sim_name, 'RUN_ID')
648648
except KeyError:
649649
pass
650-
portal_data['startat'] = getTimeString(time.localtime(self.start_time))
650+
portal_data['startat'] = getTimeString(time.localtime(self.config_manager.sim_map[sim_name].start_time))
651651
portal_data['ips_version'] = get_versions()['version']
652652

653653
try:
@@ -659,12 +659,12 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
659659
portal_data['state'] = 'Completed'
660660
portal_data['stopat'] = getTimeString(time.localtime(event_time))
661661
# Zipkin json format
662-
portal_data['trace'] = {"timestamp": int(self.start_time*1e6),
663-
"duration": int((event_time - self.start_time)*1e6),
662+
portal_data['trace'] = {"timestamp": int(self.config_manager.sim_map[sim_name].start_time*1e6),
663+
"duration": int((event_time - self.config_manager.sim_map[sim_name].start_time)*1e6),
664664
"localEndpoint": {
665-
"serviceName": str(self.component_id)
665+
"serviceName": f'{sim_name}@{self.component_id}'
666666
},
667-
"id": hashlib.md5(str(self.component_id).encode()).hexdigest()[:16],
667+
"id": hashlib.md5(f'{sim_name}@{self.component_id}'.encode()).hexdigest()[:16],
668668
'tags': {'total_cores': str(self.resource_manager.total_cores)}}
669669
elif eventType == "IPS_CALL_END":
670670
trace = {} # Zipkin json format
@@ -675,7 +675,7 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok=True, ta
675675
trace['localEndpoint'] = {"serviceName": target}
676676
trace['name'] = operation
677677
trace['id'] = hashlib.md5(f"{target}:{operation}".encode()).hexdigest()[:16]
678-
trace["parentId"] = hashlib.md5(str(self.component_id).encode()).hexdigest()[:16]
678+
trace["parentId"] = hashlib.md5(f'{sim_name}@{self.component_id}'.encode()).hexdigest()[:16]
679679

680680
if trace:
681681
portal_data['trace'] = trace

0 commit comments

Comments
 (0)