Skip to content

Commit

Permalink
Fix sampling for line probe without condition
Browse files Browse the repository at this point in the history
In the case of a line probe MethodLocation is DEFAULT and we should
not consider the evaluteAt attribute as it is meant for method probe
only
  • Loading branch information
jpbempel committed Nov 2, 2023
1 parent 047c47c commit 69b777a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public enum MethodLocation {
EXIT;

public static boolean isSame(MethodLocation methodLocation, MethodLocation evaluateAt) {
if (methodLocation == MethodLocation.DEFAULT) {
// line probe always assume we are the right location
return true;
}
if (methodLocation == MethodLocation.ENTRY) {
return evaluateAt == MethodLocation.DEFAULT || evaluateAt == MethodLocation.ENTRY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void methodProbe() throws IOException, URISyntaxException {
public void singleLineProbe() throws IOException, URISyntaxException {
final String CLASS_NAME = "CapturedSnapshot01";
DebuggerTransformerTest.TestSnapshotListener listener =
installSingleProbe(CLASS_NAME, "main", "int (java.lang.String)", "8");
installSingleProbeAtExit(CLASS_NAME, "main", "int (java.lang.String)", "8");
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
int result = Reflect.on(testClass).call("main", "1").get();
assertEquals(3, result);
Expand Down Expand Up @@ -1582,7 +1582,7 @@ private Snapshot doUnknownCount(String CLASS_NAME) throws IOException, URISyntax
public void beforeForLoopLineProbe() throws IOException, URISyntaxException {
final String CLASS_NAME = "CapturedSnapshot02";
DebuggerTransformerTest.TestSnapshotListener listener =
installSingleProbe(CLASS_NAME, null, null, "46");
installSingleProbeAtExit(CLASS_NAME, null, null, "46");
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
int result = Reflect.on(testClass).call("main", "synchronizedBlock").get();
assertEquals(76, result);
Expand All @@ -1597,10 +1597,12 @@ public void dupLineProbeSameTemplate() throws IOException, URISyntaxException {
LogProbe probe1 =
createProbeBuilder(PROBE_ID1, CLASS_NAME, null, null, "39")
.template(LOG_TEMPLATE, parseTemplate(LOG_TEMPLATE))
.evaluateAt(MethodLocation.EXIT)
.build();
LogProbe probe2 =
createProbeBuilder(PROBE_ID2, CLASS_NAME, null, null, "39")
.template(LOG_TEMPLATE, parseTemplate(LOG_TEMPLATE))
.evaluateAt(MethodLocation.EXIT)
.build();
DebuggerTransformerTest.TestSnapshotListener listener =
installProbes(CLASS_NAME, probe1, probe2);
Expand Down Expand Up @@ -1910,6 +1912,12 @@ private DebuggerTransformerTest.TestSnapshotListener installSingleProbe(
return installProbes(typeName, logProbes);
}

private DebuggerTransformerTest.TestSnapshotListener installSingleProbeAtExit(
String typeName, String methodName, String signature, String... lines) {
LogProbe logProbes = createProbeAtExit(PROBE_ID, typeName, methodName, signature, lines);
return installProbes(typeName, logProbes);
}

private DebuggerTransformerTest.TestSnapshotListener installProbes(
String expectedClassName, Configuration configuration) {
Config config = mock(Config.class);
Expand Down Expand Up @@ -2169,6 +2177,13 @@ private static LogProbe createProbe(
return createProbeBuilder(id, typeName, methodName, signature, lines).build();
}

private static LogProbe createProbeAtExit(
ProbeId id, String typeName, String methodName, String signature, String... lines) {
return createProbeBuilder(id, typeName, methodName, signature, lines)
.evaluateAt(MethodLocation.EXIT)
.build();
}

private static LogProbe.Builder createProbeBuilder(
ProbeId id, String typeName, String methodName, String signature, String... lines) {
return LogProbe.builder()
Expand All @@ -2186,6 +2201,7 @@ private static LogProbe createSourceFileProbe(ProbeId id, String sourceFile, int
.probeId(id)
.captureSnapshot(true)
.where(null, null, null, line, sourceFile)
.evaluateAt(MethodLocation.EXIT)
.build();
}

Expand Down

0 comments on commit 69b777a

Please sign in to comment.