Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public void skipSpaces() {
skipPast(' ');
}

public void skipRightBrace() {
skipPast(')');
}

public void skipLine() {
skipPast('\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public boolean getSnapshot(CpuMetrics snapshot) {
return false;
}

reader.skipRightBrace();

int index = 0;
while (index < PROC_USER_TIME_FIELD) {
while (index < PROC_USER_TIME_FIELD - 1) {
reader.skipSpaces();
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ public void testRealProcfile() throws Exception {
assertThat(snapshot.childSystemTimeS).isEqualTo(11.0 / 100);
}

@Test
public void testRealProcfileWithBlankedComm() throws Exception {
String stat =
"21031 (facebook.blank katana) S 354 354 0 0 -1 1077952832 227718 1446 318 0 9852 889 6 11 20 0 133 0 502496 2050461696 70553 4294967295 1 1 0 0 0 0 4608 0 1166120188 4294967295 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
TestableCpuMetricsCollector collector =
new TestableCpuMetricsCollector().setPath(createFile(stat));

CpuMetrics snapshot = new CpuMetrics();
assertThat(collector.getSnapshot(snapshot)).isTrue();

assertThat(snapshot.userTimeS).isEqualTo(9852.0 / 100);
assertThat(snapshot.systemTimeS).isEqualTo(889.0 / 100);
assertThat(snapshot.childUserTimeS).isEqualTo(6.0 / 100);
assertThat(snapshot.childSystemTimeS).isEqualTo(11.0 / 100);
}

@Test
public void testSaneProcFile() throws Exception {
StringBuilder testStringBuilder = new StringBuilder();
Expand Down