Skip to content

Commit

Permalink
Add details in file for further use
Browse files Browse the repository at this point in the history
Signed-off-by: Chaurasiya, Payal <[email protected]>
  • Loading branch information
payalcha committed Dec 6, 2024
1 parent 4c8d25a commit ea7c509
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/end_to_end/test_suites/memory_logs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def test_log_memory_usage(request, fx_federation):
aggregator_log_file = os.path.join(fx_federation.workspace_path, "aggregator.log")

memory_usage_dict = fed_helper.extract_memory_usage(aggregator_log_file)
# Write memory usage details to a file in workspace
fed_helper.write_memory_usage_to_file(memory_usage_dict, os.path.join(fx_federation.workspace_path,
"aggregator_memory_usage.log"))
# check memory usage entries for each round
assert len(memory_usage_dict) == request.config.num_rounds, \
"Memory usage details are not available for all rounds"
Expand All @@ -41,5 +44,10 @@ def test_log_memory_usage(request, fx_federation):
for collaborator in fx_federation.collaborators:
collaborator_log_file = os.path.join(fx_federation.workspace_path, f"{collaborator.collaborator_name}.log")
memory_usage_dict = fed_helper.extract_memory_usage(collaborator_log_file)
# Write memory usage details to a file in workspace
fed_helper.write_memory_usage_to_file(memory_usage_dict, os.path.join(fx_federation.workspace_path,
f"{collaborator.collaborator_name}_memory_usage.log"))
assert len(memory_usage_dict) == request.config.num_rounds, \
f"Memory usage details are not available for all rounds for collaborator {collaborator.collaborator_name}"

log.info("Memory usage details are available for all participants")
15 changes: 15 additions & 0 deletions tests/end_to_end/utils/federation_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,18 @@ def extract_memory_usage(log_file):
except Exception as e:
log.error(f"An error occurred while extracting memory usage: {e}")
raise e

def write_memory_usage_to_file(memory_usage_dict, output_file):
"""
Writes memory usage data to a file.
This function writes the specified memory usage data to the specified output file.
Args:
memory_usage_dict (dict): A dictionary containing the memory usage data.
output_file (str): The path to the output file to which to write the memory usage data.
"""
try:
with open(output_file, 'w') as file:
json.dump(memory_usage_dict, file, indent=4)
except Exception as e:
log.error(f"An error occurred while writing memory usage data to file: {e}")
raise e

0 comments on commit ea7c509

Please sign in to comment.