com.etsy.statsd.profiler.util.StackTraceFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of statsd-jvm-profiler Show documentation
Show all versions of statsd-jvm-profiler Show documentation
Simple JVM profiler using StatsD
package com.etsy.statsd.profiler.util;
import com.google.common.base.Joiner;
import java.util.ArrayList;
import java.util.List;
/**
* Utility class for formatting stack traces
*
* @author Andrew Johnson
*/
public class StackTraceFormatter {
/**
* Formats a StackTraceElement as a String, excluding the line number
*
* @param element The StackTraceElement to format
* @return A String representing the given StackTraceElement
*/
public static String formatStackTraceElement(StackTraceElement element) {
return String.format("%s-%s-%d", element.getClassName().replace(".", "-"), element.getMethodName(), element.getLineNumber());
}
/**
* Formats an entire stack trace as a String
*
* @param stack The stack trace to format
* @return A String representing the given stack trace
*/
public static String formatStackTrace(StackTraceElement[] stack) {
List lines = new ArrayList<>();
for (StackTraceElement element : stack) {
lines.add(formatStackTraceElement(element));
}
return Joiner.on(".").join(lines);
}
}