Tidy existing given that lineNumber in SpiProfileLocationFactory always comes in as 0

The history behind this is that originally there was a "profileId" concept where that was a int value that could be used as an "id" for a transactional method that we wanted to profile.

That went away and then the idea was that bytecode enhancement would determine the line number and we would use that but that was a bad idea and we ended up with lineNumber always as 0.

These days with StackWalker and DProfileLocation we can do this better that way so yeah. A followup to this is to add to the api a boolean flag as to whether a profile location should be with line numbers (which can change frequently due to refactoring etc)
This commit is contained in:
rob
2023-02-22 15:22:58 +13:00
parent 9e186698fe
commit 34dc4375da
7 changed files with 41 additions and 38 deletions
@@ -16,7 +16,7 @@ class BasicProfileLocationTest {
@Test
void metricNameFromOverride() {
DTimedProfileLocation loc = new DTimedProfileLocation(12, "", MetricFactory.get().createTimedMetric("a.b.c"));
DTimedProfileLocation loc = new DTimedProfileLocation("", MetricFactory.get().createTimedMetric("a.b.c"));
loc.initWith("foo.label");
loc.add(42);
@@ -39,7 +39,7 @@ class BasicProfileLocationTest {
@Test
void metricNameFromTimed() {
DTimedProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("a.b.c"));
DTimedProfileLocation loc = new DTimedProfileLocation("foo", MetricFactory.get().createTimedMetric("a.b.c"));
loc.add(42);
BasicMetricVisitor visitor = new BasicMetricVisitor("v", naming);
@@ -52,7 +52,7 @@ class BasicProfileLocationTest {
@Test
void obtain() {
DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("junk"));
DProfileLocation loc = new DTimedProfileLocation("foo", MetricFactory.get().createTimedMetric("junk"));
assertThat(loc.obtain()).isTrue();
assertThat(loc.fullLocation()).endsWith("org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)");
@@ -5,17 +5,23 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class UtilLocationTest {
class UtilLocationTest {
@Test
public void label() {
void label() {
Assertions.assertThat(UtilLocation.label("foo")).isEqualTo("foo");
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
}
@Test
public void loc() {
void loc() {
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo("org.foo.MyFoo.doIt");
assertThat(UtilLocation.label("org.foo.MyFoo.doIt")).isEqualTo("MyFoo.doIt");
}
@Test
void locWithLineNumber() {
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)", true)).isEqualTo("org.foo.MyFoo.doIt:12");
assertThat(UtilLocation.label("org.foo.MyFoo.doIt:12")).isEqualTo("MyFoo.doIt:12");
}
}