amd-debug-tools 0.2.0__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.

Potentially problematic release.


This version of amd-debug-tools might be problematic. Click here for more details.

Files changed (47) hide show
  1. amd_debug_tools-0.2.0/LICENSE +19 -0
  2. amd_debug_tools-0.2.0/PKG-INFO +180 -0
  3. amd_debug_tools-0.2.0/README.md +156 -0
  4. amd_debug_tools-0.2.0/pyproject.toml +34 -0
  5. amd_debug_tools-0.2.0/setup.cfg +23 -0
  6. amd_debug_tools-0.2.0/src/amd_debug/__init__.py +45 -0
  7. amd_debug_tools-0.2.0/src/amd_debug/acpi.py +107 -0
  8. amd_debug_tools-0.2.0/src/amd_debug/bash/amd-s2idle +89 -0
  9. amd_debug_tools-0.2.0/src/amd_debug/battery.py +87 -0
  10. amd_debug_tools-0.2.0/src/amd_debug/bios.py +138 -0
  11. amd_debug_tools-0.2.0/src/amd_debug/common.py +324 -0
  12. amd_debug_tools-0.2.0/src/amd_debug/database.py +331 -0
  13. amd_debug_tools-0.2.0/src/amd_debug/failures.py +588 -0
  14. amd_debug_tools-0.2.0/src/amd_debug/installer.py +404 -0
  15. amd_debug_tools-0.2.0/src/amd_debug/kernel.py +389 -0
  16. amd_debug_tools-0.2.0/src/amd_debug/prerequisites.py +1215 -0
  17. amd_debug_tools-0.2.0/src/amd_debug/pstate.py +314 -0
  18. amd_debug_tools-0.2.0/src/amd_debug/s2idle-hook +72 -0
  19. amd_debug_tools-0.2.0/src/amd_debug/s2idle.py +406 -0
  20. amd_debug_tools-0.2.0/src/amd_debug/sleep_report.py +453 -0
  21. amd_debug_tools-0.2.0/src/amd_debug/templates/html +427 -0
  22. amd_debug_tools-0.2.0/src/amd_debug/templates/md +39 -0
  23. amd_debug_tools-0.2.0/src/amd_debug/templates/stdout +13 -0
  24. amd_debug_tools-0.2.0/src/amd_debug/templates/txt +23 -0
  25. amd_debug_tools-0.2.0/src/amd_debug/validator.py +863 -0
  26. amd_debug_tools-0.2.0/src/amd_debug/wake.py +111 -0
  27. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/PKG-INFO +180 -0
  28. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/SOURCES.txt +46 -0
  29. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/dependency_links.txt +1 -0
  30. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/entry_points.txt +4 -0
  31. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/requires.txt +10 -0
  32. amd_debug_tools-0.2.0/src/amd_debug_tools.egg-info/top_level.txt +1 -0
  33. amd_debug_tools-0.2.0/test/test_acpi.py +94 -0
  34. amd_debug_tools-0.2.0/test/test_batteries.py +95 -0
  35. amd_debug_tools-0.2.0/test/test_bios.py +254 -0
  36. amd_debug_tools-0.2.0/test/test_common.py +276 -0
  37. amd_debug_tools-0.2.0/test/test_database.py +290 -0
  38. amd_debug_tools-0.2.0/test/test_failures.py +149 -0
  39. amd_debug_tools-0.2.0/test/test_installer.py +185 -0
  40. amd_debug_tools-0.2.0/test/test_kernel.py +209 -0
  41. amd_debug_tools-0.2.0/test/test_launcher.py +96 -0
  42. amd_debug_tools-0.2.0/test/test_prerequisites.py +1726 -0
  43. amd_debug_tools-0.2.0/test/test_pstate.py +169 -0
  44. amd_debug_tools-0.2.0/test/test_s2idle.py +836 -0
  45. amd_debug_tools-0.2.0/test/test_sleep_report.py +171 -0
  46. amd_debug_tools-0.2.0/test/test_validator.py +729 -0
  47. amd_debug_tools-0.2.0/test/test_wake.py +220 -0
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 Advanced Micro Devices
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: amd-debug-tools
3
+ Version: 0.2.0
4
+ Summary: debug tools for AMD systems
5
+ Author-email: Mario Limonciello <superm1@kernel.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://web.git.kernel.org/pub/scm/linux/kernel/git/superm1/amd-debug-tools.git/
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Requires-Python: >=3.7
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pyudev
14
+ Requires-Dist: packaging
15
+ Requires-Dist: pandas
16
+ Requires-Dist: jinja2
17
+ Requires-Dist: tabulate
18
+ Requires-Dist: seaborn
19
+ Requires-Dist: cysystemd
20
+ Requires-Dist: Jinja2
21
+ Requires-Dist: matplotlib
22
+ Requires-Dist: seaborn
23
+ Dynamic: license-file
24
+
25
+ # Helpful tools for debugging AMD Zen systems
26
+ [![codecov](https://codecov.io/github/superm1/amd-debug-tools/graph/badge.svg?token=Z9WTBZADGT)](https://codecov.io/github/superm1/amd-debug-tools)
27
+ [![PyPI](https://img.shields.io/pypi/v/amd-debug-tools.svg)](https://pypi.org/project/amd-debug-tools/)
28
+
29
+ This repository hosts open tools that are useful for debugging issues on AMD systems.
30
+
31
+ ## Installation
32
+ It is suggested to install tools in a virtual environment either using
33
+ `pipx` or `python3 -m venv`.
34
+
35
+ ### From PyPI
36
+ `amd-debug-tools` is distributed as a python wheel, which is a
37
+ binary package format for Python. To install from PyPI, run the following
38
+ command:
39
+
40
+ pipx install amd-debug-tools
41
+
42
+ ### From source
43
+ To build the package from source, you will need to the `python3-build`
44
+ package natively installed by your distribution package manager. Then you
45
+ can generate and install a wheel by running the following commands:
46
+
47
+ python3 -m build
48
+ pipx install dist/amd-debug-tools-*.whl
49
+
50
+ ### Ensuring path
51
+ If you have not used a `pipx` environment before, you may need to run the following command
52
+ to set up the environment:
53
+
54
+ pipx ensurepath
55
+
56
+ This will add the `pipx` environment to your path.
57
+
58
+ ### Running in tree
59
+ If you want to run the tools in tree, you need to make sure that distro dependencies
60
+ that would normally install into a venv are installed. This can be done by running:
61
+
62
+ ./install_deps.py
63
+
64
+ After dependencies are installed, you can run the tools by running:
65
+
66
+ ./amd_s2idle.py
67
+ ./amd_bios.py
68
+ ./amd_pstate.py
69
+
70
+ ## amd-s2idle
71
+ `amd-s2idle` is a tool used for analyzing the entry and exit of the s2idle
72
+ state of a Linux system.
73
+
74
+ It is intended to use with Linux kernel 6.1 or later and works by hooking
75
+ into dynamic debugging messages and events that are generated by the kernel.
76
+
77
+ For analysis of power consumption issues it can be hooked into `systemd` to
78
+ run a command to capture data right before and after the system enters and
79
+ exits the s2idle state.
80
+
81
+ 4 high level commands are supported.
82
+
83
+ ### `amd-s2idle install`
84
+ This will install the systemd hook so that data will be captured before and
85
+ after the system enters and exits the s2idle state.
86
+
87
+ This will also install a bash completion script that can be used for other
88
+ commands.
89
+
90
+ **NOTE:** This command is only supported when run from a venv.
91
+
92
+ ### `amd-s2idle uninstall`
93
+ This will uninstall the systemd hook and remove the bash completion script.
94
+
95
+ **NOTE:** This command is only supported when run from a venv.
96
+
97
+ ### `amd-s2idle test`
98
+ This will run a suspend cycle with a timer based wakeup and capture relevant
99
+ data into a database and produce a report. This can also be used to run multiple cycles.
100
+
101
+ The following optional arguments are supported for this command:
102
+
103
+ --count COUNT Number of cycles to run
104
+ --duration DURATION Duration of the cycle in seconds
105
+ --wait WAIT Time to wait before starting the cycle in seconds
106
+ --format FORMAT Format of the report to produce (html, txt or md)
107
+ --report-file File to write the report to
108
+ --force Run a test cycle even if the system fails to pass prerequisite checks
109
+ --random Run sleep cycles for random durations and waits, using the --duration and --wait arguments as an upper bound
110
+ --logind Use logind to suspend the system
111
+ --tool-debug Enable debug logging
112
+ --bios-debug Enable BIOS debug logging instead of notify logging
113
+
114
+ If the tool is launched with an environment that can call `xdg-open`, the report
115
+ will be opened in a browser.
116
+
117
+ ### `amd-s2idle report`
118
+ This will produce a report from the data captured by the `test` command
119
+ and/or from the systemd hook. The report will default to 60 days of data.
120
+
121
+ The following optional arguments are supported for this command:
122
+
123
+ --since SINCE Date to start the report from
124
+ --until UNTIL Date to end the report at
125
+ --format FORMAT Format of the report to produce (html, txt or md)
126
+ --report-file File to write the report to
127
+ --tool-debug Enable tool debug logging
128
+ --report-debug Include debug messages in the report
129
+
130
+ If the tool is launched with an environment that can call `xdg-open`, the report
131
+ will be opened in a browser.
132
+
133
+ ### `amd-s2idle version`
134
+ This will print the version of the tool and exit.
135
+
136
+ ### Debug output
137
+ All commands support the `--tool-debug` argument which will enable extra debug output. This is often needed for debugging issues with a particular cycle.
138
+
139
+ **NOTE:** enabling debug output significantly increases the size of the report.
140
+ It's suggested that you use `--since` and `--until` to focus on the cycles that you are interested in.
141
+
142
+ ## amd-bios
143
+ `amd-bios` is a a tool that can be used to enable or disable BIOS AML debug logging
144
+ -and to parse a kernel log that contains BIOS logs.
145
+
146
+ ### `amd-bios trace`
147
+ Modify BIOS AML trace debug logging.
148
+
149
+ One of the following arguments must be set for this command:
150
+
151
+ --enable Enable BIOS AML tracing
152
+ --disable Disable BIOS AML tracing
153
+
154
+ The following optional arguments are supported for this command:
155
+
156
+ --tool-debug Enable tool debug logging
157
+
158
+ ### `amd-bios parse`
159
+ Parses a kernel log that contains BIOS AML debug logging and produces a report.
160
+
161
+ The following optional arguments are supported for this command:
162
+
163
+ --input INPUT Optional input file to parse
164
+ --tool-debug Enable tool debug logging
165
+
166
+ ### `amd-bios version`
167
+ This will print the version of the tool and exit.
168
+
169
+ ## amd-pstate
170
+ `amd-pstate` is a tool used for identification of issues with amd-pstate.
171
+ It will capture some state from the system as well as from the machine specific registers that
172
+ amd-pstate uses.
173
+
174
+ ## Compatibility scripts
175
+
176
+ Compatibility scripts are provided for the previous names the tools went by:
177
+ `amd_s2idle.py`, `amd_bios.py` and `amd_pstate.py`.
178
+ These allow cloning the repository and running the scripts without installing
179
+ the package.
180
+
@@ -0,0 +1,156 @@
1
+ # Helpful tools for debugging AMD Zen systems
2
+ [![codecov](https://codecov.io/github/superm1/amd-debug-tools/graph/badge.svg?token=Z9WTBZADGT)](https://codecov.io/github/superm1/amd-debug-tools)
3
+ [![PyPI](https://img.shields.io/pypi/v/amd-debug-tools.svg)](https://pypi.org/project/amd-debug-tools/)
4
+
5
+ This repository hosts open tools that are useful for debugging issues on AMD systems.
6
+
7
+ ## Installation
8
+ It is suggested to install tools in a virtual environment either using
9
+ `pipx` or `python3 -m venv`.
10
+
11
+ ### From PyPI
12
+ `amd-debug-tools` is distributed as a python wheel, which is a
13
+ binary package format for Python. To install from PyPI, run the following
14
+ command:
15
+
16
+ pipx install amd-debug-tools
17
+
18
+ ### From source
19
+ To build the package from source, you will need to the `python3-build`
20
+ package natively installed by your distribution package manager. Then you
21
+ can generate and install a wheel by running the following commands:
22
+
23
+ python3 -m build
24
+ pipx install dist/amd-debug-tools-*.whl
25
+
26
+ ### Ensuring path
27
+ If you have not used a `pipx` environment before, you may need to run the following command
28
+ to set up the environment:
29
+
30
+ pipx ensurepath
31
+
32
+ This will add the `pipx` environment to your path.
33
+
34
+ ### Running in tree
35
+ If you want to run the tools in tree, you need to make sure that distro dependencies
36
+ that would normally install into a venv are installed. This can be done by running:
37
+
38
+ ./install_deps.py
39
+
40
+ After dependencies are installed, you can run the tools by running:
41
+
42
+ ./amd_s2idle.py
43
+ ./amd_bios.py
44
+ ./amd_pstate.py
45
+
46
+ ## amd-s2idle
47
+ `amd-s2idle` is a tool used for analyzing the entry and exit of the s2idle
48
+ state of a Linux system.
49
+
50
+ It is intended to use with Linux kernel 6.1 or later and works by hooking
51
+ into dynamic debugging messages and events that are generated by the kernel.
52
+
53
+ For analysis of power consumption issues it can be hooked into `systemd` to
54
+ run a command to capture data right before and after the system enters and
55
+ exits the s2idle state.
56
+
57
+ 4 high level commands are supported.
58
+
59
+ ### `amd-s2idle install`
60
+ This will install the systemd hook so that data will be captured before and
61
+ after the system enters and exits the s2idle state.
62
+
63
+ This will also install a bash completion script that can be used for other
64
+ commands.
65
+
66
+ **NOTE:** This command is only supported when run from a venv.
67
+
68
+ ### `amd-s2idle uninstall`
69
+ This will uninstall the systemd hook and remove the bash completion script.
70
+
71
+ **NOTE:** This command is only supported when run from a venv.
72
+
73
+ ### `amd-s2idle test`
74
+ This will run a suspend cycle with a timer based wakeup and capture relevant
75
+ data into a database and produce a report. This can also be used to run multiple cycles.
76
+
77
+ The following optional arguments are supported for this command:
78
+
79
+ --count COUNT Number of cycles to run
80
+ --duration DURATION Duration of the cycle in seconds
81
+ --wait WAIT Time to wait before starting the cycle in seconds
82
+ --format FORMAT Format of the report to produce (html, txt or md)
83
+ --report-file File to write the report to
84
+ --force Run a test cycle even if the system fails to pass prerequisite checks
85
+ --random Run sleep cycles for random durations and waits, using the --duration and --wait arguments as an upper bound
86
+ --logind Use logind to suspend the system
87
+ --tool-debug Enable debug logging
88
+ --bios-debug Enable BIOS debug logging instead of notify logging
89
+
90
+ If the tool is launched with an environment that can call `xdg-open`, the report
91
+ will be opened in a browser.
92
+
93
+ ### `amd-s2idle report`
94
+ This will produce a report from the data captured by the `test` command
95
+ and/or from the systemd hook. The report will default to 60 days of data.
96
+
97
+ The following optional arguments are supported for this command:
98
+
99
+ --since SINCE Date to start the report from
100
+ --until UNTIL Date to end the report at
101
+ --format FORMAT Format of the report to produce (html, txt or md)
102
+ --report-file File to write the report to
103
+ --tool-debug Enable tool debug logging
104
+ --report-debug Include debug messages in the report
105
+
106
+ If the tool is launched with an environment that can call `xdg-open`, the report
107
+ will be opened in a browser.
108
+
109
+ ### `amd-s2idle version`
110
+ This will print the version of the tool and exit.
111
+
112
+ ### Debug output
113
+ All commands support the `--tool-debug` argument which will enable extra debug output. This is often needed for debugging issues with a particular cycle.
114
+
115
+ **NOTE:** enabling debug output significantly increases the size of the report.
116
+ It's suggested that you use `--since` and `--until` to focus on the cycles that you are interested in.
117
+
118
+ ## amd-bios
119
+ `amd-bios` is a a tool that can be used to enable or disable BIOS AML debug logging
120
+ -and to parse a kernel log that contains BIOS logs.
121
+
122
+ ### `amd-bios trace`
123
+ Modify BIOS AML trace debug logging.
124
+
125
+ One of the following arguments must be set for this command:
126
+
127
+ --enable Enable BIOS AML tracing
128
+ --disable Disable BIOS AML tracing
129
+
130
+ The following optional arguments are supported for this command:
131
+
132
+ --tool-debug Enable tool debug logging
133
+
134
+ ### `amd-bios parse`
135
+ Parses a kernel log that contains BIOS AML debug logging and produces a report.
136
+
137
+ The following optional arguments are supported for this command:
138
+
139
+ --input INPUT Optional input file to parse
140
+ --tool-debug Enable tool debug logging
141
+
142
+ ### `amd-bios version`
143
+ This will print the version of the tool and exit.
144
+
145
+ ## amd-pstate
146
+ `amd-pstate` is a tool used for identification of issues with amd-pstate.
147
+ It will capture some state from the system as well as from the machine specific registers that
148
+ amd-pstate uses.
149
+
150
+ ## Compatibility scripts
151
+
152
+ Compatibility scripts are provided for the previous names the tools went by:
153
+ `amd_s2idle.py`, `amd_bios.py` and `amd_pstate.py`.
154
+ These allow cloning the repository and running the scripts without installing
155
+ the package.
156
+
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=59.8.0", "setuptools-git-versioning>=2.0,<3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools-git-versioning]
6
+ enabled = true
7
+
8
+ [project]
9
+ name = "amd-debug-tools"
10
+ authors = [{ name = "Mario Limonciello", email = "superm1@kernel.org" }]
11
+ description = "debug tools for AMD systems"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: POSIX :: Linux",
17
+ ]
18
+ dependencies = [
19
+ "pyudev",
20
+ "packaging",
21
+ "pandas",
22
+ "jinja2",
23
+ "tabulate",
24
+ "seaborn",
25
+ "cysystemd",
26
+ "Jinja2",
27
+ "matplotlib",
28
+ "seaborn",
29
+ ]
30
+ dynamic = ["version", "scripts"]
31
+ license = "MIT"
32
+
33
+ [project.urls]
34
+ "Homepage" = "https://web.git.kernel.org/pub/scm/linux/kernel/git/superm1/amd-debug-tools.git/"
@@ -0,0 +1,23 @@
1
+ [options]
2
+ package_dir =
3
+ =src
4
+ packages = find_namespace:
5
+
6
+ [options.packages.find]
7
+ where = src
8
+
9
+ [options.entry_points]
10
+ console_scripts =
11
+ amd-s2idle = amd_debug:amd_s2idle
12
+ amd-bios = amd_debug:amd_bios
13
+ amd-pstate = amd_debug:amd_pstate
14
+
15
+ [options.package_data]
16
+ amd_debug = s2idle-hook
17
+ amd_debug.templates = *
18
+ amd_debug.bash = amd-s2idle
19
+
20
+ [egg_info]
21
+ tag_build =
22
+ tag_date = 0
23
+
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/python3
2
+ # SPDX-License-Identifier: MIT
3
+
4
+
5
+ def amd_s2idle():
6
+ """Launch the amd-s2idle tool."""
7
+ from . import s2idle # pylint: disable=import-outside-toplevel
8
+
9
+ return s2idle.main()
10
+
11
+
12
+ def amd_bios():
13
+ """Launch the amd-bios tool."""
14
+ from . import bios # pylint: disable=import-outside-toplevel
15
+
16
+ return bios.main()
17
+
18
+
19
+ def amd_pstate():
20
+ """Launch the amd-pstate tool."""
21
+ from . import pstate # pylint: disable=import-outside-toplevel
22
+
23
+ return pstate.main()
24
+
25
+
26
+ def install_dep_superset():
27
+ """Install all supserset dependencies."""
28
+ from . import installer # pylint: disable=import-outside-toplevel
29
+
30
+ return installer.install_dep_superset()
31
+
32
+
33
+ def launch_tool(tool_name):
34
+ """Launch a tool with the given name and arguments."""
35
+ tools = {
36
+ "amd_s2idle.py": amd_s2idle,
37
+ "amd_bios.py": amd_bios,
38
+ "amd_pstate.py": amd_pstate,
39
+ "install_deps.py": install_dep_superset,
40
+ }
41
+ if tool_name in tools:
42
+ return tools[tool_name]()
43
+ else:
44
+ print(f"\033[91mUnknown exe: {tool_name}\033[0m")
45
+ return False
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/python3
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ import os
5
+ import logging
6
+ from amd_debug.common import BIT, read_file
7
+
8
+ ACPI_METHOD = "M460"
9
+
10
+
11
+ def search_acpi_tables(pattern):
12
+ """Search for a pattern in ACPI tables"""
13
+ p = os.path.join("/", "sys", "firmware", "acpi", "tables")
14
+
15
+ for fn in os.listdir(p):
16
+ if not fn.startswith("SSDT") and not fn.startswith("DSDT"):
17
+ continue
18
+ fp = os.path.join(p, fn)
19
+ with open(fp, "rb") as file:
20
+ content = file.read()
21
+ if pattern.encode() in content:
22
+ return True
23
+ return False
24
+
25
+
26
+ class AcpicaTracer:
27
+ """Class for ACPI tracing"""
28
+
29
+ def __init__(self):
30
+ self.acpi_base = os.path.join("/", "sys", "module", "acpi", "parameters")
31
+ keys = [
32
+ "trace_debug_layer",
33
+ "trace_debug_level",
34
+ "trace_method_name",
35
+ "trace_state",
36
+ ]
37
+ self.original = {}
38
+ self.supported = False
39
+ for key in keys:
40
+ fname = os.path.join(self.acpi_base, key)
41
+ if not os.path.exists(fname):
42
+ logging.debug("ACPI Notify() debugging not available")
43
+ return
44
+ v = read_file(fname)
45
+ if v and v != "(null)":
46
+ self.original[key] = v
47
+ self.supported = True
48
+
49
+ def _write_expected(self, expected):
50
+ for key, value in expected.items():
51
+ p = os.path.join(self.acpi_base, key)
52
+ if isinstance(value, int):
53
+ t = str(int(value))
54
+ else:
55
+ t = value
56
+ with open(p, "w", encoding="utf-8") as w:
57
+ w.write(t)
58
+
59
+ def trace_notify(self):
60
+ """Trace notify events"""
61
+ if not self.supported:
62
+ return False
63
+ expected = {
64
+ "trace_debug_layer": BIT(2),
65
+ "trace_debug_level": BIT(2),
66
+ "trace_state": "enable",
67
+ }
68
+ self._write_expected(expected)
69
+ logging.debug("Enabled ACPI debugging for ACPI_LV_INFO/ACPI_EVENTS")
70
+ return True
71
+
72
+ def trace_bios(self):
73
+ """Trace BIOS events"""
74
+ if not self.supported:
75
+ return False
76
+ if not search_acpi_tables(ACPI_METHOD):
77
+ logging.debug(
78
+ "will not work on this system: ACPI tables do not contain %s",
79
+ ACPI_METHOD,
80
+ )
81
+ return False
82
+ expected = {
83
+ "trace_debug_layer": BIT(7),
84
+ "trace_debug_level": BIT(4),
85
+ "trace_method_name": f"\\{ACPI_METHOD}",
86
+ "trace_state": "method",
87
+ }
88
+ self._write_expected(expected)
89
+ logging.debug("Enabled ACPI debugging for BIOS")
90
+ return True
91
+
92
+ def disable(self):
93
+ """Disable ACPI tracing"""
94
+ if not self.supported:
95
+ return False
96
+ expected = {
97
+ "trace_state": "disable",
98
+ }
99
+ self._write_expected(expected)
100
+ return True
101
+
102
+ def restore(self):
103
+ """Restore original ACPI tracing settings"""
104
+ if not self.supported:
105
+ return False
106
+ self._write_expected(self.original)
107
+ return True
@@ -0,0 +1,89 @@
1
+ _cmd_list=(
2
+ 'install'
3
+ 'uninstall'
4
+ 'test'
5
+ 'report'
6
+ 'version'
7
+ )
8
+
9
+ _general_opts=(
10
+ )
11
+
12
+ _report_opts=(
13
+ '--since'
14
+ '--until'
15
+ '--report-file'
16
+ '--format'
17
+ '--report-debug'
18
+ )
19
+
20
+ _test_opts=(
21
+ '--wait'
22
+ '--count'
23
+ '--duration'
24
+ '--report-file'
25
+ '--format'
26
+ '--force'
27
+ '--logind'
28
+ '--tool-debug'
29
+ '--report-debug'
30
+ )
31
+
32
+ _format_opts=(
33
+ 'md'
34
+ 'html'
35
+ 'txt'
36
+ )
37
+
38
+ _show_test_opts()
39
+ {
40
+ COMPREPLY+=( $(compgen -W '${_test_opts[@]}' -- "$cur") )
41
+ }
42
+
43
+ _show_report_opts()
44
+ {
45
+ COMPREPLY+=( $(compgen -W '${_report_opts[@]}' -- "$cur") )
46
+ }
47
+
48
+ _show_format_completion()
49
+ {
50
+ COMPREPLY+=( $(compgen -W '${_format_opts[@]}' -- "$cur") )
51
+ }
52
+
53
+ _amd_s2idle()
54
+ {
55
+ local cur prev command arg args
56
+ COMPREPLY=()
57
+ _get_comp_words_by_ref cur prev
58
+ _get_first_arg
59
+ _count_args
60
+
61
+ case $prev in
62
+ --log|--duration|--count|--wait|--since|--report-file)
63
+ return 0
64
+ ;;
65
+ --format)
66
+ _show_format_completion
67
+ return 0
68
+ ;;
69
+ esac
70
+ case $arg in
71
+ test)
72
+ _show_test_opts
73
+ ;;
74
+ report)
75
+ _show_report_opts
76
+ ;;
77
+
78
+ *)
79
+ #find first command
80
+ if [[ "$args" = "1" ]]; then
81
+ COMPREPLY=( $(compgen -W '${_cmd_list[@]}' -- "$cur") )
82
+ fi
83
+ ;;
84
+ esac
85
+
86
+ return 0
87
+ }
88
+
89
+ complete -F _amd_s2idle amd-s2idle