from msprof_analyze.prof_common.file_manager import FileManager
from msprof_analyze.prof_common.constant import Constant
class MsprofCommunicationTimeAdapter:
P2P_HCOM = ["hcom_send", "hcom_receive", "hcom_batchsendrecv"]
TOTAL = "total"
def __init__(self, file_path):
self.file_path = file_path
def generate_comm_time_data(self):
output_communication = {"step": {Constant.P2P: {}, Constant.COLLECTIVE: {}}}
communication_data = FileManager.read_json_file(self.file_path)
for communication_op, communication_info in communication_data.items():
lower_op_name = communication_op.lower()
if any(lower_op_name.startswith(start_str) for start_str in self.P2P_HCOM):
output_communication["step"][Constant.P2P][communication_op] = communication_info
elif lower_op_name.startswith(self.TOTAL):
continue
else:
output_communication["step"][Constant.COLLECTIVE][communication_op] = communication_info
return output_communication