-
Notifications
You must be signed in to change notification settings - Fork 80
Feat:Add power, temps and Split physical CPUS #2407
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f5d204e
Add power placeholder and Split physical CPUS
SimonFair e64211b
Add icon to total power.
SimonFair e4ed589
Fix placeholder index
SimonFair 2f66cd3
Changes for power and temp.
SimonFair b58021c
Merge remote-tracking branch 'upstream/master' into CPU-Packages
SimonFair e799c91
Layout change and fixes
SimonFair 5083f85
Remove test code
SimonFair 117a494
Update DashStats.page
SimonFair 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
| function get_cpu_packages(string $separator = ','): array { | ||
| $packages = []; | ||
|
|
||
| foreach (glob("/sys/devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list") as $path) { | ||
| $pkg_id = (int)file_get_contents(dirname($path) . "/physical_package_id"); | ||
| $siblings = str_replace(",", $separator, trim(file_get_contents($path))); | ||
|
|
||
| if (!in_array($siblings, $packages[$pkg_id] ?? [])) { | ||
| $packages[$pkg_id][] = $siblings; | ||
| } | ||
| } | ||
|
|
||
| // Sort groups within each package by first CPU number | ||
| foreach ($packages as &$list) { | ||
| $keys = array_map(fn($s) => (int)explode($separator, $s)[0], $list); | ||
| array_multisort($keys, SORT_ASC, SORT_NUMERIC, $list); | ||
| } | ||
| unset($list); | ||
|
|
||
| return $packages; | ||
| } |
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.
Fix translation markers, variable declaration, and temperature conversion logic.
Several issues in
updateCPUPower():_(Total)_and_(Power)_inside the JavaScript template literal will not be processed by PHP—they'll appear as literal text. You need to pre-translate these server-side or use a different approach for localization.tempdisplayis assigned withoutlet,const, orvar, creating an unintended global variable.temp.toFixed(0)returns a string; while JavaScript coerces it to a number in arithmetic, it's cleaner to convert the raw number:temp * 9 / 5 + 32, then round once.tempunit;;) and inconsistent indentation.Apply this diff:
const totalEl = document.getElementById('cpu-total-power'); const totalPower = cpupower.totalPower ?? 0; if (totalEl) { - totalEl.innerHTML = `<i class="fa fa-fw fa-plug"></i> _(Total)_ _(Power)_: ${totalPower.toFixed(2)} W`; + totalEl.innerHTML = `<i class="fa fa-fw fa-plug"></i> <?=_('Total')?> <?=_('Power')?>: ${totalPower.toFixed(2)} W`; } ... const cpustemps = cpupower.temp ?? []; cpustemps.forEach((temp, index) => { const coreTempEl = document.getElementById(`cpu-temp${index}`); - if (coreTempEl) { - tempdisplay = temp.toFixed(0); - if (tempunit === "F") { - tempdisplay = ((temp.toFixed(0))* 9 / 5) + 32; - } - coreTempEl.innerHTML = Math.round(tempdisplay)+` °`+tempunit;; + if (coreTempEl) { + let tempdisplay = temp; + if (tempunit === "F") { + tempdisplay = (temp * 9 / 5) + 32; + } + coreTempEl.innerHTML = Math.round(tempdisplay) + ` °` + tempunit; } });