Skip to content

Commit

Permalink
Display logging for generic CPU handler
Browse files Browse the repository at this point in the history
  • Loading branch information
PedramBakh committed Sep 20, 2024
1 parent 97ff1ef commit ecf4ae6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions carbontracker/components/cpu/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_cpu_brand(self) -> str:
try:
info = cpuinfo.get_cpu_info()
cpu_brand = info.get('brand_raw', '')
logger.info(f"Detected CPU: {cpu_brand}")
logger.err_info(f"Detected CPU: {cpu_brand}")
return cpu_brand
except Exception as e:
logger.err_warn(f"Failed to get CPU info: {e}")
Expand Down Expand Up @@ -60,12 +60,9 @@ def calculate_average_tdp(self) -> float:
return statistics.mean(self.cpu_power_data.values()) / 2 # 50% utilization

def init(self):
logger.info("[setup] CPU Tracking...")
if not self.cpu_brand:
logger.err_warn("Failed to detect CPU. Falling back to generic CPU handler.")
self.cpu_brand = "Unknown CPU"
else:
logger.info(f"CPU Model: {self.cpu_brand}")

self.tdp = self.find_matching_tdp()

Expand All @@ -74,7 +71,7 @@ def init(self):
logger.err_warn(f"No matching TDP found for CPU: {self.cpu_brand}. Using average TDP of {self.tdp:.2f}W as fallback.")
else:
self.tdp = self.tdp / 2 # 50% utilization
logger.info(f"Using TDP of {self.tdp:.2f}W for {self.cpu_brand}")
logger.err_info(f"Using TDP of {self.tdp:.2f}W for {self.cpu_brand}")

def find_matching_tdp(self) -> Optional[float]:
# Try direct match
Expand All @@ -85,7 +82,7 @@ def find_matching_tdp(self) -> Optional[float]:
cpu_name_without_freq = self.cpu_brand.split('@')[0].strip()
for cpu_name, tdp in self.cpu_power_data.items():
if cpu_name_without_freq in cpu_name:
logger.info(f"Matched CPU {self.cpu_brand} to {cpu_name} with TDP {tdp}W")
logger.err_info(f"Matched CPU {self.cpu_brand} to {cpu_name} with TDP {tdp}W")
return tdp

return None
Expand Down

0 comments on commit ecf4ae6

Please sign in to comment.