-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/PerfTypeMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.muzzle; | ||
|
||
import io.opentelemetry.javaagent.bootstrap.StopWatch; | ||
import io.opentelemetry.javaagent.bootstrap.StopWatchImpl; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class PerfTypeMatcher implements ElementMatcher<TypeDescription> { | ||
private static final ThreadLocal<Boolean> matching = new ThreadLocal<>(); | ||
private final ElementMatcher<TypeDescription> delegate; | ||
|
||
public PerfTypeMatcher(ElementMatcher<TypeDescription> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
public static boolean isMatching() { | ||
return matching.get() != null; | ||
} | ||
|
||
@Override | ||
public boolean matches(TypeDescription target) { | ||
matching.set(Boolean.TRUE); | ||
try (StopWatch sw = StopWatchImpl.create("match")) { | ||
return delegate.matches(target); | ||
} finally { | ||
matching.set(null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package muzzle.other; | ||
|
||
import muzzle.TestClasses; | ||
|
||
// to testing protected methods we need to have a test classes in different packages | ||
@SuppressWarnings("unused") | ||
public class OtherTestClasses { | ||
|
||
@SuppressWarnings("ClassNamedLikeTypeParameter") | ||
public static class Nested { | ||
public static class B2 extends TestClasses.Nested.B { | ||
public void stuff() { | ||
super.protectedMethod(); | ||
} | ||
} | ||
|
||
private Nested() {} | ||
} | ||
|
||
private OtherTestClasses() {} | ||
} |