Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double-counting of log statements in parser #89

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions carbontracker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,14 @@ def get_avg_power_usages(std_log_data):
for component in components:
powers: list[list[float]] = []
for comp, power in matches:
if power == "None":
powers.append([0.0])
continue
if comp == component:
p_list = power.strip("[").strip("]").split(" ")
p_power = [float(num) for num in p_list if num != ""]
powers.append(p_power)
if power == "None":
powers.append([0.0])
continue
else:
p_list = power.strip("[").strip("]").split(" ")
p_power = [float(num) for num in p_list if num != ""]
powers.append(p_power)
avg_power_usages[component] = powers

return avg_power_usages
Expand Down
4 changes: 4 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,7 @@ def test_parse_epoch_mismatch(
log_dir, "10151_2024-03-26T105926Z_carbontracker_output.log"
),
)

def test_parse_logs_mismatch(self):
results = parser.get_avg_power_usages("2024-03-26 10:51:53 - Epoch 1:\n2024-03-26 10:51:53 - Duration: 0:00:00.00\n2024-03-26 10:51:53 - Average power usage (W) for cpu: None\n2024-03-26 10:51:53 - Average power usage (W) for gpu: None")
self.assertEqual(results, {"cpu": [[0.0]], "gpu": [[0.0]]})
Loading