Skip to content

Commit

Permalink
Fix on NetBSD that doing /sinfo shows IndexOutOfRangeException for al…
Browse files Browse the repository at this point in the history
…l process CPU usage
  • Loading branch information
UnknownShadow200 committed Aug 7, 2022
1 parent 2541bad commit 23b3f97
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions MCGalaxy/Server/OperatingSystem.cs
Expand Up @@ -105,13 +105,15 @@ class UnixOS : IOperatingSystem
}

static CPUTime ParseCpuLine(string line) {
// cpu [USER TIME] [NICE TIME] [SYSTEM TIME] [IDLE TIME] [I/O WAIT TIME] [IRQ TIME] [SW IRQ TIME]
// Linux : cpu [USER TIME] [NICE TIME] [SYSTEM TIME] [IDLE TIME] [I/O WAIT TIME] [IRQ TIME] [SW IRQ TIME]
// NetBSD: cpu [USER TIME] [NICE TIME] [SYSTEM TIME] [IDLE TIME]
line = line.Replace(" ", " ");
string[] bits = line.SplitSpaces();

ulong user = ulong.Parse(bits[2]);
ulong nice = ulong.Parse(bits[3]);
ulong kern = ulong.Parse(bits[4]);
ulong idle = ulong.Parse(bits[5]);
ulong user = ulong.Parse(bits[1]);
ulong nice = ulong.Parse(bits[2]);
ulong kern = ulong.Parse(bits[3]);
ulong idle = ulong.Parse(bits[4]);
// TODO interrupt time too?

CPUTime all;
Expand Down

0 comments on commit 23b3f97

Please sign in to comment.