Skip to content

Commit

Permalink
merged to include iss mchr3k#19 and iss mchr3k#36
Browse files Browse the repository at this point in the history
  • Loading branch information
eostermueller committed May 10, 2016
2 parents 3efda29 + b7dffdd commit 831929f
Show file tree
Hide file tree
Showing 13 changed files with 1,422 additions and 63 deletions.
14 changes: 12 additions & 2 deletions org.intrace/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@

<batchtest fork="yes" todir="./reports/junit/raw">
<fileset dir="./testsrc">
<include name="**/agent/*Test.java"/>
<include name="**/agent/*Test.java"/>
</fileset>
</batchtest>
</junit>
Expand Down Expand Up @@ -395,7 +395,7 @@

<target name="example_build">
<mkdir dir="./build/test" />
<javac destdir="./build/test" debug="true" source="1.6" target="1.6"
<javac destdir="./build/test" debug="true" source="1.7" target="1.7"
includeantruntime="false">
<src path="./testsrc"/>
<classpath>
Expand All @@ -415,6 +415,16 @@
</java>
</target>

<target name="example2" depends="jar,example_build">
<java classname="org.intracetest.agent.ArgumentTypes" fork="true">
<classpath>
<pathelement path="./build/test" />
</classpath>
<jvmarg value="-javaagent:build/jars/intrace-agent.jar=[instru-true" />
</java>
</target>


<target name="waitexample" depends="jar,example_build">
<java classname="example.TraceExample" fork="true">
<arg value="5000" />
Expand Down
Binary file modified org.intrace/lib/intrace-agent.jar
Binary file not shown.
99 changes: 68 additions & 31 deletions org.intrace/src/org/intrace/agent/AgentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import java.util.Locale;
import java.util.Map;

import org.intrace.output.trace.TraceHandler;
import org.intrace.shared.AgentConfigConstants;

