use of com.google.common.eventbus.Subscribe 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.google.common.eventbus.Subscribe in project buck by facebook.
the class BroadcastEventListenerTest method tryBroadcastInMultipleBuses.
@Test
public void tryBroadcastInMultipleBuses() {
BuckEventBus bus1 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus1"));
BuckEventBus bus2 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus2"));
bus1.register(new Object() {
@Subscribe
public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
trackedEvents.add(event);
}
});
bus2.register(new Object() {
@Subscribe
public void actionGraphCacheHit(ActionGraphEvent.Cache.Hit event) {
trackedEvents.add(event);
}
@Subscribe
public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
trackedEvents.add(event);
}
});
BroadcastEventListener listener = new BroadcastEventListener();
listener.addEventBus(bus1);
listener.addEventBus(bus2);
listener.broadcast(ActionGraphEvent.Cache.hit());
listener.broadcast(ActionGraphEvent.Cache.miss(/* cacheWasEmpty */
false));
assertEquals(countEventsOf(ActionGraphEvent.Cache.Miss.class), 2);
assertEquals(countEventsOf(ActionGraphEvent.Cache.Hit.class), 1);
}
use of com.google.common.eventbus.Subscribe in project buck by facebook.
the class ActionGraphCacheTest method setUp.
@Before
public void setUp() {
// Creates the following target graph:
// A
// /
// B
nodeB = createTargetNode("B");
nodeA = createTargetNode("A", nodeB);
targetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
eventBus = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)));
broadcastEventListener = new BroadcastEventListener();
broadcastEventListener.addEventBus(eventBus);
eventBus.register(new Object() {
@Subscribe
public void actionGraphCacheEvent(ActionGraphEvent.Cache event) {
trackedEvents.add(event);
}
});
}
use of com.google.common.eventbus.Subscribe in project buck by facebook.
the class ShellStepTest method createContext.
private static ExecutionContext createContext(ImmutableMap<ProcessExecutorParams, FakeProcess> processes, final Console console) throws IOException {
ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).setProcessExecutor(new FakeProcessExecutor(processes, console)).build();
context.getBuckEventBus().register(new Object() {
@Subscribe
public void logEvent(ConsoleEvent event) throws IOException {
if (event.getLevel().equals(Level.WARNING)) {
console.getStdErr().write(event.getMessage().getBytes(Charsets.UTF_8));
}
}
});
return context;
}
use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.
the class ForgeModContainer method modConstruction.
@Subscribe
public void modConstruction(FMLConstructionEvent evt) {
List<String> all = Lists.newArrayList();
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
Iterator<String> itr = all.iterator();
while (itr.hasNext()) {
String cls = itr.next();
if (!cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"))
itr.remove();
}
FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "Preloading CrashReport Classes");
//Sort it because I like pretty output ;)
Collections.sort(all);
for (String name : all) {
FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "\t" + name);
try {
Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
} catch (Exception e) {
e.printStackTrace();
}
}
NetworkRegistry.INSTANCE.register(this, this.getClass(), "*", evt.getASMHarvestedData());
ForgeNetworkHandler.registerChannel(this, evt.getSide());
ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
}
Aggregations