Home | History | Annotate | Download | only in perf
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Marc R. Hoffmann - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.core.test.perf;
     13 
     14 import org.jacoco.core.instr.Instrumenter;
     15 import org.jacoco.core.runtime.IRuntime;
     16 import org.jacoco.core.runtime.LoggerRuntime;
     17 import org.jacoco.core.test.TargetLoader;
     18 import org.objectweb.asm.ClassReader;
     19 
     20 /**
     21  * Scenario to measure the overhead in terms of additional byte code size
     22  * through instrumentation.
     23  */
     24 public class InstrumentationSizeSzenario implements IPerfScenario {
     25 
     26 	private final Class<?> target;
     27 
     28 	public InstrumentationSizeSzenario(Class<?> target) {
     29 		this.target = target;
     30 	}
     31 
     32 	public void run(IPerfOutput output) throws Exception {
     33 		final IRuntime runtime = new LoggerRuntime();
     34 		ClassReader reader = new ClassReader(TargetLoader.getClassData(target));
     35 		final Instrumenter instr = new Instrumenter(runtime);
     36 		instr.instrument(reader);
     37 		output.writeByteResult("instrumented class",
     38 				instr.instrument(reader).length, reader.b.length);
     39 	}
     40 
     41 }
     42