ENH: Add ProfileLocation - Part 2 - performance metrics for transactions with label and profileLocation

This commit is contained in:
Rob Bygrave
2018-01-22 14:54:27 +13:00
parent 4e33027fdf
commit 51d2e4c600
37 changed files with 779 additions and 33 deletions
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebeaninternal.metric.MetricFactory;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -9,7 +10,7 @@ public class BasicProfileLocationTest {
@Test
public void obtain() {
DProfileLocation loc = new DProfileLocation(12);
DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("junk"));
assertThat(loc.obtain()).endsWith(":12)");
assertThat(loc.shortDescription()).isEqualTo("NativeMethodAccessorImpl.invoke0(Native Method:12)");
@@ -4,12 +4,15 @@ import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import io.ebean.Transaction;
import io.ebean.annotation.Transactional;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Transactional;
import io.ebean.meta.MetaInfoManager;
import io.ebean.meta.MetaTimedMetric;
import io.ebeaninternal.api.SpiTransaction;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.EBasicVer;
import org.junit.Test;
import org.tests.model.basic.TSDetail;
import org.tests.model.basic.TSMaster;
@@ -26,11 +29,15 @@ public class TestBatchInsertFlush extends BaseTestCase {
EbeanServer server = Ebean.getDefaultServer();
MetaInfoManager metaInfoManager = server.getMetaInfoManager();
metaInfoManager.collectTransactionStatistics(true);
Transaction transaction = server.beginTransaction();
try {
transaction.setPersistCascade(false);
transaction.setBatchSize(10);
transaction.setBatch(PersistBatch.ALL);
transaction.setLabel("TestBatchInsertFlush.no_cascade");
LoggedSqlCollector.start();
@@ -64,11 +71,19 @@ public class TestBatchInsertFlush extends BaseTestCase {
// detail
assertThat(sql.get(2)).contains("insert into t_detail_with_other_namexxxyy");
assertThat(((SpiTransaction)transaction).getLabel()).isEqualTo("TestBatchInsertFlush.no_cascade");
} finally {
transaction.end();
}
List<MetaTimedMetric> txnStats = metaInfoManager.collectTransactionStatistics(true);
assertThat(txnStats).hasSize(1);
assertThat(txnStats.get(0).getName()).isEqualTo("txn.named.TestBatchInsertFlush.no_cascade");
for (MetaTimedMetric txnMetric : txnStats) {
System.out.println(txnMetric);
}
}
@Test
@@ -7,15 +7,20 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ProfileLocationTest {
private static ProfileLocation loc = ProfileLocation.create(12);
@Test
public void test() {
assertThat(doIt()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:19)");
}
private static ProfileLocation loc = ProfileLocation.create(12, "foo");
private String doIt() {
return loc.obtain();
}
@Test
public void test_obtain() {
assertThat(doIt()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:13)");
}
@Test
public void test_add() {
loc.add(100);
}
}
@@ -5,6 +5,7 @@ import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.meta.MetaInfoManager;
import io.ebean.meta.MetaQueryPlanStatistic;
import io.ebean.meta.MetaTimedMetric;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.Customer;
@@ -137,6 +138,7 @@ public class TestCustomerFinder extends BaseTestCase {
MetaInfoManager metaInfoManager = Ebean.getDefaultServer().getMetaInfoManager();
metaInfoManager.collectQueryPlanStatistics(true);
metaInfoManager.collectTransactionStatistics(true);
List<Customer> customers = Customer.find.all();
assertThat(customers).isNotEmpty();
@@ -157,6 +159,10 @@ public class TestCustomerFinder extends BaseTestCase {
for (MetaQueryPlanStatistic planStat : planStats) {
System.out.println(planStat);
}
for (MetaTimedMetric txnTimed : metaInfoManager.collectTransactionStatistics(true)) {
System.out.println(txnTimed);
}
}
}