Skip to content

Commit

Permalink
Merge pull request #1 from joshlay/v0.1.22
Browse files Browse the repository at this point in the history
v0.1.22: Log fix, move to GitHub
  • Loading branch information
joshlay authored Mar 2, 2024
2 parents e2f0ace + 6babf63 commit 36eb7e5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Josh Lay
Copyright (c) 2024 Josh Lay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
# amdgpu_stats

A Python module/TUI for AMD GPU statistics.
Tested _only_ on `RX6000` series cards and _(less so)_ with Ryzen CPU iGPUs.

Please [file an issue](https://git.init3.us/BraveTraveler/amdgpu_stats/issues)
if finding incompatibility!
A Python module/TUI for AMD GPU statistics. Please [file an issue](https://github.com/joshlay/amdgpu_stats/issues)
with feature requests or bug reports!

## Screenshots

<details open>
<summary>Main screen / stats</summary>

![Screenshot of the main stats table](https://git.init3.us/BraveTraveler/amdgpu_stats/raw/branch/master/screens/main.svg "Main screen")
![Screenshot of the main stats table](https://raw.githubusercontent.com/joshlay/amdgpu_stats/master/screens/main.svg "Main screen")
</details>
<details>
<summary>Usage graphs</summary>

![Screenshot of the 'graphing' scroll bars](https://git.init3.us/BraveTraveler/amdgpu_stats/raw/branch/master/screens/graphs.svg "Graphs")
![Screenshot of the 'graphing' scroll bars](https://raw.githubusercontent.com/joshlay/amdgpu_stats/master/screens/graphs.svg "Graphs")
</details>
<details>
<summary>Logs</summary>

![Screenshot of the 'Logs' tab pane](https://git.init3.us/BraveTraveler/amdgpu_stats/raw/branch/master/screens/logs.svg "Logs")
![Screenshot of the 'Logs' tab pane](https://raw.githubusercontent.com/joshlay/amdgpu_stats/master/screens/logs.svg "Logs")
</details>

## Installation

```bash
pip install amdgpu-stats
```
To use the _TUI_, run `amdgpu-stats` in your terminal of choice. For the _module_, see below!

To use the _TUI_, run `amdgpu-stats` in your terminal of choice. For the _module_,
see below!

## Module

Introduction:

```python
In [1]: import amdgpu_stats.utils

Expand All @@ -47,17 +48,11 @@ Out[4]: '659 MHz'
```

For more information on what the module provides, please see:
- [ReadTheDocs](https://amdgpu-stats.readthedocs.io/en/latest/)
- `help('amdgpu_stats.utils')` in your interpreter
- [The module source](https://git.init3.us/BraveTraveler/amdgpu_stats/src/branch/master/src/amdgpu_stats/utils.py)

Feature requests [are encouraged](https://git.init3.us/BraveTraveler/amdgpu_stats/issues) 😀
- [ReadTheDocs](https://amdgpu-stats.readthedocs.io/en/latest/)
- `help('amdgpu_stats.utils')` in your interpreter
- [The module source](https://github.com/joshlay/amdgpu_stats/blob/master/src/amdgpu_stats/utils.py)

## Requirements
Only `Linux` is supported. Information is _completely_ sourced from interfaces in `sysfs`.

It _may_ be necessary to update the `amdgpu.ppfeaturemask` parameter to enable metrics.

This is assumed present for *control* over the elements being monitored. Untested without.

See [this Arch Wiki entry](https://wiki.archlinux.org/title/AMDGPU#Boot_parameter) for context.
Only `Linux` is supported. Information is _completely_ sourced from `sysfs`.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'amdgpu_stats'
copyright = '2023, Josh Lay'
copyright = '2024, Josh Lay'
author = 'Josh Lay'
release = '0.1.6'
release = '0.1.22'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tool.poetry]
name = "amdgpu-stats"
version = "0.1.21"
version = "0.1.22"
description = "A module/TUI for AMD GPU statistics"
authors = ["Josh Lay <[email protected]>"]
repository = "https://git.init3.us/BraveTraveler/amdgpu_stats"
repository = "https://github.com/joshlay/amdgpu_stats"
license = "MIT"
readme = "README.md"
documentation = "https://amdgpu-stats.readthedocs.io/en/latest/"
Expand Down
31 changes: 20 additions & 11 deletions src/amdgpu_stats/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ def compose(self) -> ComposeResult:
yield self.text_log

def update_log(self, message: str, show_ts: bool = True) -> None:
"""Update the Log widget with a new message.
Highest Textual version-requiring widget; >=0.32.0
Should be more performant than the old TextLog widget
"""Update the Log widget/pane with a new message.
Args:
message (str): The message to be added to the logging widget on the 'Logs' tab.
Expand Down Expand Up @@ -221,10 +218,12 @@ class app(App): # pylint: disable=invalid-name

# apply stylesheet; this is watched/dynamically reloaded
# can be edited (in installation dir) and seen live
# TODO: use xdg-config-dir, defaulting to the included style if not found
CSS_PATH = 'style.css'

# set the title - same as the class, but with spaces
TITLE = 'AMD GPU Stats'

# set a default subtitle, will change with the active tab
SUB_TITLE = f'cards: {list(AMDGPU_CARDS)}'

Expand All @@ -250,14 +249,28 @@ def compose(self) -> ComposeResult:
yield Container(self.stats_widget)
yield Footer()

def update_log(self, message: str, show_ts: bool = True) -> None:
"""Update the TextLog widget with a new message.
Highest Textual version-requiring widget; >=0.32.0
Should be more performant than the old TextLog widget
Args:
message (str): The message to be added to the logging widget on the 'Logs' tab.
show_ts (bool, optional): If True (default), appends a timestamp to the message.
"""
if show_ts:
message = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}"
self.stats_widget.text_log.write_line(message)

@work(exclusive=True)
async def action_custom_dark(self) -> None:
"""An action to toggle dark mode.
Wraps 'action_toggle_dark' with our logging"""
self.app.dark = not self.app.dark
# inline conditional due to how Textual doesn't pretty notifs. for us like TextLog
message = f"[bold]Dark side: [italic][{'green' if self.app.dark else 'red'}]{self.app.dark}"
# with new log widget... styling doesn't get rendered, disabling. makes notifications look nice
# message = f"[bold]Dark side: [italic][{'green' if self.app.dark else 'red'}]{self.app.dark}"
message = f"Dark side: {self.app.dark}"
self.notify(message)
self.update_log(message)

Expand All @@ -284,14 +297,10 @@ async def action_custom_screenshot(self, screen_dir: str = '/tmp') -> None:
# take the screenshot, recording the path for logging/notification
outpath = self.save_screenshot(path=screen_dir, filename=screen_name)
# construct the log/notification message, then show it
message = f"[bold]Path: [/]'[green]{outpath}[/]'"
message = f"Path: '{outpath}'"
self.notify(message, title='Screenshot captured', timeout=3.0)
self.update_log(message)

def update_log(self, message: str) -> None:
"""Update the TextLog widget with a new message."""
self.stats_widget.text_log.write(message)

def action_custom_tab(self) -> None:
"""Toggle between the 'Stats' and 'Logs' tabs"""
# walk/cycle the tabs
Expand Down

0 comments on commit 36eb7e5

Please sign in to comment.