8133666: OperatingSystemMXBean reports abnormally high machine CPU consumption on Linux
Reviewed-by: sla, mgronlun
This commit is contained in:
parent
8b0d0cea27
commit
a9fb6ab847
@ -77,14 +77,17 @@ static void next_line(FILE *f) {
|
|||||||
static int get_totalticks(int which, ticks *pticks) {
|
static int get_totalticks(int which, ticks *pticks) {
|
||||||
FILE *fh;
|
FILE *fh;
|
||||||
uint64_t userTicks, niceTicks, systemTicks, idleTicks;
|
uint64_t userTicks, niceTicks, systemTicks, idleTicks;
|
||||||
|
uint64_t iowTicks = 0, irqTicks = 0, sirqTicks= 0;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if((fh = fopen("/proc/stat", "r")) == NULL) {
|
if((fh = fopen("/proc/stat", "r")) == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = fscanf(fh, "cpu " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64,
|
n = fscanf(fh, "cpu " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
|
||||||
&userTicks, &niceTicks, &systemTicks, &idleTicks);
|
DEC_64 " " DEC_64,
|
||||||
|
&userTicks, &niceTicks, &systemTicks, &idleTicks,
|
||||||
|
&iowTicks, &irqTicks, &sirqTicks);
|
||||||
|
|
||||||
// Move to next line
|
// Move to next line
|
||||||
next_line(fh);
|
next_line(fh);
|
||||||
@ -93,24 +96,30 @@ static int get_totalticks(int which, ticks *pticks) {
|
|||||||
if (which != -1) {
|
if (which != -1) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < which; i++) {
|
for (i = 0; i < which; i++) {
|
||||||
if (fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64, &userTicks, &niceTicks, &systemTicks, &idleTicks) != 4) {
|
if (fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
|
||||||
|
DEC_64 " " DEC_64 " " DEC_64,
|
||||||
|
&userTicks, &niceTicks, &systemTicks, &idleTicks,
|
||||||
|
&iowTicks, &irqTicks, &sirqTicks) < 4) {
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
next_line(fh);
|
next_line(fh);
|
||||||
}
|
}
|
||||||
n = fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 "\n",
|
n = fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64 " "
|
||||||
&userTicks, &niceTicks, &systemTicks, &idleTicks);
|
DEC_64 " " DEC_64 " " DEC_64 "\n",
|
||||||
|
&userTicks, &niceTicks, &systemTicks, &idleTicks,
|
||||||
|
&iowTicks, &irqTicks, &sirqTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
if (n != 4) {
|
if (n < 4) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
pticks->used = userTicks + niceTicks;
|
pticks->used = userTicks + niceTicks;
|
||||||
pticks->usedKernel = systemTicks;
|
pticks->usedKernel = systemTicks + irqTicks + sirqTicks;
|
||||||
pticks->total = userTicks + niceTicks + systemTicks + idleTicks;
|
pticks->total = userTicks + niceTicks + systemTicks + idleTicks +
|
||||||
|
iowTicks + irqTicks + sirqTicks;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user