/** * Checks for Benchmark Tags. If there are not tags events are passed through. If there are, there * are three kinds - 'start' which instantiates a benchmark; 'first' which starts a benchmark; and * 'stop' which ends a benchmark. These are consumed by this decorator. */ @Override public void append(Event e) throws IOException, InterruptedException { byte[] bench = e.get(BenchmarkInjectDecorator.ATTR_BENCHMARK); if (bench == null) { // This is the normal case -- a regular message getSink().append(e); return; } // All of these messages are silently consumed and not forwarded byte[] tagbytes = e.get(BenchmarkInjectDecorator.ATTR_BENCHMARK_TAG); Preconditions.checkNotNull(tagbytes); String tag = new String(tagbytes, CharEncUtils.RAW); if (Arrays.equals(bench, BenchmarkInjectDecorator.BENCH_START)) { StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); Benchmark b = new Benchmark(tag, pw, pw); b.mark("benchmarkStart"); benchmarks.put(tag, new Pair<Benchmark, StringWriter>(b, out)); } else if (Arrays.equals(bench, BenchmarkInjectDecorator.BENCH_FIRST)) { Benchmark b = benchmarks.get(tag).getLeft(); b.mark("benchmarkFirst"); } else if (Arrays.equals(bench, BenchmarkInjectDecorator.BENCH_STOP)) { Benchmark b = benchmarks.get(tag).getLeft(); b.mark("benchmarkDone"); b.done(); ReportEvent rpt = getMetrics(); LOG.info(rpt.toText()); reportSink.append(rpt); } else if (Arrays.equals(bench, BenchmarkInjectDecorator.BENCH_ERROR)) { Benchmark b = benchmarks.get(tag).getLeft(); b.mark("benchmarkError"); b.done(); LOG.info(getMetrics().toText()); ReportEvent rpt = getMetrics(); LOG.info(rpt.toText()); reportSink.append(rpt); } else { String msg = "Unexpected Benchmark event type: " + tag; LOG.error(msg); throw new IllegalArgumentException(msg); } }
@Test public void testCountSink() throws IOException, InterruptedException { Benchmark b = new Benchmark("nullsink"); b.mark("begin"); TextFileSource txt = new TextFileSource(HADOOP_DATA[0]); txt.open(); MemorySinkSource mem = new MemorySinkSource(); mem.open(); EventUtil.dumpAll(txt, mem); b.mark("disk_loaded"); CounterSink snk = new CounterSink("counter"); EventUtil.dumpAll(mem, snk); b.mark(snk.getName() + " done", snk.getCount()); b.done(); }
@Test public void testNullSink() throws IOException, InterruptedException { Benchmark b = new Benchmark("nullsink"); b.mark("begin"); TextFileSource txt = new TextFileSource(HADOOP_DATA[0]); txt.open(); MemorySinkSource mem = new MemorySinkSource(); mem.open(); EventUtil.dumpAll(txt, mem); b.mark("disk_loaded"); EventSink nullsnk = new NullSink(); EventUtil.dumpAll(mem, nullsnk); b.mark("nullsink done"); b.done(); }
@Test public void testHadoopRegexes() throws IOException, InterruptedException { Benchmark b = new Benchmark("hadoop_regexes"); b.mark("begin"); TextFileSource txt = new TextFileSource(HADOOP_DATA[0]); txt.open(); MemorySinkSource mem = new MemorySinkSource(); mem.open(); EventUtil.dumpAll(txt, mem); b.mark("disk_loaded"); SimpleRegexReporterBuilder bld = new SimpleRegexReporterBuilder(HADOOP_REGEXES); Collection<RegexGroupHistogramSink> sinks = bld.load(); MultiReporter snk = new MultiReporter("hadoop_regex_sinks", sinks); snk.open(); b.mark("filters_loaded", new File(HADOOP_REGEXES).getName(), sinks.size()); EventUtil.dumpAll(mem, snk); b.mark(snk.getName() + " done"); b.done(); }