fix(sysinfo): remove CPU context

BREAKING CHANGE: this property isn't used in any of the themes and it's
incorrect as fetching CPU information requires a timer which we don't
want to use as it will make rendering the prompt slower

For users who migrate to this version, remove the .CPU property from
the sysinfo segment's template in case you have that set.

resolves #3730
This commit is contained in:
Jan De Dobbeleer 2023-04-24 08:13:51 +02:00 committed by Jan De Dobbeleer
parent ac403236a4
commit 077e538500
3 changed files with 0 additions and 22 deletions

View file

@ -24,7 +24,6 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform/cmd"
"github.com/jandedobbeleer/oh-my-posh/src/regex"
cpu "github.com/shirou/gopsutil/v3/cpu"
disk "github.com/shirou/gopsutil/v3/disk"
load "github.com/shirou/gopsutil/v3/load"
process "github.com/shirou/gopsutil/v3/process"
@ -157,9 +156,6 @@ type Memory struct {
type SystemInfo struct {
// mem
Memory
// cpu
Times float64
CPU []cpu.InfoStat
// load
Load1 float64
Load5 float64
@ -923,16 +919,6 @@ func (env *Shell) SystemInfo() (*SystemInfo, error) {
s.Load15 = loadStat.Load15
}
processorTimes, err := cpu.Percent(0, false)
if err == nil && len(processorTimes) > 0 {
s.Times = processorTimes[0]
}
processors, err := cpu.Info()
if err == nil {
s.CPU = processors
}
diskIO, err := disk.IOCounters()
if err == nil {
s.Disks = diskIO

View file

@ -8,7 +8,6 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/stretchr/testify/assert"
)
@ -75,12 +74,6 @@ func TestSysInfo(t *testing.T) {
},
},
},
{
Case: "2 physical cpus",
ExpectedString: "1200 1200",
Template: "{{range $cpu := .CPU}}{{round $cpu.Mhz 2 }} {{end}}",
SysInfo: platform.SystemInfo{CPU: []cpu.InfoStat{{Mhz: 1200}, {Mhz: 1200}}},
},
}
for _, tc := range cases {

View file

@ -54,7 +54,6 @@ import Config from '@site/src/components/Config.js';
| `.Load1` | `float64` | is the current load1 (can be empty on windows) |
| `.Load5` | `float64` | is the current load5 (can be empty on windows) |
| `.Load15` | `float64` | is the current load15 (can be empty on windows) |
| `.CPU` | `[]struct` | an array of [InfoStat][cpuinfo] object, you can use any property it has e.g. `(index .CPU 0).Cores` |
| `.Disks` | `[]struct` | an array of [IOCountersStat][ioinfo] object, you can use any property it has e.g. `.Disks.disk0.IoTime` |
[cpuinfo]: https://github.com/shirou/gopsutil/blob/78065a7ce2021f6a78c8d6f586a2683ba501dcec/cpu/cpu.go#L32