use of com.facebook.buck.util.ProcessResourceConsumption in project buck by facebook.
the class ChromeTraceBuildListener method processResourceConsumption.
@Subscribe
public void processResourceConsumption(ProcessTracker.ProcessResourceConsumptionEvent event) {
Optional<ProcessResourceConsumption> resourceConsumption = event.getResourceConsumption();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("executable", event.getExecutableName());
if (event.getContext().isPresent()) {
builder.put("context", event.getContext().get().toString());
}
if (resourceConsumption.isPresent()) {
ProcessResourceConsumption res = resourceConsumption.get();
builder.put("mem_size_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getMemSize())));
builder.put("mem_resident_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getMemResident())));
builder.put("cpu_real_ms", Long.toString(res.getCpuReal()));
builder.put("cpu_user_ms", Long.toString(res.getCpuUser()));
builder.put("cpu_sys_ms", Long.toString(res.getCpuSys()));
builder.put("bytes_read_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getIoBytesRead())));
builder.put("bytes_written_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getIoBytesWritten())));
}
writeChromeTraceEvent("perf", "process", ChromeTraceEvent.Phase.COUNTER, builder.build(), event);
}
use of com.facebook.buck.util.ProcessResourceConsumption in project buck by facebook.
the class ProcessTrackerTest method testThisProcessInfo.
@Test
public void testThisProcessInfo() throws Exception {
BlockingQueue<ProcessResourceConsumptionEvent> events = new LinkedBlockingQueue<>();
try (ProcessTrackerForTest processTracker = createProcessTracker(events)) {
ProcessResourceConsumption res1 = createConsumption(42, 3, 0);
processHelper.setProcessResourceConsumption(123, res1);
ProcessTracker.ThisProcessInfo info1 = processTracker.new ThisProcessInfo(123, "proc1");
assertFalse(info1.hasProcessFinished());
testProcessInfo(info1, 123, "proc1", Optional.empty(), res1, events);
ProcessTracker.ThisProcessInfo info2 = processTracker.new ThisProcessInfo(200, "proc2");
assertFalse(info2.hasProcessFinished());
testProcessInfo(info2, 200, "proc2", Optional.empty(), null, events);
}
}
use of com.facebook.buck.util.ProcessResourceConsumption in project buck by facebook.
the class ProcessTrackerTest method testExternalProcessInfo.
@Test
public void testExternalProcessInfo() throws Exception {
BlockingQueue<ProcessResourceConsumptionEvent> events = new LinkedBlockingQueue<>();
try (ProcessTrackerForTest processTracker = createProcessTracker(events)) {
FakeNuProcess proc1 = new FakeNuProcess(111);
ProcessResourceConsumption res1 = createConsumption(42, 3, 0);
processHelper.setProcessResourceConsumption(111, res1);
ProcessTracker.ExternalProcessInfo info1 = processTracker.new ExternalProcessInfo(111, proc1, createParams("proc1"), CONTEXT);
assertFalse(info1.hasProcessFinished());
testProcessInfo(info1, 111, "proc1", Optional.of(createParams("proc1")), res1, events);
FakeNuProcess proc2 = new FakeNuProcess(222);
ProcessTracker.ExternalProcessInfo info2 = processTracker.new ExternalProcessInfo(222, proc2, createParams("proc2"), CONTEXT);
assertFalse(info2.hasProcessFinished());
testProcessInfo(info2, 222, "proc2", Optional.of(createParams("proc2")), null, events);
proc1.finish(-3);
assertTrue(info1.hasProcessFinished());
}
}
use of com.facebook.buck.util.ProcessResourceConsumption in project buck by facebook.
the class ProcessTrackerTest method testEventClass.
@Test
public void testEventClass() {
ProcessResourceConsumptionEvent event1 = new ProcessResourceConsumptionEvent("name42", Optional.empty(), Optional.empty(), Optional.empty());
assertEquals("name42", event1.getExecutableName());
assertEquals(Optional.empty(), event1.getParams());
assertEquals(Optional.empty(), event1.getContext());
assertEquals(Optional.empty(), event1.getResourceConsumption());
ProcessExecutorParams params = createParams("name100p");
ProcessResourceConsumption res = createConsumption(123, 45, 7011);
ProcessResourceConsumptionEvent event2 = new ProcessResourceConsumptionEvent("name100e", Optional.of(params), Optional.of(CONTEXT), Optional.of(res));
assertEquals("name100e", event2.getExecutableName());
assertEquals(Optional.of(params), event2.getParams());
assertEquals(Optional.of(CONTEXT), event2.getContext());
assertEquals(Optional.of(res), event2.getResourceConsumption());
}
use of com.facebook.buck.util.ProcessResourceConsumption in project buck by facebook.
the class ProcessTrackerTest method testProcessInfo.
private void testProcessInfo(ProcessTracker.ProcessInfo info, long pid, String name, Optional<ProcessExecutorParams> params, @Nullable ProcessResourceConsumption res1, BlockingQueue<ProcessResourceConsumptionEvent> events) throws Exception {
info.postEvent();
verifyEvents(ImmutableMap.of(name, params), ImmutableMap.of(name, Optional.ofNullable(res1)), events);
ProcessResourceConsumption res2 = createConsumption(5, 10, 40);
processHelper.setProcessResourceConsumption(pid, res2);
info.updateResourceConsumption();
// we keep track of the peak value for each metric
ProcessResourceConsumption res3 = ProcessResourceConsumption.getPeak(res1, res2);
info.postEvent();
verifyEvents(ImmutableMap.of(name, params), ImmutableMap.of(name, Optional.of(res3)), events);
}
Aggregations