/**
* Args Format: "[arg1[arg2[arg3"
*
* where argx is of the form value-parameter
*/
public class AgentSettings
public class AgentSettings implements VerboseLogger
{
// Static settings which control agent startup


// Static settings which control agent startup
private int serverPort = 9123;
private int callbackPort = -1;
private boolean waitStart = false;
Expand All @@ -23,27 +26,39 @@ public class AgentSettings
private int actualServerPort = -1;

// Dynamic settings
private String[] classRegex = new String[0];
private String[] excludeClassRegex = new String[0];
private InstrCriteria classesToInclude = null;
public InstrCriteria getClassesToInclude() {
return classesToInclude;
}


public InstrCriteria getClassesToExclude() {
return classesToExclude;
}

private InstrCriteria classesToExclude = null;
private boolean instruEnabled = true;
private boolean saveTracedClassfiles = false;
private boolean verboseMode = false;

public AgentSettings(String args)
{
parseArgs(args);
}


public AgentSettings(AgentSettings oldInstance)
{
// Copy all static state and dynamic settings
actualServerPort = oldInstance.getActualServerPort();
classRegex = oldInstance.getClassRegex();
excludeClassRegex = oldInstance.getExcludeClassRegex();
this.classesToInclude = oldInstance.classesToInclude;
this.classesToExclude = oldInstance.classesToExclude;


instruEnabled = oldInstance.isInstrumentationEnabled();
saveTracedClassfiles = oldInstance.saveTracedClassfiles();
verboseMode = oldInstance.isVerboseMode();
}
public AgentSettings(String args)
{
parseArgs(args);
}


public void parseArgs(String args)
Expand Down Expand Up @@ -111,15 +126,17 @@ else if (arg.toLowerCase(Locale.ROOT).equals(AgentConfigConstants.START_ACTIVATE
else if (arg.startsWith(AgentConfigConstants.CLASS_REGEX))
{
String classRegexStr = arg.replace(AgentConfigConstants.CLASS_REGEX, "");
classRegex = classRegexStr.split("\\|");
this.classesToInclude = new InstrCriteria(classRegexStr);
this.classesToInclude.verboseLogger = this;
}
else if (arg.startsWith(AgentConfigConstants.EXCLUDE_CLASS_REGEX))
{
String classExcludeRegexStr = arg
.replace(
AgentConfigConstants.EXCLUDE_CLASS_REGEX,
"");
excludeClassRegex = classExcludeRegexStr.split("\\|");
this.classesToExclude = new InstrCriteria(classExcludeRegexStr);
this.classesToExclude.verboseLogger = this;
}
}

Expand Down Expand Up @@ -150,12 +167,18 @@ public int getCallbackPort()

public String[] getClassRegex()
{
return classRegex;
String[] rc = {};
if (this.classesToInclude!=null)
rc = this.classesToInclude.getClassRegex();
return rc;
}

public String[] getExcludeClassRegex()
{
return excludeClassRegex;
String[] rc = {};
if (this.classesToExclude!=null)
rc = this.classesToInclude.getClassRegex();
return rc;
}

public boolean isInstrumentationEnabled()
Expand All @@ -178,8 +201,17 @@ public String toString()
{
// Output key settings
String currentSettings = "";
currentSettings += "Class Regex : " + Arrays.toString(classRegex) + "\n";
currentSettings += "Exclude Class Regex : " + Arrays.toString(excludeClassRegex) + "\n";

String includeString = "";
if (this.classesToInclude != null)
includeString = this.classesToInclude.toString();
currentSettings += "Include Class Regex : " + includeString + "\n";

String excludeString = "";
if (this.classesToExclude != null)
excludeString = this.classesToExclude.toString();
currentSettings += "Exclude Class Regex : " + excludeString + "\n";

currentSettings += "Tracing Enabled : " + instruEnabled + "\n";
currentSettings += "Save Traced Class Files : " + saveTracedClassfiles
+ "\n";
Expand All @@ -191,10 +223,20 @@ public Map<String, String> getSettingsMap()
Map<String, String> settingsMap = new HashMap<String, String>();
settingsMap.put(AgentConfigConstants.INSTRU_ENABLED,
Boolean.toString(instruEnabled));

String includeSettings = "";
if (this.classesToInclude!=null) {
includeSettings = this.classesToInclude.toString();
}
settingsMap.put(AgentConfigConstants.CLASS_REGEX,
getPatternString(classRegex));
includeSettings);

String excludeSettings = "";
if (this.classesToExclude!=null) {
includeSettings = this.classesToExclude.toString();
}
settingsMap.put(AgentConfigConstants.EXCLUDE_CLASS_REGEX,
getPatternString(excludeClassRegex));
excludeSettings);
settingsMap.put(AgentConfigConstants.VERBOSE_MODE,
Boolean.toString(verboseMode));
settingsMap.put(AgentConfigConstants.SAVE_TRACED_CLASSFILES,
Expand All @@ -203,18 +245,13 @@ public Map<String, String> getSettingsMap()
settingsMap.put(AgentConfigConstants.START_WAIT, Boolean.toString(waitStart));
return settingsMap;
}


public void logVerbose(String v) {
if (isVerboseMode())
{
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: " + v);
}
}

private String getPatternString(String[] parts)
{
StringBuilder strBuilder = new StringBuilder();
for (int ii = 0; ii < parts.length; ii++)
{
strBuilder.append(parts[ii]);
if (ii < (parts.length - 1))
{
strBuilder.append("|");
}
}
return strBuilder.toString();
}
}
14 changes: 7 additions & 7 deletions org.intrace/src/org/intrace/agent/ClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private byte[] getInstrumentedClassBytes(String xiClassName,

InstrumentedClassWriter writer = new InstrumentedClassWriter(xiClassName,
cr, analysis,
shouldInstrument);
shouldInstrument,
settings);
cr.accept(writer, 0);

return writer.toByteArray();
Expand Down Expand Up @@ -163,7 +164,7 @@ private boolean isToBeConsideredForInstrumentation(
return false;
}

// Don't sensitive classes
// Don't instrument sensitive classes
if (isSensitiveClass(className))
{
if (settings.isVerboseMode())
Expand All @@ -183,10 +184,9 @@ private boolean isToBeConsideredForInstrumentation(
return false;
}

// Don't modify classes which match the exclude regex
if ((settings.getExcludeClassRegex() == null)
|| matches(settings.getExcludeClassRegex(), className))
{

if (this.settings.getClassesToExclude() != null &&
this.settings.getClassesToExclude().allMethodsSpecified(className)) {
if (settings.isVerboseMode())
{
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: Ignoring class matching the active exclude regex: "
Expand Down Expand Up @@ -699,7 +699,7 @@ public void instrumentKlasses(Set<ComparableClass> klasses)
}
catch (Throwable e)
{
String error = "Error instrumenting [" + klass.klass.getName() + "]";
String error = "Exception [" + e.getMessage() + "] instrumenting [" + klass.klass.getName() + "]";
if (settings.isVerboseMode())
TraceHandler.INSTANCE.writeTraceOutput("DEBUG: !! " + error);
System.err.println(error);
Expand Down
Loading

0 comments on commit 831929f

Please sign in to comment.