amd-debug-tools 0.2.18__tar.gz → 0.2.19__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {amd_debug_tools-0.2.18/src/amd_debug_tools.egg-info → amd_debug_tools-0.2.19}/PKG-INFO +1 -1
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/common.py +42 -11
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/database.py +80 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/failures.py +1 -1
- amd_debug_tools-0.2.19/src/amd_debug/power_rails.py +195 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/s2idle.py +8 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/sleep_report.py +174 -22
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/templates/html +11 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/validator.py +20 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19/src/amd_debug_tools.egg-info}/PKG-INFO +1 -1
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug_tools.egg-info/SOURCES.txt +2 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug_tools.egg-info/top_level.txt +1 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_database.py +100 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_installer.py +194 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_kernel.py +163 -2
- amd_debug_tools-0.2.19/src/test_power_rails.py +373 -0
- amd_debug_tools-0.2.19/src/test_pstate.py +323 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_sleep_report.py +47 -2
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_validator.py +315 -3
- amd_debug_tools-0.2.19/src/test_wake.py +504 -0
- amd_debug_tools-0.2.18/src/test_pstate.py +0 -164
- amd_debug_tools-0.2.18/src/test_wake.py +0 -216
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/.github/workflows/ci.yml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/.github/workflows/mirror.yml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/.gitignore +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/.pre-commit-config.yaml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/.vscode/settings.json +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/LICENSE +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/Makefile +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/README.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/amd_bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/amd_pstate.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/amd_s2idle.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/amd_ttm.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/docs/amd-bios.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/docs/amd-pstate.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/docs/amd-s2idle.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/docs/amd-ttm.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/docs/in-tree.md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/install_deps.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/psr.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/pyproject.toml +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/setup.cfg +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/__init__.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/acpi.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/bash/amd-s2idle +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/battery.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/display.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/installer.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/kernel.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/prerequisites.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/pstate.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/s2idle-hook +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/templates/md +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/templates/stdout +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/templates/txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/ttm.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug/wake.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug_tools.egg-info/dependency_links.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug_tools.egg-info/entry_points.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/amd_debug_tools.egg-info/requires.txt +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/launcher.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_acpi.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_batteries.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_bios.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_common.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_display.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_failures.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_launcher.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_prerequisites.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_s2idle.py +0 -0
- {amd_debug_tools-0.2.18 → amd_debug_tools-0.2.19}/src/test_ttm.py +0 -0
|
@@ -13,6 +13,8 @@ import time
|
|
|
13
13
|
import struct
|
|
14
14
|
import subprocess
|
|
15
15
|
import sys
|
|
16
|
+
import stat
|
|
17
|
+
import pathlib
|
|
16
18
|
from ast import literal_eval
|
|
17
19
|
from datetime import date, timedelta
|
|
18
20
|
|
|
@@ -133,18 +135,46 @@ def _configure_log(prefix) -> str:
|
|
|
133
135
|
path = os.environ.get("XDG_DATA_HOME") or os.path.join(
|
|
134
136
|
home, ".local", "share", "amd-debug-tools"
|
|
135
137
|
)
|
|
136
|
-
|
|
137
|
-
log
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
|
|
139
|
+
# Prevent symlink attacks on log directory/file when running as root
|
|
140
|
+
path_obj = pathlib.Path(path)
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
if path_obj.exists():
|
|
144
|
+
if path_obj.is_symlink():
|
|
145
|
+
raise ValueError(f"Log directory is a symlink: {path}")
|
|
146
|
+
else:
|
|
147
|
+
os.makedirs(path, mode=0o755, exist_ok=True)
|
|
148
|
+
if path_obj.is_symlink():
|
|
149
|
+
raise ValueError(f"Log directory became a symlink during creation: {path}")
|
|
150
|
+
|
|
144
151
|
if "SUDO_UID" in os.environ:
|
|
145
|
-
os.
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
os.lchown(path, int(os.environ["SUDO_UID"]), int(os.environ["SUDO_GID"]))
|
|
153
|
+
except (ValueError, OSError) as e:
|
|
154
|
+
logging.warning(f"Cannot create safe log directory: {e}")
|
|
155
|
+
log = "/dev/null"
|
|
156
|
+
level = logging.WARNING
|
|
157
|
+
else:
|
|
158
|
+
log = os.path.join(path, f"{prefix}-{date.today()}.txt")
|
|
159
|
+
|
|
160
|
+
try:
|
|
161
|
+
fd = os.open(
|
|
162
|
+
log,
|
|
163
|
+
os.O_WRONLY | os.O_CREAT | os.O_NOFOLLOW,
|
|
164
|
+
mode=stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, # 0o644
|
|
165
|
+
)
|
|
166
|
+
try:
|
|
167
|
+
os.close(fd)
|
|
168
|
+
if "SUDO_UID" in os.environ:
|
|
169
|
+
os.lchown(log, int(os.environ["SUDO_UID"]), int(os.environ["SUDO_GID"]))
|
|
170
|
+
except Exception:
|
|
171
|
+
os.close(fd)
|
|
172
|
+
raise
|
|
173
|
+
except FileExistsError:
|
|
174
|
+
if os.path.islink(log):
|
|
175
|
+
raise ValueError(f"Log file is a symlink: {log}")
|
|
176
|
+
|
|
177
|
+
level = logging.DEBUG
|
|
148
178
|
else:
|
|
149
179
|
log = "/dev/null"
|
|
150
180
|
level = logging.WARNING
|
|
@@ -392,6 +422,7 @@ def relaunch_sudo() -> None:
|
|
|
392
422
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
393
423
|
"XDG_SESSION_TYPE",
|
|
394
424
|
"XDG_DATA_DIRS",
|
|
425
|
+
"KDE_SESSION_VERSION",
|
|
395
426
|
"SSH_CLIENT",
|
|
396
427
|
"SSH_TTY"
|
|
397
428
|
]:
|
|
@@ -6,7 +6,7 @@ import os
|
|
|
6
6
|
|
|
7
7
|
from amd_debug.common import read_file
|
|
8
8
|
|
|
9
|
-
SCHEMA_VERSION =
|
|
9
|
+
SCHEMA_VERSION = 2
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def migrate(cur, user_version) -> None:
|
|
@@ -17,6 +17,18 @@ def migrate(cur, user_version) -> None:
|
|
|
17
17
|
# - add priority column
|
|
18
18
|
if val == 0:
|
|
19
19
|
cur.execute("ALTER TABLE debug ADD COLUMN priority INTEGER")
|
|
20
|
+
# Schema 2
|
|
21
|
+
# - add power_rails table
|
|
22
|
+
if val == 1:
|
|
23
|
+
cur.execute(
|
|
24
|
+
"CREATE TABLE IF NOT EXISTS power_rails ("
|
|
25
|
+
"t0 INTEGER, "
|
|
26
|
+
"label TEXT, "
|
|
27
|
+
"e0 REAL, "
|
|
28
|
+
"e1 REAL, "
|
|
29
|
+
"scale REAL, "
|
|
30
|
+
"PRIMARY KEY(t0, label))"
|
|
31
|
+
)
|
|
20
32
|
# Update schema if necessary
|
|
21
33
|
if val != user_version:
|
|
22
34
|
cur.execute(f"PRAGMA user_version = {user_version}")
|
|
@@ -85,6 +97,15 @@ class SleepDatabase:
|
|
|
85
97
|
"full INTEGER,"
|
|
86
98
|
"unit TEXT)"
|
|
87
99
|
)
|
|
100
|
+
cur.execute(
|
|
101
|
+
"CREATE TABLE IF NOT EXISTS power_rails ("
|
|
102
|
+
"t0 INTEGER,"
|
|
103
|
+
"label TEXT,"
|
|
104
|
+
"e0 REAL,"
|
|
105
|
+
"e1 REAL,"
|
|
106
|
+
"scale REAL,"
|
|
107
|
+
"PRIMARY KEY(t0, label))"
|
|
108
|
+
)
|
|
88
109
|
self.prereq_data_cnt = 0
|
|
89
110
|
|
|
90
111
|
if new:
|
|
@@ -167,7 +188,7 @@ class SleepDatabase:
|
|
|
167
188
|
else:
|
|
168
189
|
cur.execute(
|
|
169
190
|
"""
|
|
170
|
-
INSERT into battery (t0, name, b0, b1, full, unit)
|
|
191
|
+
INSERT into battery (t0, name, b0, b1, full, unit)
|
|
171
192
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
172
193
|
""",
|
|
173
194
|
(
|
|
@@ -180,6 +201,46 @@ class SleepDatabase:
|
|
|
180
201
|
),
|
|
181
202
|
)
|
|
182
203
|
|
|
204
|
+
def record_power_rail_energy(self, label, energy, scale):
|
|
205
|
+
"""Helper function to record power rail energy
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
label: Rail label (e.g., "CPU_VDDCR_PH1_IN_POWER_1")
|
|
209
|
+
energy: Raw energy accumulator value
|
|
210
|
+
scale: Scale factor to convert raw to Joules
|
|
211
|
+
|
|
212
|
+
First call (prep): INSERT with e0
|
|
213
|
+
Second call (post): UPDATE with e1
|
|
214
|
+
"""
|
|
215
|
+
assert self.db
|
|
216
|
+
assert self.last_suspend
|
|
217
|
+
cur = self.db.cursor()
|
|
218
|
+
cur.execute(
|
|
219
|
+
"SELECT e0 FROM power_rails WHERE t0=? AND label=?",
|
|
220
|
+
(int(self.last_suspend.strftime("%Y%m%d%H%M%S")), label),
|
|
221
|
+
)
|
|
222
|
+
result = cur.fetchone()
|
|
223
|
+
if result is None:
|
|
224
|
+
# First call (prep): INSERT with e0
|
|
225
|
+
cur.execute(
|
|
226
|
+
"""
|
|
227
|
+
INSERT INTO power_rails (t0, label, e0, e1, scale)
|
|
228
|
+
VALUES (?, ?, ?, NULL, ?)
|
|
229
|
+
""",
|
|
230
|
+
(
|
|
231
|
+
int(self.last_suspend.strftime("%Y%m%d%H%M%S")),
|
|
232
|
+
label,
|
|
233
|
+
energy,
|
|
234
|
+
scale,
|
|
235
|
+
),
|
|
236
|
+
)
|
|
237
|
+
else:
|
|
238
|
+
# Second call (post): UPDATE with e1
|
|
239
|
+
cur.execute(
|
|
240
|
+
"UPDATE power_rails SET e1=? WHERE t0=? AND label=?",
|
|
241
|
+
(energy, int(self.last_suspend.strftime("%Y%m%d%H%M%S")), label),
|
|
242
|
+
)
|
|
243
|
+
|
|
183
244
|
def record_cycle_data(self, message, symbol) -> None:
|
|
184
245
|
"""Helper function to record a message to cycle_data database"""
|
|
185
246
|
assert self.last_suspend
|
|
@@ -316,6 +377,23 @@ class SleepDatabase:
|
|
|
316
377
|
)
|
|
317
378
|
return cur.fetchall()
|
|
318
379
|
|
|
380
|
+
def report_power_rails(self, t0=None) -> list:
|
|
381
|
+
"""Helper function to report power rails for a given timestamp
|
|
382
|
+
|
|
383
|
+
Returns:
|
|
384
|
+
List of tuples: (t0, label, e0, e1, scale)
|
|
385
|
+
"""
|
|
386
|
+
assert self.db
|
|
387
|
+
if t0 is None:
|
|
388
|
+
assert self.last_suspend
|
|
389
|
+
t0 = self.last_suspend
|
|
390
|
+
cur = self.db.cursor()
|
|
391
|
+
cur.execute(
|
|
392
|
+
"SELECT * FROM power_rails WHERE t0=?",
|
|
393
|
+
(int(t0.strftime("%Y%m%d%H%M%S")),),
|
|
394
|
+
)
|
|
395
|
+
return cur.fetchall()
|
|
396
|
+
|
|
319
397
|
def get_last_prereq_ts(self) -> int:
|
|
320
398
|
"""Helper function to report the last line from prereq database"""
|
|
321
399
|
assert self.db
|
|
@@ -441,7 +441,7 @@ class LowHardwareSleepResidency(S0i3Failure):
|
|
|
441
441
|
super().__init__()
|
|
442
442
|
self.description = "System had low hardware sleep residency"
|
|
443
443
|
self.explanation = (
|
|
444
|
-
f"The system was asleep for {
|
|
444
|
+
f"The system was asleep for {duration}, but only spent {percent:.2%} "
|
|
445
445
|
"of this time in a hardware sleep state. In sleep cycles that are at least "
|
|
446
446
|
"60 seconds long it's expected you spend above 90 percent of the cycle in "
|
|
447
447
|
"hardware sleep."
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""Discovery and reading of IIO power monitor rails.
|
|
3
|
+
|
|
4
|
+
This module discovers power monitoring chips via the Linux IIO (Industrial I/O)
|
|
5
|
+
sysfs interface and reads energy accumulator values for suspend power consumption analysis.
|
|
6
|
+
|
|
7
|
+
Each power monitor chip exposes N rails (typically 1-4). For rail N, the IIO
|
|
8
|
+
driver provides:
|
|
9
|
+
- in_powerN_label -- human-readable rail name
|
|
10
|
+
- in_energyN_raw -- raw energy accumulator value
|
|
11
|
+
- in_energyN_scale -- scale factor to convert raw to Joules
|
|
12
|
+
|
|
13
|
+
We capture energy accumulators before and after suspend, then calculate average
|
|
14
|
+
power as: Power (W) = ΔEnergy (J) / Δtime (s)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Set
|
|
22
|
+
|
|
23
|
+
IIO_DEVICES_ROOT = Path("/sys/bus/iio/devices")
|
|
24
|
+
|
|
25
|
+
# Supported power monitor chip names (extensible set)
|
|
26
|
+
SUPPORTED_POWER_CHIPS: Set[str] = {
|
|
27
|
+
"pac1954",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Maximum channel number to scan (some future chips may have more)
|
|
31
|
+
MAX_CHANNELS = 16
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _read_text(path: Path) -> str:
|
|
35
|
+
"""Read and strip text from a sysfs file."""
|
|
36
|
+
return path.read_text().strip()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _read_float(path: Path) -> float:
|
|
40
|
+
"""Read a floating-point value from a sysfs file."""
|
|
41
|
+
return float(_read_text(path))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class PowerRail:
|
|
46
|
+
"""A single named power rail on an IIO power monitor chip.
|
|
47
|
+
|
|
48
|
+
Attributes:
|
|
49
|
+
device: IIO device name (e.g., "iio:device0")
|
|
50
|
+
channel: Channel number (1..N)
|
|
51
|
+
label: Human-readable rail name (e.g., "CPU_VDDCR_PH1_IN_POWER_1")
|
|
52
|
+
sysfs: Path to the device directory in sysfs
|
|
53
|
+
energy_scale: Scale factor to convert raw energy to Joules
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
device: str
|
|
57
|
+
channel: int
|
|
58
|
+
label: str
|
|
59
|
+
sysfs: Path
|
|
60
|
+
energy_scale: float
|
|
61
|
+
|
|
62
|
+
def read_energy_raw(self) -> float:
|
|
63
|
+
"""Read the current raw energy accumulator value.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Raw energy accumulator value (units depend on chip, use energy_scale
|
|
67
|
+
to convert to Joules)
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
OSError: If the sysfs file cannot be read
|
|
71
|
+
"""
|
|
72
|
+
return _read_float(self.sysfs / f"in_energy{self.channel}_raw")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _discover_chip_rails(device_dir: Path, chip_ids: Set[str] = None) -> list[PowerRail]:
|
|
76
|
+
"""Discover all enabled power rails for a single IIO device.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
device_dir: Path to the IIO device directory (e.g., /sys/bus/iio/devices/iio:device0)
|
|
80
|
+
chip_ids: Set of supported chip IDs to filter by (default: SUPPORTED_POWER_CHIPS)
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
List of PowerRail objects for enabled rails on this device
|
|
84
|
+
"""
|
|
85
|
+
if chip_ids is None:
|
|
86
|
+
chip_ids = SUPPORTED_POWER_CHIPS
|
|
87
|
+
|
|
88
|
+
# Check if this is a supported power monitor chip
|
|
89
|
+
name_path = device_dir / "name"
|
|
90
|
+
if not name_path.exists():
|
|
91
|
+
return []
|
|
92
|
+
|
|
93
|
+
chip_name = _read_text(name_path)
|
|
94
|
+
if chip_name not in chip_ids:
|
|
95
|
+
return []
|
|
96
|
+
|
|
97
|
+
device_id = device_dir.name
|
|
98
|
+
rails: list[PowerRail] = []
|
|
99
|
+
|
|
100
|
+
# Scan for power rails (channel 1..MAX_CHANNELS)
|
|
101
|
+
for n in range(1, MAX_CHANNELS + 1):
|
|
102
|
+
label_path = device_dir / f"in_power{n}_label"
|
|
103
|
+
if not label_path.exists():
|
|
104
|
+
continue
|
|
105
|
+
|
|
106
|
+
label = _read_text(label_path)
|
|
107
|
+
if not label:
|
|
108
|
+
continue # Unwired or disabled rail
|
|
109
|
+
|
|
110
|
+
# Read the energy scale factor
|
|
111
|
+
scale_path = device_dir / f"in_energy{n}_scale"
|
|
112
|
+
if not scale_path.exists():
|
|
113
|
+
continue # No energy accumulator for this rail
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
energy_scale = _read_float(scale_path)
|
|
117
|
+
rails.append(
|
|
118
|
+
PowerRail(
|
|
119
|
+
device=device_id,
|
|
120
|
+
channel=n,
|
|
121
|
+
label=label,
|
|
122
|
+
sysfs=device_dir,
|
|
123
|
+
energy_scale=energy_scale,
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
except (FileNotFoundError, ValueError, OSError):
|
|
127
|
+
# Skip rails with missing or invalid scale files
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
return rails
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def discover_rails(
|
|
134
|
+
iio_root: Path = IIO_DEVICES_ROOT,
|
|
135
|
+
chip_ids: Set[str] = None,
|
|
136
|
+
) -> list[PowerRail]:
|
|
137
|
+
"""Discover all IIO power monitor rails on the system.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
iio_root: Root directory for IIO devices (default: /sys/bus/iio/devices)
|
|
141
|
+
chip_ids: Set of supported chip IDs (default: SUPPORTED_POWER_CHIPS)
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
List of all discovered PowerRail objects, sorted by device name
|
|
145
|
+
"""
|
|
146
|
+
if not iio_root.exists():
|
|
147
|
+
return []
|
|
148
|
+
|
|
149
|
+
rails: list[PowerRail] = []
|
|
150
|
+
for device_dir in sorted(iio_root.glob("iio:device*")):
|
|
151
|
+
rails.extend(_discover_chip_rails(device_dir, chip_ids))
|
|
152
|
+
|
|
153
|
+
return rails
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class PowerRails:
|
|
157
|
+
"""Manages discovery and reading of IIO power monitor rails.
|
|
158
|
+
|
|
159
|
+
This class discovers available power monitor chips at initialization and
|
|
160
|
+
provides methods to read energy accumulator values from the discovered rails.
|
|
161
|
+
|
|
162
|
+
Attributes:
|
|
163
|
+
rails: List of discovered PowerRail objects
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
def __init__(self, iio_root: Path = IIO_DEVICES_ROOT):
|
|
167
|
+
"""Initialize and discover power rails.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
iio_root: Root directory for IIO devices (allows testing with mock paths)
|
|
171
|
+
"""
|
|
172
|
+
self.iio_root = iio_root
|
|
173
|
+
self.rails = discover_rails(iio_root)
|
|
174
|
+
|
|
175
|
+
def get_rails(self) -> list[PowerRail]:
|
|
176
|
+
"""Get the list of discovered power rails.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
List of PowerRail objects
|
|
180
|
+
"""
|
|
181
|
+
return self.rails
|
|
182
|
+
|
|
183
|
+
def read_rail_energy(self, rail: PowerRail) -> float:
|
|
184
|
+
"""Read the current energy accumulator for a specific rail.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
rail: PowerRail object to read from
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
Raw energy accumulator value
|
|
191
|
+
|
|
192
|
+
Raises:
|
|
193
|
+
OSError: If the sysfs file cannot be read
|
|
194
|
+
"""
|
|
195
|
+
return rail.read_energy_raw()
|
|
@@ -20,7 +20,7 @@ from amd_debug.common import (
|
|
|
20
20
|
from amd_debug.validator import SleepValidator
|
|
21
21
|
from amd_debug.installer import Installer
|
|
22
22
|
from amd_debug.prerequisites import PrerequisiteValidator
|
|
23
|
-
from amd_debug.sleep_report import SleepReport
|
|
23
|
+
from amd_debug.sleep_report import SleepReport, confirm_overwrite_report
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class Defaults:
|
|
@@ -62,7 +62,7 @@ def display_report_file(fname, fmt) -> None:
|
|
|
62
62
|
if user:
|
|
63
63
|
env_vars = []
|
|
64
64
|
for var in ["DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "XDG_RUNTIME_DIR",
|
|
65
|
-
"DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_DATA_DIRS"]:
|
|
65
|
+
"DBUS_SESSION_BUS_ADDRESS", "XDG_SESSION_TYPE", "XDG_DATA_DIRS", "KDE_SESSION_VERSION"]:
|
|
66
66
|
value = os.environ.get(var)
|
|
67
67
|
if value:
|
|
68
68
|
env_vars.append(f"{var}={value}")
|
|
@@ -179,6 +179,9 @@ def report(since, until, fname, fmt, tool_debug, report_debug) -> bool:
|
|
|
179
179
|
)
|
|
180
180
|
except KeyboardInterrupt:
|
|
181
181
|
sys.exit("\nReport generation cancelled")
|
|
182
|
+
if not confirm_overwrite_report(fname):
|
|
183
|
+
print("Report generation cancelled")
|
|
184
|
+
return False
|
|
182
185
|
try:
|
|
183
186
|
app = SleepReport(
|
|
184
187
|
since=since,
|
|
@@ -226,6 +229,9 @@ def run_test_cycle(
|
|
|
226
229
|
except KeyboardInterrupt:
|
|
227
230
|
sys.exit("\nTest cancelled")
|
|
228
231
|
|
|
232
|
+
if not confirm_overwrite_report(fname):
|
|
233
|
+
sys.exit("Test cancelled")
|
|
234
|
+
|
|
229
235
|
try:
|
|
230
236
|
app = PrerequisiteValidator(debug)
|
|
231
237
|
run = app.run()
|