Search in sources :

Example 1 with ProcessResourceConsumptionEvent

use of com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent in project buck by facebook.

the class ProcessTrackerTest method createProcessTracker.

private ProcessTrackerForTest createProcessTracker(final BlockingQueue<ProcessResourceConsumptionEvent> events) {
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    eventBus.register(new Object() {

        @Subscribe
        public void event(ProcessResourceConsumptionEvent event) {
            events.add(event);
        }
    });
    return new ProcessTrackerForTest(eventBus, FakeInvocationInfoFactory.create(), processHelper, processRegistry);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ProcessResourceConsumptionEvent(com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with ProcessResourceConsumptionEvent

use of com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent in project buck by facebook.

the class ProcessTrackerTest method pollEvents.

private static List<ProcessResourceConsumptionEvent> pollEvents(BlockingQueue<ProcessResourceConsumptionEvent> events) throws Exception {
    List<ProcessResourceConsumptionEvent> res = new ArrayList<>();
    while (!events.isEmpty()) {
        ProcessResourceConsumptionEvent event = events.poll(0, TimeUnit.MILLISECONDS);
        res.add(event);
    }
    return res;
}
Also used : ProcessResourceConsumptionEvent(com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent) ArrayList(java.util.ArrayList)

Example 3 with ProcessResourceConsumptionEvent

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

Example 4 with ProcessResourceConsumptionEvent

use of com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent in project buck by facebook.

the class ProcessTrackerTest method dumpEvents.

private static void dumpEvents(BlockingQueue<ProcessResourceConsumptionEvent> events) {
    System.err.println("Dumping events: " + events.size());
    for (ProcessResourceConsumptionEvent event : events) {
        System.err.println("{'" + event.getExecutableName() + "', " + event.getParams() + "}");
    }
    System.err.println("");
}
Also used : ProcessResourceConsumptionEvent(com.facebook.buck.util.perf.ProcessTracker.ProcessResourceConsumptionEvent)

Example 5 with ProcessResourceConsumptionEvent

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