Skip to content

Commit 7a6fb89

Browse files
committed
fix nits, cache totalcount, return proper filtered count
1 parent b1092d3 commit 7a6fb89

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

pkg/util/procinfo/procinfo_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func GetProcInfo(ctx context.Context, _ any, pid int32) (*ProcInfo, error) {
9090
info.CpuUser = -1
9191
info.CpuSys = -1
9292
info.VmRSS = -1
93+
info.NumThreads = -1
9394
if ti, terr := getDarwinProcTaskInfo(pid); terr == nil {
9495
if darwinTimeScale > 0 {
9596
info.CpuUser = float64(ti.TotalUser) * darwinTimeScale / 1e9

pkg/util/procinfo/procinfo_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func readStat(pid int32) (*ProcInfo, error) {
118118
if numThreads, err := strconv.ParseInt(rest[17], 10, 32); err == nil {
119119
info.NumThreads = int32(numThreads)
120120
}
121-
if rssPages, err := strconv.ParseInt(rest[21], 10, 64); err == nil && rssPages > 0 {
121+
if rssPages, err := strconv.ParseInt(rest[21], 10, 64); err == nil {
122122
info.VmRSS = rssPages * pageSize
123123
}
124124

pkg/wshrpc/wshremote/processviewer.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type cpuSample struct {
4040
// widgetPidOrder stores the ordered pid list from the last non-LastPidOrder request for a widget.
4141
type widgetPidOrder struct {
4242
pids []int32
43+
totalCount int
4344
lastRequest time.Time
4445
}
4546

@@ -116,7 +117,7 @@ func (s *procCacheState) touchWidgetPidOrder(widgetId string) {
116117
}
117118
}
118119

119-
func (s *procCacheState) storeWidgetPidOrder(widgetId string, pids []int32) {
120+
func (s *procCacheState) storeWidgetPidOrder(widgetId string, pids []int32, totalCount int) {
120121
if widgetId == "" {
121122
return
122123
}
@@ -127,28 +128,29 @@ func (s *procCacheState) storeWidgetPidOrder(widgetId string, pids []int32) {
127128
}
128129
s.widgetPidOrders[widgetId] = &widgetPidOrder{
129130
pids: pids,
131+
totalCount: totalCount,
130132
lastRequest: time.Now(),
131133
}
132134
}
133135

134-
func (s *procCacheState) getWidgetPidOrder(widgetId string) []int32 {
136+
func (s *procCacheState) getWidgetPidOrder(widgetId string) ([]int32, int) {
135137
if widgetId == "" {
136-
return nil
138+
return nil, 0
137139
}
138140
s.lock.Lock()
139141
defer s.lock.Unlock()
140142
if s.widgetPidOrders == nil {
141-
return nil
143+
return nil, 0
142144
}
143145
entry, ok := s.widgetPidOrders[widgetId]
144146
if !ok {
145-
return nil
147+
return nil, 0
146148
}
147149
if time.Since(entry.lastRequest) >= ProcCacheIdleTimeout {
148150
delete(s.widgetPidOrders, widgetId)
149-
return nil
151+
return nil, 0
150152
}
151-
return entry.pids
153+
return entry.pids, entry.totalCount
152154
}
153155

154156
func (s *procCacheState) runLoop(firstReadyCh chan struct{}) {
@@ -505,7 +507,12 @@ func (impl *ServerImpl) RemoteProcessListCommand(ctx context.Context, data wshrp
505507
var pidOrder []int32
506508
var filteredCount int
507509
if data.LastPidOrder {
508-
pidOrder = procCache.getWidgetPidOrder(data.WidgetId)
510+
var cachedTotal int
511+
pidOrder, cachedTotal = procCache.getWidgetPidOrder(data.WidgetId)
512+
if pidOrder != nil {
513+
filteredCount = len(pidOrder)
514+
totalCount = cachedTotal
515+
}
509516
}
510517
if pidOrder == nil {
511518
sortBy := data.SortBy
@@ -524,7 +531,7 @@ func (impl *ServerImpl) RemoteProcessListCommand(ctx context.Context, data wshrp
524531
pidOrder[i] = p.Pid
525532
}
526533
if data.WidgetId != "" {
527-
procCache.storeWidgetPidOrder(data.WidgetId, pidOrder)
534+
procCache.storeWidgetPidOrder(data.WidgetId, pidOrder, totalCount)
528535
}
529536
}
530537

0 commit comments

Comments
 (0)