use of com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent 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.perf.ProcessTracker.ProcessResourceConsumptionEvent in project buck by facebook.
the class ProcessTrackerTest method testInteraction.
@Test
public void testInteraction() throws Exception {
BlockingQueue<ProcessResourceConsumptionEvent> events = new LinkedBlockingQueue<>();
try (ProcessTrackerForTest processTracker = createProcessTracker(events)) {
processTracker.explicitStartUp();
processTracker.verifyThisProcessInfo(PID, "<buck-process>");
assertEquals(1, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that ProcessTracker subscribes to ProcessRegistry and that calling
// registerProcess causes ProcessTracker to start tracking the process.
FakeNuProcess proc41 = new FakeNuProcess(41);
processTracker.verifyNoProcessInfo(41);
assertEquals(1, processTracker.processesInfo.size());
processRegistry.registerProcess(proc41, createParams("proc41"), CONTEXT);
processTracker.verifyExternalProcessInfo(41, proc41, createParams("proc41"));
assertEquals(2, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that after registering a new process, both are being tracked
FakeNuProcess proc42 = new FakeNuProcess(42);
processRegistry.registerProcess(proc42, createParams("proc42"), CONTEXT);
processTracker.verifyExternalProcessInfo(41, proc41, createParams("proc41"));
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that after registering a process with an already tracked pid,
// the old process info gets discarded.
FakeNuProcess proc41b = new FakeNuProcess(41);
processRegistry.registerProcess(proc41b, createParams("proc41b"), CONTEXT);
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
// Verify an event has been posted to the bus on remove
verifyEvents(ImmutableMap.of("proc41", Optional.of(createParams("proc41"))), null, events);
// Verify that processes whose pid cannot be obtained are ignored
processRegistry.registerProcess(new FakeProcess(0), createParams("proc0"), CONTEXT);
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that ongoing processes are kept after refresh
processTracker.explicitRunOneIteration();
processTracker.verifyExternalProcessInfo(42, proc42, createParams("proc42"));
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
assertEquals(3, processTracker.processesInfo.size());
verifyEvents(ImmutableMap.of(), null, events);
// Verify that finished processes are removed after refresh
proc42.finish(0);
processTracker.explicitRunOneIteration();
processTracker.verifyExternalProcessInfo(41, proc41b, createParams("proc41b"));
processTracker.verifyNoProcessInfo(42);
assertEquals(2, processTracker.processesInfo.size());
// Verify an event has been posted to the bus on remove
verifyEvents(ImmutableMap.of("proc42", Optional.of(createParams("proc42"))), null, events);
processTracker.explicitShutDown();
processTracker.verifyNoProcessInfo(41);
processTracker.verifyNoProcessInfo(PID);
assertEquals(0, processTracker.processesInfo.size());
// Verify events for the existing processes have been posted to the bus on shut down
verifyEvents(ImmutableMap.of("proc41b", Optional.of(createParams("proc41b")), "<buck-process>", Optional.empty()), null, events);
}
// verify no events are sent after closing ProcessTracker
processRegistry.registerProcess(new FakeNuProcess(43), createParams("proc43"), CONTEXT);
verifyEvents(ImmutableMap.of(), null, events);
}
Aggregations