ProcessStatistics extends AbstractStatistic { static void collectStatus(RandomAccessFile procStatus, StatisticsSink sink) { if (procStatus == null) return; try { procStatus.seek(0); String line; while ((line = procStatus.readLine()) != null) { if (line.startsWith("read_bytes:")) { Matcher matcher = LinuxHelper.COUNT_PATTERN.matcher(line); if (matcher.find()) sink.addSize(PROCESS_VAR_READ, Long.parseLong(matcher.group(1))); continue; } if (line.startsWith("write_bytes:")) { Matcher matcher = LinuxHelper.COUNT_PATTERN.matcher(line); if (matcher.find()) sink.addSize(PROCESS_VAR_WRITTEN, Long.parseLong(matcher.group(1))); continue; } if (line.startsWith("voluntary_ctxt_switches:")) { Matcher matcher = LinuxHelper.COUNT_PATTERN.matcher(line); if (matcher.find()) sink.add(PROCESS_VAR_CTXTSWITCHES, matcher.group(1)); continue; } if (line.startsWith("nonvoluntary_ctxt_switches:")) { Matcher matcher = LinuxHelper.COUNT_PATTERN.matcher(line); if (matcher.find()) sink.add(PROCESS_VAR_INTERRUPTS, matcher.group(1)); } } } catch (IOException ignored) { } } ProcessStatistics(); @Override void close();  }
@Test public void collectStatus() throws IOException { doCollectFromFile("/status.txt", "ctxtswitches=4, interrupts=67"); }