Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 180 additions & 20 deletions frontend/app/view/processviewer/processviewer.tsx

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions frontend/preview/previews/processviewer.preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import { useRpcOverride } from "../mock/use-rpc-override";
const PreviewNodeId = "preview-processviewer-node";

const MockProcesses: ProcessInfo[] = [
{ pid: 1, ppid: 0, command: "launchd", user: "root", cpu: 0.0, mem: 4096 * 1024 },
{ pid: 123, ppid: 1, command: "kernel_task", user: "root", cpu: 12.3, mem: 2048 * 1024 * 1024 },
{ pid: 456, ppid: 1, command: "WindowServer", user: "_windowserver", cpu: 5.1, mem: 512 * 1024 * 1024 },
{ pid: 789, ppid: 1, command: "node", user: "mike", cpu: 8.7, mem: 256 * 1024 * 1024 },
{ pid: 1001, ppid: 1, command: "Electron", user: "mike", cpu: 3.2, mem: 400 * 1024 * 1024 },
{ pid: 1234, ppid: 1001, command: "waveterm-helper", user: "mike", cpu: 0.5, mem: 64 * 1024 * 1024 },
{ pid: 2001, ppid: 1, command: "sshd", user: "root", cpu: 0.0, mem: 8 * 1024 * 1024 },
{ pid: 2345, ppid: 1, command: "postgres", user: "postgres", cpu: 1.2, mem: 128 * 1024 * 1024 },
{ pid: 3001, ppid: 1, command: "nginx", user: "_www", cpu: 0.3, mem: 32 * 1024 * 1024 },
{ pid: 3456, ppid: 1, command: "python3", user: "mike", cpu: 2.8, mem: 96 * 1024 * 1024 },
{ pid: 4001, ppid: 1, command: "docker", user: "root", cpu: 0.1, mem: 48 * 1024 * 1024 },
{ pid: 4567, ppid: 4001, command: "containerd", user: "root", cpu: 0.2, mem: 80 * 1024 * 1024 },
{ pid: 5001, ppid: 1, command: "zsh", user: "mike", cpu: 0.0, mem: 6 * 1024 * 1024 },
{ pid: 5678, ppid: 5001, command: "vim", user: "mike", cpu: 0.0, mem: 20 * 1024 * 1024 },
{ pid: 6001, ppid: 1, command: "coreaudiod", user: "_coreaudiod", cpu: 0.4, mem: 16 * 1024 * 1024 },
{ pid: 1, ppid: 0, command: "launchd", user: "root", cpu: 0.0, mem: 4096 * 1024, mempct: 0.01 },
{ pid: 123, ppid: 1, command: "kernel_task", user: "root", cpu: 12.3, mem: 2048 * 1024 * 1024, mempct: 6.25 },
{ pid: 456, ppid: 1, command: "WindowServer", user: "_windowserver", cpu: 5.1, mem: 512 * 1024 * 1024, mempct: 1.56 },
{ pid: 789, ppid: 1, command: "node", user: "mike", cpu: 8.7, mem: 256 * 1024 * 1024, mempct: 0.78 },
{ pid: 1001, ppid: 1, command: "Electron", user: "mike", cpu: 3.2, mem: 400 * 1024 * 1024, mempct: 1.22 },
{ pid: 1234, ppid: 1001, command: "waveterm-helper", user: "mike", cpu: 0.5, mem: 64 * 1024 * 1024, mempct: 0.20 },
{ pid: 2001, ppid: 1, command: "sshd", user: "root", cpu: 0.0, mem: 8 * 1024 * 1024, mempct: 0.02 },
{ pid: 2345, ppid: 1, command: "postgres", user: "postgres", cpu: 1.2, mem: 128 * 1024 * 1024, mempct: 0.39 },
{ pid: 3001, ppid: 1, command: "nginx", user: "_www", cpu: 0.3, mem: 32 * 1024 * 1024, mempct: 0.10 },
{ pid: 3456, ppid: 1, command: "python3", user: "mike", cpu: 2.8, mem: 96 * 1024 * 1024, mempct: 0.29 },
{ pid: 4001, ppid: 1, command: "docker", user: "root", cpu: 0.1, mem: 48 * 1024 * 1024, mempct: 0.15 },
{ pid: 4567, ppid: 4001, command: "containerd", user: "root", cpu: 0.2, mem: 80 * 1024 * 1024, mempct: 0.24 },
{ pid: 5001, ppid: 1, command: "zsh", user: "mike", cpu: 0.0, mem: 6 * 1024 * 1024, mempct: 0.02 },
{ pid: 5678, ppid: 5001, command: "vim", user: "mike", cpu: 0.0, mem: 20 * 1024 * 1024, mempct: 0.06 },
{ pid: 6001, ppid: 1, command: "coreaudiod", user: "_coreaudiod", cpu: 0.4, mem: 16 * 1024 * 1024, mempct: 0.05 },
Comment on lines +13 to +27
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Populate numthreads in every mock ProcessInfo.

ProcessInfo now requires numthreads (frontend/types/gotypes.d.ts:1265-1277), so these literals no longer type-check. If the preview does not care about thread counts, use the new -1 sentinel consistently.

🧪 Minimal fix
-    { pid: 1, ppid: 0, command: "launchd", user: "root", cpu: 0.0, mem: 4096 * 1024, mempct: 0.01 },
+    { pid: 1, ppid: 0, command: "launchd", user: "root", cpu: 0.0, mem: 4096 * 1024, mempct: 0.01, numthreads: -1 },

Apply the same numthreads field to the remaining mock rows.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/preview/previews/processviewer.preview.tsx` around lines 13 - 27,
The mock ProcessInfo literals are missing the required numthreads field so they
fail type-checking; update every mocked row in the preview data (the array of
ProcessInfo objects) to include numthreads: -1 (use the -1 sentinel
consistently) so each object conforms to the ProcessInfo type; ensure every
object (e.g., entries with pid 1, 123, 456, etc.) gets the numthreads property
added.

];

const MockSummary: ProcessSummary = {
Expand Down
4 changes: 4 additions & 0 deletions frontend/tailwindsetup.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ svg [aria-label="tip"] g path {
color: var(--border-color);
}

.wide-scrollbar::-webkit-scrollbar {
width: 10px;
}

/* Monaco editor scrollbar styling */
.monaco-editor .slider {
background: rgba(255, 255, 255, 0.4);
Expand Down
13 changes: 8 additions & 5 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,14 @@ declare global {

// wshrpc.CommandRemoteProcessListData
type CommandRemoteProcessListData = {
widgetid?: string;
sortby?: string;
sortdesc?: boolean;
start?: number;
limit?: number;
textsearch?: string;
pids?: number[];
lastpidorder?: boolean;
keepalive?: boolean;
};

// wshrpc.CommandRemoteProcessSignalData
Expand Down Expand Up @@ -1267,10 +1269,11 @@ declare global {
command?: string;
status?: string;
user?: string;
mem?: number;
mempct?: number;
cpu?: number;
numthreads?: number;
mem: number;
mempct: number;
cpu: number;
numthreads: number;
gone?: boolean;
};

// wshrpc.ProcessListResponse
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/util/procinfo/procinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ var LinuxStatStatus = map[string]string{
// ProcInfo holds per-process information read from the OS.
// CpuUser and CpuSys are cumulative CPU seconds since process start;
// callers should diff two samples over a known interval to derive a rate.
// CpuUser, CpuSys, and VmRSS are set to -1 when the data is unavailable
// (e.g. permission denied reading another user's process).
type ProcInfo struct {
Pid int32
Ppid int32
Command string
Status string
CpuUser float64 // cumulative user CPU seconds
CpuSys float64 // cumulative system CPU seconds
VmRSS uint64 // resident set size in bytes
CpuUser float64 // cumulative user CPU seconds; -1 if unavailable
CpuSys float64 // cumulative system CPU seconds; -1 if unavailable
VmRSS int64 // resident set size in bytes; -1 if unavailable
Uid uint32
NumThreads int32
NumThreads int32 // -1 if unavailable
}
16 changes: 5 additions & 11 deletions pkg/util/procinfo/procinfo_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"unsafe"

"github.com/ebitengine/purego"
goproc "github.com/shirou/gopsutil/v4/process"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -88,22 +87,17 @@ func GetProcInfo(ctx context.Context, _ any, pid int32) (*ProcInfo, error) {
Uid: k.Eproc.Ucred.Uid,
}

info.CpuUser = -1
info.CpuSys = -1
info.VmRSS = -1
info.NumThreads = -1
if ti, terr := getDarwinProcTaskInfo(pid); terr == nil {
if darwinTimeScale > 0 {
info.CpuUser = float64(ti.TotalUser) * darwinTimeScale / 1e9
info.CpuSys = float64(ti.TotalSystem) * darwinTimeScale / 1e9
}
info.VmRSS = ti.ResidentSize
info.VmRSS = int64(ti.ResidentSize)
info.NumThreads = ti.Threadnum
} else {
if p, gerr := goproc.NewProcessWithContext(ctx, pid); gerr == nil {
if mi, merr := p.MemoryInfoWithContext(ctx); merr == nil {
info.VmRSS = mi.RSS
}
if nt, nerr := p.NumThreadsWithContext(ctx); nerr == nil {
info.NumThreads = nt
}
}
}

return info, nil
Expand Down
32 changes: 21 additions & 11 deletions pkg/util/procinfo/procinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ func readStat(pid int32) (*ProcInfo, error) {
return nil, fmt.Errorf("procinfo: parse pid: %w", err)
}

ppid, _ := strconv.ParseInt(rest[1], 10, 32)
utime, _ := strconv.ParseUint(rest[11], 10, 64)
stime, _ := strconv.ParseUint(rest[12], 10, 64)
numThreads, _ := strconv.ParseInt(rest[17], 10, 32)
rssPages, _ := strconv.ParseInt(rest[21], 10, 64)

statusChar := rest[0]
status, ok := LinuxStatStatus[statusChar]
if !ok {
Expand All @@ -104,14 +98,30 @@ func readStat(pid int32) (*ProcInfo, error) {

info := &ProcInfo{
Pid: int32(parsedPid),
Ppid: int32(ppid),
Command: comm,
Status: status,
CpuUser: float64(utime) / userHz,
CpuSys: float64(stime) / userHz,
VmRSS: uint64(rssPages * pageSize),
NumThreads: int32(numThreads),
CpuUser: -1,
CpuSys: -1,
VmRSS: -1,
NumThreads: -1,
}

if ppid, err := strconv.ParseInt(rest[1], 10, 32); err == nil {
info.Ppid = int32(ppid)
}
if utime, err := strconv.ParseUint(rest[11], 10, 64); err == nil {
info.CpuUser = float64(utime) / userHz
}
if stime, err := strconv.ParseUint(rest[12], 10, 64); err == nil {
info.CpuSys = float64(stime) / userHz
}
if numThreads, err := strconv.ParseInt(rest[17], 10, 32); err == nil {
info.NumThreads = int32(numThreads)
}
if rssPages, err := strconv.ParseInt(rest[21], 10, 64); err == nil {
info.VmRSS = rssPages * pageSize
}

return info, nil
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/procinfo/procinfo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func GetProcInfo(_ context.Context, snap any, pid int32) (*ProcInfo, error) {
Ppid: int32(si.ppid),
NumThreads: int32(si.numThreads),
Command: si.exeName,
CpuUser: -1,
CpuSys: -1,
VmRSS: -1,
}

handle, err := windows.OpenProcess(
Expand Down Expand Up @@ -127,7 +130,7 @@ func GetProcInfo(_ context.Context, snap any, pid int32) (*ProcInfo, error) {
uintptr(mc.CB),
)
if r != 0 {
info.VmRSS = uint64(mc.WorkingSetSize)
info.VmRSS = int64(mc.WorkingSetSize)
}

return info, nil
Expand Down
Loading
Loading