@@ -5,6 +5,7 @@ package cpu
5
5
import (
6
6
"context"
7
7
"fmt"
8
+ "strings"
8
9
"unsafe"
9
10
10
11
"github.com/StackExchange/wmi"
18
19
)
19
20
20
21
type Win32_Processor struct {
21
- LoadPercentage * uint16
22
+ Win32_ProcessorWithoutLoadPct
23
+ LoadPercentage * uint16
24
+ }
25
+
26
+ // LoadPercentage takes a linearly more time as the number of sockets increases.
27
+ // For vSphere by default corespersocket = 1, meaning for a 40 vCPU VM Get Processor Info
28
+ // could take more than half a minute.
29
+ type Win32_ProcessorWithoutLoadPct struct {
22
30
Family uint16
23
31
Manufacturer string
24
32
Name string
@@ -104,8 +112,9 @@ func Info() ([]InfoStat, error) {
104
112
105
113
func InfoWithContext (ctx context.Context ) ([]InfoStat , error ) {
106
114
var ret []InfoStat
107
- var dst []Win32_Processor
115
+ var dst []Win32_ProcessorWithoutLoadPct
108
116
q := wmi .CreateQuery (& dst , "" )
117
+ q = strings .ReplaceAll (q , "Win32_ProcessorWithoutLoadPct" , "Win32_Processor" )
109
118
if err := common .WMIQueryWithContext (ctx , q , & dst ); err != nil {
110
119
return ret , err
111
120
}
@@ -242,8 +251,9 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
242
251
}
243
252
// physical cores https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L499
244
253
// for the time being, try with unreliable and slow WMI call…
245
- var dst []Win32_Processor
254
+ var dst []Win32_ProcessorWithoutLoadPct
246
255
q := wmi .CreateQuery (& dst , "" )
256
+ q = strings .ReplaceAll (q , "Win32_ProcessorWithoutLoadPct" , "Win32_Processor" )
247
257
if err := common .WMIQueryWithContext (ctx , q , & dst ); err != nil {
248
258
return 0 , err
249
259
}
0 commit comments