Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"exitStackTrace" and "gzip" enhancements together in a single pull request. #34

Merged
merged 2 commits into from
Apr 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified org.intrace/lib/intrace-agent.jar
Binary file not shown.
22 changes: 21 additions & 1 deletion org.intrace/src/org/intrace/agent/AgentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class AgentSettings
private int actualServerPort = -1;

// Dynamic settings
private boolean gzipEnabled = false;
private String[] classRegex = new String[0];
private String[] excludeClassRegex = new String[0];
private boolean instruEnabled = true;
Expand All @@ -38,14 +39,22 @@ public AgentSettings(AgentSettings oldInstance)
{
// Copy all static state and dynamic settings
actualServerPort = oldInstance.getActualServerPort();
gzipEnabled = oldInstance.isGzipEnabled();
classRegex = oldInstance.getClassRegex();
excludeClassRegex = oldInstance.getExcludeClassRegex();
instruEnabled = oldInstance.isInstrumentationEnabled();
saveTracedClassfiles = oldInstance.saveTracedClassfiles();
verboseMode = oldInstance.isVerboseMode();
}

public void parseArgs(String args)
public boolean isGzipEnabled() {
return gzipEnabled;
}
public void setGzipEnabled(boolean val) {
gzipEnabled = val;
}

public void parseArgs(String args)
{
String[] seperateArgs = args.split("\\[");
for (int ii = 0; ii < seperateArgs.length; ii++)
Expand Down Expand Up @@ -107,6 +116,14 @@ else if (arg.toLowerCase(Locale.ROOT).equals(AgentConfigConstants.START_ACTIVATE
{
waitStart = false;
}
else if (arg.toLowerCase(Locale.ROOT).equals(AgentConfigConstants.GZIP + "true"))
{
gzipEnabled = true;
}
else if (arg.toLowerCase(Locale.ROOT).equals(AgentConfigConstants.GZIP + "false"))
{
gzipEnabled = false;
}
else if (arg.startsWith(AgentConfigConstants.CLASS_REGEX))
{
String classRegexStr = arg.replace(AgentConfigConstants.CLASS_REGEX, "");
Expand Down Expand Up @@ -177,6 +194,7 @@ public String toString()
{
// Output key settings
String currentSettings = "";
currentSettings += "GZip Enabled : " + gzipEnabled + "\n";
currentSettings += "Class Regex : " + Arrays.toString(classRegex) + "\n";
currentSettings += "Exclude Class Regex : " + Arrays.toString(excludeClassRegex) + "\n";
currentSettings += "Tracing Enabled : " + instruEnabled + "\n";
Expand All @@ -190,6 +208,8 @@ public Map<String, String> getSettingsMap()
Map<String, String> settingsMap = new HashMap<String, String>();
settingsMap.put(AgentConfigConstants.INSTRU_ENABLED,
Boolean.toString(instruEnabled));
settingsMap.put(AgentConfigConstants.GZIP,
Boolean.toString(gzipEnabled));
settingsMap.put(AgentConfigConstants.CLASS_REGEX,
getPatternString(classRegex));
settingsMap.put(AgentConfigConstants.EXCLUDE_CLASS_REGEX,
Expand Down
10 changes: 10 additions & 0 deletions org.intrace/src/org/intrace/agent/ClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.intrace.output.AgentHelper;
import org.intrace.output.InstruRunnable;
import org.intrace.output.trace.TraceHandler;
import org.intrace.output.trace.TraceSettings;
import org.intrace.shared.AgentConfigConstants;
import org.objectweb.asm.ClassReader;

Expand Down Expand Up @@ -482,6 +483,9 @@ public Map<String, String> getSettings()
Integer.toString(modifiedClasses.size()));
return settingsMap;
}
public boolean isGzipEnabled() {
return settings.isGzipEnabled();
}

/**
* Handle a message and return a response.
Expand All @@ -507,6 +511,12 @@ else if (oldSettings.isInstrumentationEnabled() != settings
// System.out.println("## Settings Changed");
setInstrumentationEnabled(settings.isInstrumentationEnabled());
}
else if (oldSettings.isGzipEnabled() != settings.isGzipEnabled())
{
//For coding simplicity and user clarity, the gzip parameter can only be set on agent side
//So, return to the old setting, which originated with the intrace agent command line parameter -- [gzip-true
settings.setGzipEnabled(oldSettings.isGzipEnabled());
}
else if (!Arrays.equals(oldSettings.getClassRegex(), settings.getClassRegex()))
{
// System.out.println("## Settings Changed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public class AgentClientConnection extends InstruRunnable
{
private final Socket connectedClient;
private final ClassTransformer transformer;
private boolean traceConnEstablished = false;
public ClassTransformer getTransformer() {
return transformer;
}

private boolean traceConnEstablished = false;
private final Object traceConnLock = new Object();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ClientStrings
public static final String ENABLE_BRANCH_TRACE = "Branch";
public static final String ENABLE_ARGS_TRACE = "Method Args, Return Values, Exceptions";
public static final String ENABLE_ARRAY_TRACE = "Truncate Array Args";
public static final String ENABLE_EXIT_STACK_TRACE = "Add Stacktrace to Exit";

public static final String BEGIN_CAPTURE_CALLERS = "New Callers Capture...";
public static final String END_CAPTURE_CALLERS = "End Callers Capture";
Expand Down
25 changes: 25 additions & 0 deletions org.intrace/src/org/intrace/client/gui/helper/InTraceUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ private class TraceTab
final Button branchTrace;
final Button argsTrace;
final Button arrayTrace;
final Button exitStackTrace;

final Composite composite;

Expand All @@ -813,6 +814,11 @@ private TraceTab(Composite parent)
arrayTrace.setText(ClientStrings.ENABLE_ARRAY_TRACE);
arrayTrace.setAlignment(SWT.CENTER);

exitStackTrace = new Button(composite, SWT.CHECK);
exitStackTrace.setText(ClientStrings.ENABLE_EXIT_STACK_TRACE);
exitStackTrace.setAlignment(SWT.CENTER);


entryExitTrace
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
{
Expand Down Expand Up @@ -857,6 +863,17 @@ public void widgetSelected(SelectionEvent arg0)
settingsData.truncArraysEnabled = !settingsData.truncArraysEnabled;
}
});
exitStackTrace
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent arg0)
{
toggleSetting(settingsData.exitStackTrace, "[exit-stack-trace-true",
"[exit-stack-trace-false");
settingsData.exitStackTrace = !settingsData.exitStackTrace;
}
});
}
}

Expand Down Expand Up @@ -2026,6 +2043,11 @@ public boolean isNetOutputEnabled()
{
return settingsData.netOutEnabled;
}
@Override
public boolean isGzipEnabled()
{
return settingsData.gzipEnabled;
}
};
networkTraceThread = new NetworkDataReceiverThread(remoteAddress,
networkTracePort, config, outputTabs.textOutputTab.filterThread);
Expand Down Expand Up @@ -2204,6 +2226,7 @@ private void updateUIStateSameThread()

settingsTabs.traceTab.argsTrace.setEnabled(true);
settingsTabs.traceTab.branchTrace.setEnabled(true);
settingsTabs.traceTab.exitStackTrace.setEnabled(true);
settingsTabs.traceTab.entryExitTrace.setEnabled(true);
settingsTabs.traceTab.arrayTrace.setEnabled(true);
settingsTabs.agentOutputSettingsTab.fileOutput.setEnabled(true);
Expand All @@ -2218,6 +2241,7 @@ private void updateUIStateSameThread()
// Update the button pressed/unpressed state
settingsTabs.traceTab.argsTrace.setSelection(settingsData.argsEnabled);
settingsTabs.traceTab.branchTrace.setSelection(settingsData.branchEnabled);
settingsTabs.traceTab.exitStackTrace.setSelection(settingsData.exitStackTrace);
settingsTabs.traceTab.entryExitTrace.setSelection(settingsData.entryExitEnabled);
settingsTabs.traceTab.arrayTrace.setSelection(settingsData.truncArraysEnabled);
settingsTabs.agentOutputSettingsTab.fileOutput.setSelection(settingsData.fileOutEnabled);
Expand Down Expand Up @@ -2256,6 +2280,7 @@ private void updateUIStateSameThread()

settingsTabs.traceTab.argsTrace.setEnabled(false);
settingsTabs.traceTab.branchTrace.setEnabled(false);
settingsTabs.traceTab.exitStackTrace.setEnabled(false);
settingsTabs.traceTab.entryExitTrace.setEnabled(false);
settingsTabs.traceTab.arrayTrace.setEnabled(false);
settingsTabs.agentOutputSettingsTab.fileOutput.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import java.net.InetSocketAddress;
import java.net.Socket;

import org.intrace.shared.Base64;


public class NetworkDataReceiverThread implements Runnable
{
public static interface INetworkOutputConfig
{
public boolean isNetOutputEnabled();
public boolean isGzipEnabled();
}

private final Socket traceSocket;
Expand Down Expand Up @@ -53,6 +57,10 @@ public void run()
{
if (outputConfig.isNetOutputEnabled())
{
if (outputConfig.isGzipEnabled()) {
byte[] tmp = Base64.decode(traceLine);
traceLine = new String(tmp);
}
traceThread.addTraceLine(traceLine);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public class ParsedSettingsData

public boolean entryExitEnabled;
public boolean branchEnabled;
public boolean gzipEnabled = false;
public boolean truncArraysEnabled;
public boolean argsEnabled;
public boolean exitStackTrace = false;

public boolean stdOutEnabled;
public boolean fileOutEnabled;
public boolean netOutEnabled;
Expand All @@ -35,6 +38,24 @@ public ParsedSettingsData(Map<String, String> settingsMap)
{
this.settingsMap = settingsMap;

if ("true".equals(settingsMap.get(AgentConfigConstants.GZIP)))
{
gzipEnabled = true;
}
else
{
gzipEnabled = false;
}

if ("true".equals(settingsMap.get(AgentConfigConstants.EXIT_STACK_TRACE)))
{
exitStackTrace = true;
}
else
{
exitStackTrace = false;
}

classRegex = settingsMap.get(AgentConfigConstants.CLASS_REGEX);
classExcludeRegex = settingsMap
.get(AgentConfigConstants.EXCLUDE_CLASS_REGEX);
Expand Down Expand Up @@ -86,6 +107,7 @@ public ParsedSettingsData(Map<String, String> settingsMap)
branchEnabled = false;
}


if ("true".equals(settingsMap.get(TraceConfigConstants.ARG)))
{
argsEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.concurrent.TimeUnit;

import org.intrace.agent.server.AgentClientConnection;
import org.intrace.shared.Base64;

public class NetworkDataSenderThread extends InstruRunnable
{
Expand Down Expand Up @@ -100,6 +101,10 @@ public void runMethod()
Object traceLine = outgoingData.poll(5, TimeUnit.SECONDS);
if (traceLine != null)
{
if (traceLine instanceof String && connection.getTransformer().isGzipEnabled()) {
String tmp = (String)traceLine;
traceLine = Base64.encodeBytes(tmp.getBytes(), Base64.GZIP);
}
traceWriter.writeObject(traceLine);
}
else
Expand Down
52 changes: 48 additions & 4 deletions org.intrace/src/org/intrace/output/trace/TraceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.io.StringWriter;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.intrace.output.AgentHelper;
Expand All @@ -16,6 +18,12 @@
*/
public class TraceHandler implements IInstrumentationHandler
{
/**
* Including the period at the end enables code in "org.intracetest" to be included in the trace
*/
private static final String INTRACE_PACKAGE = "org.intrace.";
private static final String THREAD = "java.lang.Thread";
private static final String GET_STACK_TRACE = "getStackTrace";
public static final TraceHandler INSTANCE = new TraceHandler();
private TraceHandler()
{
Expand All @@ -26,7 +34,8 @@ private TraceHandler()
private boolean branchTrace = false;
private boolean argTrace = true;
private boolean truncateArrays = true;

private boolean exitStackTrace = false;

private static final TraceSettings traceSettings = new TraceSettings("");

public String getResponse(String args)
Expand All @@ -50,7 +59,8 @@ public String getResponse(String args)
branchTrace = traceSettings.isBranchTraceEnabled();
argTrace = traceSettings.isArgTraceEnabled();
truncateArrays = traceSettings.isTruncateArraysEnabled();

exitStackTrace = traceSettings.isExitStackTraceEnabled();

return null;
}

Expand Down Expand Up @@ -251,6 +261,15 @@ public void val(String desc, String className, String methodName,
}

private static final char ESCAPE_REPLACEMENT = '\u25A1';
/**
* If user has requested to see a stack trace for each 'exit' event (with the parameter [exit-stack-trace-true) , then
* this delimiter will follow the regular event text, which will be followed by the text of the stack trace.
*/
private static final String STACK_TRACE_DELIM = "~";
/**
* Just like Arrays.toString(Object), place a comma between each element of the stack trace
*/
private static final Object STACK_ELE_DELIM = ",";

private String replaceChars(String xiArg)
{
Expand Down Expand Up @@ -384,13 +403,38 @@ public void enter(String className, String methodName, int lineNo)
}
}

/**
* Remove all "org.intrace" elements from the current stack trace and return it as string.
* @return
*/
public String getStackTrace() {

StringBuilder sb = new StringBuilder();
int counter = 0;
for(StackTraceElement ste : Thread.currentThread().getStackTrace() ) {
if ( ste.getClassName().indexOf(INTRACE_PACKAGE) <0
&& (ste.getClassName().indexOf(THREAD) < 0) && ste.getMethodName().indexOf(GET_STACK_TRACE)<0) {
if (counter++>0) sb.append(STACK_ELE_DELIM); //Just like Arrays.toString(), place a comma between each stack trace ele.
sb.append(ste.toString());
}
}

return sb.toString();
}
@Override
public void exit(String className, String methodName, int lineNo)
{
if (entryExitTrace)
{
writeTraceOutput(className + ":" + methodName + ": }" +
(lineNo >= 0 ? ":" + lineNo : ""));

if (exitStackTrace) {
writeTraceOutput(className + ":" + methodName + ": }" +
(lineNo >= 0 ? ":" + lineNo : "") +
STACK_TRACE_DELIM + getStackTrace() );
} else {
writeTraceOutput(className + ":" + methodName + ": }" +
(lineNo >= 0 ? ":" + lineNo : "") );
}
}
}

Expand Down
Loading