Search in sources :

Example 6 with ProcessResourceConsumptionEvent

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());
}
Also used : ProcessResourceConsumptionEvent(com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ProcessResourceConsumption(com.facebook.buck.util.ProcessResourceConsumption) Test(org.junit.Test)

Example 7 with ProcessResourceConsumptionEvent

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);
}
Also used : ProcessResourceConsumptionEvent(com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent) FakeProcess(com.facebook.buck.util.FakeProcess) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) FakeNuProcess(com.facebook.buck.util.FakeNuProcess) Test(org.junit.Test)

Aggregations

ProcessResourceConsumptionEvent (com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent)7 Test (org.junit.Test)4 ProcessResourceConsumption (com.facebook.buck.util.ProcessResourceConsumption)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 FakeNuProcess (com.facebook.buck.util.FakeNuProcess)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 FakeProcess (com.facebook.buck.util.FakeProcess)1 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)1 Subscribe (com.google.common.eventbus.Subscribe)1 ArrayList (java.util.ArrayList)1