-
-
Notifications
You must be signed in to change notification settings - Fork 296
perf: reduce tracker cold-start and concurrent measurement overhead #1246
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
Open
davidberenstein1957
wants to merge
17
commits into
master
Choose a base branch
from
davidberenstein1957/codecarbon-api-speed-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1c87924
perf: reduce tracker cold-start and concurrent measurement overhead
davidberenstein1957 9a5e0ba
perf: prefer fast cpu_load on Mac ARM and fix monitor CLI args
davidberenstein1957 5afe403
fix: restore test suite compatibility with perf optimizations
davidberenstein1957 fa53a02
chore: add benchmark and profiling scripts for tracker perf work
davidberenstein1957 ab9bcec
chore: drop benchmark and profiling scripts from PR
davidberenstein1957 8f95e9f
fix: resolve CI failures for pre-commit, wheel tests, and coverage
davidberenstein1957 fe75a1e
fix: make hardware_cache tests portable on Linux CI
davidberenstein1957 cf356ed
test: raise patch coverage for perf optimization changes
davidberenstein1957 06d0ede
perf: cache output handlers and add throughput benchmarks
davidberenstein1957 c961b35
fix: satisfy pre-commit for benchmark scripts
davidberenstein1957 b06dec3
refactor: drop handler singleton cache, keep targeted perf wins
davidberenstein1957 2427513
refactor: remove API/output micro-caches and benchmark tooling
davidberenstein1957 c0ca28e
refactor: simplify probe caches with stdlib lru_cache
davidberenstein1957 ae79098
fix: avoid eager GPU imports in hardware_cache.clear_cache
davidberenstein1957 8334302
refactor: use single monitor CLI entry point and update docs
davidberenstein1957 ab80373
fix: make hardware cache plans fully self-contained
davidberenstein1957 8ccb30e
test: expect tracking_mode in RAPL CPU setup assertion
davidberenstein1957 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,27 +4,29 @@ | |
| https://software.intel.com/content/www/us/en/develop/articles/intel-power-gadget.html | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| from functools import lru_cache | ||
| from typing import Dict, Optional, Tuple | ||
|
|
||
| import pandas as pd | ||
| import psutil | ||
| from rapidfuzz import fuzz, process, utils | ||
|
|
||
| from codecarbon.core.rapl import RAPLFile | ||
| from codecarbon.core.units import Time | ||
| from codecarbon.core.util import count_cpus, detect_cpu_model | ||
| from codecarbon.external.logger import logger | ||
| from codecarbon.input import DataSource | ||
|
|
||
| # default W value per core for a CPU if no model is found in the ref csv | ||
| DEFAULT_POWER_PER_CORE = 4 | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
| def is_powergadget_available() -> bool: | ||
| """ | ||
| Checks if Intel Power Gadget is available on the system. | ||
|
|
@@ -44,6 +46,10 @@ def is_powergadget_available() -> bool: | |
| return False | ||
|
|
||
|
|
||
| def clear_powergadget_cache() -> None: | ||
| is_powergadget_available.cache_clear() | ||
|
|
||
|
|
||
| def _get_candidate_bases(rapl_dir: str) -> list: | ||
| """Get list of directories to scan for RAPL files.""" | ||
| default_rapl_dir = "/sys/class/powercap/intel-rapl/subsystem" | ||
|
|
@@ -366,6 +372,8 @@ def get_cpu_details(self) -> Dict: | |
| self._log_values() | ||
| cpu_details = {} | ||
| try: | ||
| import pandas as pd | ||
|
|
||
| cpu_data = pd.read_csv(self._log_file_path).dropna() | ||
| for col_name in cpu_data.columns: | ||
| if col_name in ["System Time", "Elapsed Time (sec)", "RDTSC"]: | ||
|
|
@@ -887,21 +895,21 @@ def __init__(self): | |
| self.model, self.tdp = self._main() | ||
|
|
||
| @staticmethod | ||
| def _get_cpu_constant_power(match: str, cpu_power_df: pd.DataFrame) -> int: | ||
| def _get_cpu_constant_power(match: str, cpu_power_df) -> int: | ||
| """Extract constant power from matched CPU""" | ||
| return float(cpu_power_df[cpu_power_df["Name"] == match]["TDP"].values[0]) | ||
|
|
||
| def _get_cpu_power_from_registry(self, cpu_model_raw: str) -> Optional[int]: | ||
| from codecarbon.input import DataSource | ||
|
|
||
| cpu_power_df = DataSource().get_cpu_power_data() | ||
| cpu_matching = self._get_matching_cpu(cpu_model_raw, cpu_power_df) | ||
| if cpu_matching: | ||
| power = self._get_cpu_constant_power(cpu_matching, cpu_power_df) | ||
| return power | ||
| return None | ||
|
|
||
| def _get_matching_cpu( | ||
| self, model_raw: str, cpu_df: pd.DataFrame, greedy=False | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| ) -> str: | ||
| def _get_matching_cpu(self, model_raw: str, cpu_df, greedy=False) -> str: | ||
| """ | ||
| Get matching cpu name | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ | |
|
|
||
| from typing import Dict, Optional | ||
|
|
||
| import pandas as pd | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same in this file |
||
| from codecarbon.core import electricitymaps_api | ||
| from codecarbon.core.units import EmissionsPerKWh, Energy | ||
| from codecarbon.external.geography import CloudMetadata, GeoMetadata | ||
|
|
@@ -64,7 +62,7 @@ def get_cloud_emissions( | |
| ) | ||
| return energy.kWh * (self._force_carbon_intensity_g_co2e_kwh / 1000.0) | ||
|
|
||
| df: pd.DataFrame = self._data_source.get_cloud_emissions_data() | ||
| df = self._data_source.get_cloud_emissions_data() | ||
| try: | ||
| emissions_per_kWh: EmissionsPerKWh = EmissionsPerKWh.from_g_per_kWh( | ||
| df.loc[ | ||
|
|
@@ -99,7 +97,7 @@ def get_cloud_country_name(self, cloud: CloudMetadata) -> str: | |
| """ | ||
| Returns the Country Name where the cloud region is located | ||
| """ | ||
| df: pd.DataFrame = self._data_source.get_cloud_emissions_data() | ||
| df = self._data_source.get_cloud_emissions_data() | ||
| flags = (df["provider"] == cloud.provider) & (df["region"] == cloud.region) | ||
| selected = df.loc[flags] | ||
| if not len(selected): | ||
|
|
@@ -114,7 +112,7 @@ def get_cloud_country_iso_code(self, cloud: CloudMetadata) -> str: | |
| """ | ||
| Returns the Country ISO Code where the cloud region is located | ||
| """ | ||
| df: pd.DataFrame = self._data_source.get_cloud_emissions_data() | ||
| df = self._data_source.get_cloud_emissions_data() | ||
| flags = (df["provider"] == cloud.provider) & (df["region"] == cloud.region) | ||
| selected = df.loc[flags] | ||
| if not len(selected): | ||
|
|
@@ -129,7 +127,7 @@ def get_cloud_geo_region(self, cloud: CloudMetadata) -> str: | |
| """ | ||
| Returns the State/City where the cloud region is located | ||
| """ | ||
| df: pd.DataFrame = self._data_source.get_cloud_emissions_data() | ||
| df = self._data_source.get_cloud_emissions_data() | ||
| flags = (df["provider"] == cloud.provider) & (df["region"] == cloud.region) | ||
| selected = df.loc[flags] | ||
| if not len(selected): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not delete this, if we are using pandas only for typing we can do