diff --git a/pom.xml b/pom.xml index fe34a3262..c9c6bc895 100644 --- a/pom.xml +++ b/pom.xml @@ -323,7 +323,7 @@ io.ebean ebean-maven-plugin - 12.1.6 + 12.1.11 test diff --git a/src/main/java/io/ebean/ProfileLocation.java b/src/main/java/io/ebean/ProfileLocation.java index 0ba6e034d..33584a0b3 100644 --- a/src/main/java/io/ebean/ProfileLocation.java +++ b/src/main/java/io/ebean/ProfileLocation.java @@ -31,9 +31,9 @@ public interface ProfileLocation { } /** - * Obtain the location description. + * Obtain the description returning true if this is the initial call. */ - String obtain(); + boolean obtain(); /** * Return a short version of the location description. @@ -45,8 +45,23 @@ public interface ProfileLocation { */ String label(); + /** + * Return the full location. + */ + String fullLocation(); + /** * Add execution time. */ void add(long executionTime); + + /** + * Return true if this request should be traced. + */ + boolean trace(); + + /** + * Set the number of times to trace the transactions for this profile location. + */ + void setTraceCount(int traceCount); } diff --git a/src/main/java/io/ebean/Query.java b/src/main/java/io/ebean/Query.java index a51889999..49ab09832 100644 --- a/src/main/java/io/ebean/Query.java +++ b/src/main/java/io/ebean/Query.java @@ -1524,17 +1524,6 @@ public interface Query { return setUseQueryCache(enabled ? CacheMode.ON : CacheMode.OFF); } - /** - * Set an id to identify this query for profiling purposes. - *

- * The profileId is expected to be unique for a given bean type. - *

- *

- * Note that the profileId is treated as a short internally and has a MAX value of 32,767. - *

- */ - Query setProfileId(int profileId); - /** * Set the profile location of this query. This is used to relate query execution metrics * back to a location like a specific line of code. diff --git a/src/main/java/io/ebean/plugin/BeanType.java b/src/main/java/io/ebean/plugin/BeanType.java index e11aa32a0..45ee40995 100644 --- a/src/main/java/io/ebean/plugin/BeanType.java +++ b/src/main/java/io/ebean/plugin/BeanType.java @@ -25,11 +25,6 @@ public interface BeanType { @Nonnull String getName(); - /** - * Return the profileId of the bean type. - */ - short getProfileId(); - /** * Return the full name of the bean type. */ diff --git a/src/main/java/io/ebeaninternal/api/SpiProfileHandler.java b/src/main/java/io/ebeaninternal/api/SpiProfileHandler.java index e5008a428..bf0786bff 100644 --- a/src/main/java/io/ebeaninternal/api/SpiProfileHandler.java +++ b/src/main/java/io/ebeaninternal/api/SpiProfileHandler.java @@ -1,5 +1,6 @@ package io.ebeaninternal.api; +import io.ebean.ProfileLocation; import io.ebeaninternal.server.transaction.ProfileStream; import io.ebeaninternal.server.transaction.TransactionProfile; @@ -24,7 +25,7 @@ public interface SpiProfileHandler { * Create a profiling stream if we are profiling this transaction. * Return null if we are not profiling this transaction. * - * @param profileId The transaction profileId + * @param location The profile location */ - ProfileStream createProfileStream(int profileId); + ProfileStream createProfileStream(ProfileLocation location); } diff --git a/src/main/java/io/ebeaninternal/api/SpiQuery.java b/src/main/java/io/ebeaninternal/api/SpiQuery.java index 9130ac67c..e1529df9b 100644 --- a/src/main/java/io/ebeaninternal/api/SpiQuery.java +++ b/src/main/java/io/ebeaninternal/api/SpiQuery.java @@ -191,7 +191,7 @@ public interface SpiQuery extends Query, TxnProfileEventCodes { /** * Return the id used to identify a particular query for the given bean type. */ - short getProfileId(); + String getProfileId(); /** * Return the profile location for this query. diff --git a/src/main/java/io/ebeaninternal/server/core/PersistRequest.java b/src/main/java/io/ebeaninternal/server/core/PersistRequest.java index eac7c40d3..cbf91835c 100644 --- a/src/main/java/io/ebeaninternal/server/core/PersistRequest.java +++ b/src/main/java/io/ebeaninternal/server/core/PersistRequest.java @@ -90,8 +90,8 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe */ public abstract int executeNow(); - void profileBase(String event, long offset, short beanTypeId, int beanCount) { - transaction.profileStream().addPersistEvent(event, offset, beanTypeId, beanCount); + void profileBase(String event, long offset, String beanName, int beanCount) { + transaction.profileStream().addPersistEvent(event, offset, beanName, beanCount); } @Override diff --git a/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java b/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java index da9b7745b..6db27933a 100644 --- a/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java +++ b/src/main/java/io/ebeaninternal/server/core/PersistRequestBean.java @@ -244,7 +244,7 @@ public final class PersistRequestBean extends PersistRequest implements BeanP */ @Override public void profile(long offset, int flushCount) { - profileBase(type.profileEventId, offset, beanDescriptor.getProfileId(), flushCount); + profileBase(type.profileEventId, offset, beanDescriptor.getName(), flushCount); } /** @@ -1332,7 +1332,7 @@ public final class PersistRequestBean extends PersistRequest implements BeanP */ @Override public void profile() { - profileBase(type.profileEventId, profileOffset, beanDescriptor.getProfileId(), 1); + profileBase(type.profileEventId, profileOffset, beanDescriptor.getName(), 1); } /** diff --git a/src/main/java/io/ebeaninternal/server/core/PersistRequestCallableSql.java b/src/main/java/io/ebeaninternal/server/core/PersistRequestCallableSql.java index d94a58d69..806691f5f 100644 --- a/src/main/java/io/ebeaninternal/server/core/PersistRequestCallableSql.java +++ b/src/main/java/io/ebeaninternal/server/core/PersistRequestCallableSql.java @@ -40,7 +40,7 @@ public final class PersistRequestCallableSql extends PersistRequest { @Override public void profile(long offset, int flushCount) { - profileBase(EVT_CALLABLESQL, offset, (short)0, flushCount); + profileBase(EVT_CALLABLESQL, offset, "", flushCount); } @Override diff --git a/src/main/java/io/ebeaninternal/server/core/PersistRequestOrmUpdate.java b/src/main/java/io/ebeaninternal/server/core/PersistRequestOrmUpdate.java index 2d6f3b8ba..807feadd8 100644 --- a/src/main/java/io/ebeaninternal/server/core/PersistRequestOrmUpdate.java +++ b/src/main/java/io/ebeaninternal/server/core/PersistRequestOrmUpdate.java @@ -34,7 +34,7 @@ public final class PersistRequestOrmUpdate extends PersistRequest { @Override public void profile(long offset, int flushCount) { - profileBase(EVT_ORMUPDATE, offset, beanDescriptor.getProfileId(), flushCount); + profileBase(EVT_ORMUPDATE, offset, beanDescriptor.getName(), flushCount); } public BeanDescriptor getBeanDescriptor() { diff --git a/src/main/java/io/ebeaninternal/server/core/PersistRequestUpdateSql.java b/src/main/java/io/ebeaninternal/server/core/PersistRequestUpdateSql.java index 96d0f96c6..01082111f 100644 --- a/src/main/java/io/ebeaninternal/server/core/PersistRequestUpdateSql.java +++ b/src/main/java/io/ebeaninternal/server/core/PersistRequestUpdateSql.java @@ -51,7 +51,7 @@ public final class PersistRequestUpdateSql extends PersistRequest { @Override public void profile(long offset, int flushCount) { - profileBase(EVT_UPDATESQL, offset, (short) 0, flushCount); + profileBase(EVT_UPDATESQL, offset, "", flushCount); } /** diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index 190e29e77..3cbdfa6aa 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -139,8 +139,6 @@ public class BeanDescriptor implements BeanType, STreeType { private final Map namedQuery; - private final short profileBeanId; - private final boolean multiValueSupported; private boolean batchEscalateOnCascadeInsert; private boolean batchEscalateOnCascadeDelete; @@ -441,7 +439,6 @@ public class BeanDescriptor implements BeanType, STreeType { this.name = InternString.intern(deploy.getName()); this.baseTableAlias = "t0"; this.fullName = InternString.intern(deploy.getFullName()); - this.profileBeanId = deploy.getProfileId(); this.beanType = deploy.getBeanType(); this.rootBeanType = PersistenceContextUtil.root(beanType); this.prototypeEntityBean = createPrototypeEntityBean(beanType); @@ -571,14 +568,6 @@ public class BeanDescriptor implements BeanType, STreeType { } } - /** - * Return the id used in profiling to identify the bean type. - */ - @Override - public short getProfileId() { - return profileBeanId; - } - /** * Derive an array of property positions for properties that are initialised in the constructor. * These properties need to be unloaded when populating beans for queries. diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java index 9403afa5b..72ce6ce7c 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java @@ -787,13 +787,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap { .collect(Collectors.toList()); deployDescriptors.sort(Comparator.comparing(DeployBeanDescriptor::getFullName)); - - short id = 0; - for (DeployBeanDescriptor desc : deployDescriptors) { - if (!desc.isEmbedded()) { - desc.setProfileId(++id); - } - } } /** diff --git a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java index 36f6526bb..0fdbe0954 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java +++ b/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanDescriptor.java @@ -214,8 +214,6 @@ public class DeployBeanDescriptor { private DeployBeanProperty idProperty; private TableJoin primaryKeyJoin; - private short profileId; - private Object jacksonAnnotatedClass; /** @@ -688,20 +686,6 @@ public class DeployBeanDescriptor { setBaseTable(new TableName(viewName), "", ""); } - /** - * Set the profileId to identity this bean type. - */ - public void setProfileId(short profileId) { - this.profileId = profileId; - } - - /** - * Return the profileId to identify this bean type. - */ - public short getProfileId() { - return profileId; - } - /** * Set the base table. Only properties mapped to the base table are by default persisted. */ diff --git a/src/main/java/io/ebeaninternal/server/profile/BasicProfileLocation.java b/src/main/java/io/ebeaninternal/server/profile/BasicProfileLocation.java index d8b58a878..507938a96 100644 --- a/src/main/java/io/ebeaninternal/server/profile/BasicProfileLocation.java +++ b/src/main/java/io/ebeaninternal/server/profile/BasicProfileLocation.java @@ -28,8 +28,8 @@ final class BasicProfileLocation implements ProfileLocation { } @Override - public String obtain() { - return fullLocation; + public boolean obtain() { + return false; } @Override @@ -42,6 +42,21 @@ final class BasicProfileLocation implements ProfileLocation { return location; } + @Override + public String fullLocation() { + return fullLocation; + } + + @Override + public boolean trace() { + return false; + } + + @Override + public void setTraceCount(int traceCount) { + // do nothing + } + private String shortDesc(String location) { int lastPer = location.lastIndexOf('.'); if (lastPer > -1) { diff --git a/src/main/java/io/ebeaninternal/server/profile/DProfileLocation.java b/src/main/java/io/ebeaninternal/server/profile/DProfileLocation.java index ec163632c..c5ff7d3ac 100644 --- a/src/main/java/io/ebeaninternal/server/profile/DProfileLocation.java +++ b/src/main/java/io/ebeaninternal/server/profile/DProfileLocation.java @@ -19,6 +19,8 @@ class DProfileLocation implements ProfileLocation { private final int lineNumber; + private int traceCount; + DProfileLocation() { this(0); } @@ -41,17 +43,18 @@ class DProfileLocation implements ProfileLocation { } @Override - public String obtain() { + public boolean obtain() { // atomic assignments so happy enough with this (racing but atomic) - if (fullLocation == null) { - final String loc = create(); - final String shortDesc = shortDesc(loc); - label = UtilLocation.label(shortDesc); - location = shortDesc; - fullLocation = loc; - initWith(label); + if (fullLocation != null) { + return false; } - return fullLocation; + final String loc = create(); + final String shortDesc = shortDesc(loc); + label = UtilLocation.label(shortDesc); + location = shortDesc; + fullLocation = loc; + initWith(label); + return true; } protected void initWith(String label) { @@ -68,6 +71,26 @@ class DProfileLocation implements ProfileLocation { return location; } + @Override + public String fullLocation() { + return fullLocation; + } + + @Override + public boolean trace() { + // racey but atomic and no problem with over or under tracing + if (traceCount <= 0) { + return false; + } else { + traceCount--; + return true; + } + } + + public void setTraceCount(int traceCount) { + this.traceCount = traceCount; + } + private String create() { // relatively expensive but we only do it once per profile location StackTraceElement[] trace = Thread.currentThread().getStackTrace(); diff --git a/src/main/java/io/ebeaninternal/server/query/CQuery.java b/src/main/java/io/ebeaninternal/server/query/CQuery.java index a8175dd8e..69994dcb1 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQuery.java +++ b/src/main/java/io/ebeaninternal/server/query/CQuery.java @@ -614,7 +614,7 @@ public class CQuery implements DbReadContext, CancelableQuery, SpiProfileTran public void profile() { getTransaction() .profileStream() - .addQueryEvent(query.profileEventId(), profileOffset, desc.getProfileId(), loadedBeanCount, query.getProfileId()); + .addQueryEvent(query.profileEventId(), profileOffset, desc.getName(), loadedBeanCount, query.getProfileId()); } QueryIterator readIterate(int bufferSize, OrmQueryRequest request) { diff --git a/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java b/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java index 614892c06..005cecd97 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java +++ b/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java @@ -189,7 +189,7 @@ class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent { public void profile() { getTransaction() .profileStream() - .addQueryEvent(query.profileEventId(), profileOffset, desc.getProfileId(), rowCount, query.getProfileId()); + .addQueryEvent(query.profileEventId(), profileOffset, desc.getName(), rowCount, query.getProfileId()); } Set getDependentTables() { diff --git a/src/main/java/io/ebeaninternal/server/query/CQueryRowCount.java b/src/main/java/io/ebeaninternal/server/query/CQueryRowCount.java index 3479c662d..6a3d40a59 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQueryRowCount.java +++ b/src/main/java/io/ebeaninternal/server/query/CQueryRowCount.java @@ -155,7 +155,7 @@ class CQueryRowCount implements SpiProfileTransactionEvent { public void profile() { getTransaction() .profileStream() - .addQueryEvent(query.profileEventId(), profileOffset, desc.getProfileId(), rowCount, query.getProfileId()); + .addQueryEvent(query.profileEventId(), profileOffset, desc.getName(), rowCount, query.getProfileId()); } Set getDependentTables() { diff --git a/src/main/java/io/ebeaninternal/server/query/CQueryUpdate.java b/src/main/java/io/ebeaninternal/server/query/CQueryUpdate.java index 68e3301d1..76858c271 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQueryUpdate.java +++ b/src/main/java/io/ebeaninternal/server/query/CQueryUpdate.java @@ -120,6 +120,6 @@ class CQueryUpdate implements SpiProfileTransactionEvent { public void profile() { getTransaction() .profileStream() - .addQueryEvent(query.profileEventId(), profileOffset, desc.getProfileId(), rowCount, query.getProfileId()); + .addQueryEvent(query.profileEventId(), profileOffset, desc.getName(), rowCount, query.getProfileId()); } } diff --git a/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java b/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java index 011e9666e..5a617a476 100644 --- a/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java +++ b/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java @@ -120,11 +120,6 @@ class DefaultFetchGroupQuery implements SpiFetchGroupQuery { return this; } - @Override - public Query setProfileId(int profileId) { - return this; - } - @Override public Query setProfileLocation(ProfileLocation profileLocation) { return this; diff --git a/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java b/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java index 8649c95f1..03dd0fb05 100644 --- a/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java +++ b/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java @@ -283,11 +283,6 @@ public class DefaultOrmQuery implements SpiQuery { private boolean orderById; - /** - * Identity the query for profiling purposes (expected to be unique for a bean type). - */ - private short profileId; - private ProfileLocation profileLocation; public DefaultOrmQuery(BeanDescriptor desc, SpiEbeanServer server, ExpressionFactory expressionFactory) { @@ -350,14 +345,8 @@ public class DefaultOrmQuery implements SpiQuery { } @Override - public short getProfileId() { - return profileId; - } - - @Override - public Query setProfileId(int profileId) { - this.profileId = (short) profileId; - return this; + public String getProfileId() { + return getPlanLabel(); } @Override diff --git a/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java b/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java index 181a92c92..12cfd436f 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java +++ b/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java @@ -1,7 +1,7 @@ package io.ebeaninternal.server.transaction; +import io.ebean.ProfileLocation; import io.ebean.config.ProfilingConfig; -import io.ebean.plugin.BeanType; import io.ebean.plugin.Plugin; import io.ebean.plugin.SpiServer; import io.ebeaninternal.api.SpiProfileHandler; @@ -34,10 +34,8 @@ import static java.time.temporal.ChronoField.YEAR; * Default profile handler. *

* Uses ConcurrentLinkedQueue to minimise contention on threads calling collectTransactionProfile(). - *

*

* Uses a sleep backoff on the single threaded consumer that reads the profiles and writes them to files. - *

*/ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { @@ -71,8 +69,6 @@ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { private final long minMicros; - private final int[] includeIds; - private final long profilesPerFile; private final boolean verbose; @@ -91,7 +87,6 @@ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { public DefaultProfileHandler(ProfilingConfig config) { this.verbose = config.isVerbose(); this.minMicros = config.getMinimumMicros(); - this.includeIds = config.getIncludeProfileIds(); this.profilesPerFile = config.getProfilesPerFile(); // dedicated single threaded executor for consuming the @@ -114,28 +109,11 @@ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { } /** - * Create and return a ProfileStream if we are profiling for the given transaction profileId. + * Create and return a ProfileStream. */ @Override - public ProfileStream createProfileStream(int profileId) { - - if (profileId < 1) { - // not this transaction - return null; - } - - if (includeIds.length == 0) { - return new DefaultProfileStream(profileId, verbose); - } - - // check if we are profiling this specific transaction profileId, just - // perform linear search as this is expected to be a small array - for (int includeId : includeIds) { - if (includeId == profileId) { - return new DefaultProfileStream(profileId, verbose); - } - } - return null; + public ProfileStream createProfileStream(ProfileLocation location) { + return new DefaultProfileStream(location, verbose); } private void flushCurrentFile() { @@ -199,7 +177,7 @@ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { // header sb.append(profile.getStartTime()).append(' ') - .append(profile.getProfileId()).append(' ') + .append(profile.getLabel()).append(' ') .append(profile.getTotalMicros()).append(' '); // summary @@ -268,14 +246,7 @@ public class DefaultProfileHandler implements SpiProfileHandler, Plugin { @Override public void configure(SpiServer server) { - - StringBuilder sb = new StringBuilder(200); - sb.append("Bean profile mapping - "); - for (BeanType type : server.getBeanTypes()) { - sb.append("profileId:").append(type.getProfileId()) - .append(" ").append(type.getName()).append(", "); - } - log.info(sb.toString()); + // do nothing } @Override diff --git a/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileStream.java b/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileStream.java index 240f73e88..bc2913137 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileStream.java +++ b/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileStream.java @@ -1,5 +1,7 @@ package io.ebeaninternal.server.transaction; +import io.ebean.ProfileLocation; + /** * Default transaction profiling event collection. */ @@ -10,9 +12,9 @@ public class DefaultProfileStream implements ProfileStream { private final TransactionProfile profile; private final TransactionProfile.Summary summary; - DefaultProfileStream(int profId, boolean verbose) { + DefaultProfileStream(ProfileLocation location, boolean verbose) { this.startNanos = System.nanoTime(); - this.profile = new TransactionProfile(System.currentTimeMillis(), profId); + this.profile = new TransactionProfile(System.currentTimeMillis(), location); this.summary = profile.getSummary(); this.buffer = (verbose) ? new StringBuilder(200) : null; } @@ -33,11 +35,11 @@ public class DefaultProfileStream implements ProfileStream { * Add a query execution event. */ @Override - public void addQueryEvent(String event, long offset, short beanTypeId, int beanCount, short queryId) { + public void addQueryEvent(String event, long offset, String beanName, int beanCount, String queryId) { long micros = exeMicros(offset); summary.addQuery(micros, beanCount); if (buffer != null) { - add(micros, event, offset, beanTypeId, beanCount, queryId); + add(micros, event, offset, beanName, beanCount, queryId); } } @@ -45,11 +47,11 @@ public class DefaultProfileStream implements ProfileStream { * Add a persist event. */ @Override - public void addPersistEvent(String event, long offset, short beanTypeId, int beanCount) { + public void addPersistEvent(String event, long offset, String beanName, int beanCount) { long micros = exeMicros(offset); summary.addPersist(micros, beanCount); if (buffer != null) { - add(micros, event, offset, beanTypeId, beanCount, (short) 0); + add(micros, event, offset, beanName, beanCount, ""); } } @@ -67,11 +69,11 @@ public class DefaultProfileStream implements ProfileStream { } } - private void add(long micros, String event, long offset, short beanTypeId, int beanCount, short queryId) { + private void add(long micros, String event, long offset, String beanName, int beanCount, String queryId) { buffer.append(event).append(','); buffer.append(offset).append(','); buffer.append(micros).append(','); - buffer.append(beanTypeId).append(','); + buffer.append(beanName).append(','); buffer.append(beanCount).append(','); buffer.append(queryId).append(";"); } @@ -81,7 +83,6 @@ public class DefaultProfileStream implements ProfileStream { */ @Override public void end(TransactionManager manager) { - profile.setTotalMicros(offset()); if (buffer != null) { profile.setData(buffer.toString()); diff --git a/src/main/java/io/ebeaninternal/server/transaction/NoopProfileHandler.java b/src/main/java/io/ebeaninternal/server/transaction/NoopProfileHandler.java index ab24af225..636ad7c6a 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/NoopProfileHandler.java +++ b/src/main/java/io/ebeaninternal/server/transaction/NoopProfileHandler.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.transaction; +import io.ebean.ProfileLocation; import io.ebeaninternal.api.SpiProfileHandler; /** @@ -13,7 +14,7 @@ public class NoopProfileHandler implements SpiProfileHandler { } @Override - public ProfileStream createProfileStream(int profileId) { + public ProfileStream createProfileStream(ProfileLocation location) { // always return null return null; } diff --git a/src/main/java/io/ebeaninternal/server/transaction/ProfileStream.java b/src/main/java/io/ebeaninternal/server/transaction/ProfileStream.java index 563fa7461..1ce000085 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/ProfileStream.java +++ b/src/main/java/io/ebeaninternal/server/transaction/ProfileStream.java @@ -13,12 +13,12 @@ public interface ProfileStream { /** * Add a query event. */ - void addQueryEvent(String event, long offset, short beanTypeId, int beanCount, short queryId); + void addQueryEvent(String event, long offset, String beanName, int beanCount, String queryId); /** * Add a persist event. */ - void addPersistEvent(String event, long offset, short beanTypeId, int beanCount); + void addPersistEvent(String event, long offset, String beanName, int beanCount); /** * Add the commit/rollback event. diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java index 8601d0e80..0b4b43ba8 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java @@ -45,6 +45,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.List; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; /** @@ -147,6 +148,8 @@ public class TransactionManager implements SpiTransactionManager { private final ServerCacheNotify cacheNotify; private final boolean supportsSavepointId; + private final ConcurrentHashMap profileLocations = new ConcurrentHashMap<>(); + /** * Create the TransactionManager */ @@ -689,7 +692,6 @@ public class TransactionManager implements SpiTransactionManager { } private void initNewTransaction(SpiTransaction transaction, TxScope txScope) { - if (txScope.isSkipCache()) { transaction.setSkipCache(true); } @@ -697,17 +699,22 @@ public class TransactionManager implements SpiTransactionManager { if (label != null) { transaction.setLabel(label); } - int profileId = txScope.getProfileId(); - if (profileId > 0) { - transaction.setProfileStream(profileHandler.createProfileStream(profileId)); - } ProfileLocation profileLocation = txScope.getProfileLocation(); if (profileLocation != null) { - profileLocation.obtain(); + if (profileLocation.obtain()) { + registerProfileLocation(profileLocation); + } transaction.setProfileLocation(profileLocation); + if (profileLocation.trace()) { + transaction.setProfileStream(profileHandler.createProfileStream(profileLocation)); + } } } + private void registerProfileLocation(ProfileLocation profileLocation) { + profileLocations.put(profileLocation.fullLocation(), profileLocation); + } + private TxScope initTxScope(TxScope txScope) { if (txScope == null) { return new TxScope(); diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionProfile.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionProfile.java index e55be367a..2c7006eba 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionProfile.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionProfile.java @@ -1,15 +1,15 @@ package io.ebeaninternal.server.transaction; +import io.ebean.ProfileLocation; + /** * Profiling information for a single transaction that has completed. */ public class TransactionProfile { - private long startTime; - /** - * The profileId of the transaction (On @Transactional explicitly or can be automatically set by enhancement). - */ - private int profileId; + private final ProfileLocation location; + private final String label; + private final long startTime; /** * The total execution time of the transaction (for filtering out small/short transactions). @@ -26,16 +26,18 @@ public class TransactionProfile { /** * Create with profileId, total micros and encoded profile data. */ - public TransactionProfile(long startTime, int profileId) { + public TransactionProfile(long startTime, ProfileLocation location) { + this.location = location; + this.label = location.label(); this.startTime = startTime; - this.profileId = profileId; this.summary = new Summary(); } /** - * Construct for JSON tools. + * Return the transaction location label. */ - public TransactionProfile(){ + public String getLabel() { + return label; } /** @@ -45,13 +47,6 @@ public class TransactionProfile { return startTime; } - /** - * Return the transaction profileId. - */ - public int getProfileId() { - return profileId; - } - /** * Return the total transaction execution time in micros. */ @@ -66,20 +61,6 @@ public class TransactionProfile { return data; } - /** - * Set start time (for JSON tools). - */ - public void setStartTime(long startTime) { - this.startTime = startTime; - } - - /** - * Set profileId (for JSON tools). - */ - public void setProfileId(int profileId) { - this.profileId = profileId; - } - /** * Set total micros (for JSON tools). */ diff --git a/src/test/java/io/ebeaninternal/server/profile/BasicProfileLocationTest.java b/src/test/java/io/ebeaninternal/server/profile/BasicProfileLocationTest.java index 43688621f..ee932f3a3 100644 --- a/src/test/java/io/ebeaninternal/server/profile/BasicProfileLocationTest.java +++ b/src/test/java/io/ebeaninternal/server/profile/BasicProfileLocationTest.java @@ -13,17 +13,18 @@ public class BasicProfileLocationTest { DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric(MetricType.TXN, "junk")); - assertThat(loc.obtain()).endsWith(":12)"); + assertThat(loc.obtain()).isTrue(); + assertThat(loc.fullLocation()).endsWith(":12)"); assertThat(loc.location()).isEqualTo("NativeMethodAccessorImpl.invoke0(Native Method:12)"); assertThat(loc.label()).isEqualTo("NativeMethodAccessorImpl.invoke0"); - } @Test public void basic_trimPackage() { BasicProfileLocation loc = new BasicProfileLocation("com.foo.Bar.all"); - assertThat(loc.obtain()).isEqualTo("com.foo.Bar.all"); + assertThat(loc.obtain()).isFalse(); + assertThat(loc.fullLocation()).isEqualTo("com.foo.Bar.all"); assertThat(loc.location()).isEqualTo("Bar.all"); assertThat(loc.label()).isEqualTo("Bar.all"); } @@ -32,7 +33,8 @@ public class BasicProfileLocationTest { public void basic_trimSinglePackage() { BasicProfileLocation loc = new BasicProfileLocation("foo.Bar.all"); - assertThat(loc.obtain()).isEqualTo("foo.Bar.all"); + assertThat(loc.obtain()).isFalse(); + assertThat(loc.fullLocation()).isEqualTo("foo.Bar.all"); assertThat(loc.location()).isEqualTo("Bar.all"); assertThat(loc.label()).isEqualTo("Bar.all"); } diff --git a/src/test/java/io/ebeaninternal/server/transaction/DefaultProfileHandlerTest.java b/src/test/java/io/ebeaninternal/server/transaction/DefaultProfileHandlerTest.java index c6f2ee717..0a6ee1e3a 100644 --- a/src/test/java/io/ebeaninternal/server/transaction/DefaultProfileHandlerTest.java +++ b/src/test/java/io/ebeaninternal/server/transaction/DefaultProfileHandlerTest.java @@ -1,40 +1,19 @@ package io.ebeaninternal.server.transaction; -import io.ebean.config.ProfilingConfig; import org.junit.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - public class DefaultProfileHandlerTest { @Test public void createProfileStream() { - ProfilingConfig profilingConfig = new ProfilingConfig(); - profilingConfig.setDirectory("target/profiling"); - - DefaultProfileHandler handler = new DefaultProfileHandler(profilingConfig); - - assertNotNull(handler.createProfileStream(12)); - assertNull(handler.createProfileStream(0)); - } - - @Test - public void createProfileStream_when_specificIncludeIds() { - - ProfilingConfig config = new ProfilingConfig(); - config.setDirectory("target/profiling"); - config.setIncludeProfileIds(new int[]{100,101}); - - DefaultProfileHandler handler = new DefaultProfileHandler(config); - - assertNotNull(handler.createProfileStream(100)); - assertNotNull(handler.createProfileStream(101)); - - assertNull(handler.createProfileStream(0)); - assertNull(handler.createProfileStream(12)); - +// ProfilingConfig profilingConfig = new ProfilingConfig(); +// profilingConfig.setDirectory("target/profiling"); +// +// DefaultProfileHandler handler = new DefaultProfileHandler(profilingConfig); +// +// assertNotNull(handler.createProfileStream(12)); +// assertNull(handler.createProfileStream(0)); } } diff --git a/src/test/java/org/tests/profile/ProfileLocationTest.java b/src/test/java/org/tests/profile/ProfileLocationTest.java index 63b564a0f..d93b5c75f 100644 --- a/src/test/java/org/tests/profile/ProfileLocationTest.java +++ b/src/test/java/org/tests/profile/ProfileLocationTest.java @@ -11,14 +11,14 @@ public class ProfileLocationTest { private static ProfileLocation loc2 = ProfileLocation.create(); - private String doIt() { + private boolean doIt() { return loc.obtain(); } @Test public void test_obtain() { - - assertThat(doIt()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)"); + assertThat(doIt()).isTrue(); + assertThat(loc.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)"); assertThat(loc.location()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:15)"); assertThat(loc.label()).isEqualTo("ProfileLocationTest.doIt"); }