Create a warning function that only warns once for permission errors.
()
| 159 | |
| 160 | |
| 161 | def _create_warn_function(): |
| 162 | """Create a warning function that only warns once for permission errors.""" |
| 163 | already_warned = False |
| 164 | |
| 165 | def warn_permission_denied(energy_path: str): |
| 166 | nonlocal already_warned |
| 167 | if not already_warned: |
| 168 | logger.warning( |
| 169 | "\tRAPL - Permission denied reading RAPL file %s. " |
| 170 | "You can grant read permission with: " |
| 171 | "sudo chmod -R a+r /sys/class/powercap/*", |
| 172 | energy_path, |
| 173 | ) |
| 174 | already_warned = True |
| 175 | else: |
| 176 | logger.debug( |
| 177 | "\tRAPL - Permission denied reading RAPL file %s. " |
| 178 | "You can grant read permission with: " |
| 179 | "sudo chmod -R a+r /sys/class/powercap/*", |
| 180 | energy_path, |
| 181 | ) |
| 182 | |
| 183 | return warn_permission_denied |
| 184 | |
| 185 | |
| 186 | def is_rapl_available(rapl_dir: Optional[str] = None) -> bool: |
no outgoing calls
no test coverage detected
searching dependent graphs…