org.jgroups.util.GenerateProfilingScript Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
The newest version!
package org.jgroups.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
/**
* Takes a list of methods to profile and generates the Byteman script from them. See ./conf/scripts/profiled-methods.txt
* as an example
* @author Bela Ban
* @since 5.2.13
*/
public class GenerateProfilingScript {
protected int num_rules_generated;
protected void generate(String input_file, String output_file) throws IOException {
try(OutputStream out=new FileOutputStream(output_file); Stream lines=Files.lines(Path.of(input_file))) {
out.write(PREFIX.getBytes());
lines.filter(l -> !l.trim().isEmpty())
.forEach(l -> generateRule(l, out));
}
}
protected void generateRule(String method, OutputStream out) {
int index=method.lastIndexOf('.');
if(index < 0)
throw new IllegalArgumentException(String.format("method name not found in %s", method));
String classname=method.substring(0, index).trim(), method_name=method.substring(index+1).trim();
try {
Class> clazz=Util.loadClass(classname, (Class>)null);
boolean is_interface=clazz.isInterface();
String start_rule=String.format(START_RULE, clazz.getSimpleName() + "." + method_name,
is_interface? "INTERFACE" : "CLASS",
classname, method_name, clazz.getSimpleName() + "." + method_name);
String stop_rule=String.format(STOP_RULE, clazz.getSimpleName() + "." + method_name,
is_interface? "INTERFACE" : "CLASS",
classname, method_name, clazz.getSimpleName() + "." + method_name);
out.write(start_rule.getBytes());
out.write(stop_rule.getBytes());
}
catch(Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws IOException {
if(args.length != 2) {
System.err.printf("%s