Package com.mysql.jdbc.profiler

Examples of com.mysql.jdbc.profiler.ProfilerEvent


            mesgBuf.append(this.originalSql);
            mesgBuf.append("\n\n with parameters bound:\n\n");
            mesgBuf.append(asSql(true));

            this.eventSink
                .consumeEvent(new ProfilerEvent(
                    ProfilerEvent.TYPE_SLOW_QUERY,
                    "", this.currentCatalog, this.connection.getId(), //$NON-NLS-1$
                    getId(), 0, System.currentTimeMillis(),
                    elapsedTime, mysql
                        .getQueryTimingUnits(), null,
                        LogUtils.findCallingClassAndMethod(new Throwable()), mesgBuf.toString()));
          }

          if (gatherPerformanceMetrics) {
            this.connection.registerQueryExecutionTime(elapsedTime);
          }
        }

        this.connection.incrementNumberOfPreparedExecutes();

        if (this.profileSQL) {
          this.eventSink = ProfilerEventHandlerFactory
              .getInstance(this.connection);

          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_EXECUTE,
              "", this.currentCatalog, //$NON-NLS-1$
              this.connectionId, this.statementId, -1, System
                  .currentTimeMillis(), mysql
                  .getCurrentTimeNanosOrMillis() - begin,
              mysql.getQueryTimingUnits(), null, LogUtils.findCallingClassAndMethod(new Throwable()),
              truncateQueryToLog(asSql(true))));
        }
 
        com.mysql.jdbc.ResultSetInternalMethods rs = mysql.readAllResults(this,
            maxRowsToRetrieve, this.resultSetType,
            this.resultSetConcurrency, createStreamingResultSet,
            this.currentCatalog, resultPacket, true, this.fieldCount,
            metadataFromCache);
       
        if (mysql.shouldIntercept()) {
          ResultSetInternalMethods interceptedResults =
              mysql.invokeStatementInterceptorsPost(this.originalSql, this, rs, true, null);
   
            if (interceptedResults != null) {
              rs = interceptedResults;
            }
        }
       
        if (this.profileSQL) {
          long fetchEndTime = mysql.getCurrentTimeNanosOrMillis();

          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_FETCH,
              "", this.currentCatalog, this.connection.getId(), //$NON-NLS-1$
              getId(), 0 /* FIXME rs.resultId */, System.currentTimeMillis(),
              (fetchEndTime - queryEndTime), mysql
                  .getQueryTimingUnits(), null,
View Full Code Here


        }

        this.connection.incrementNumberOfPrepares();

        if (this.profileSQL) {
          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_PREPARE,
              "", this.currentCatalog, //$NON-NLS-1$
              this.connectionId, this.statementId, -1,
              System.currentTimeMillis(),
              mysql.getCurrentTimeNanosOrMillis() - begin,
View Full Code Here

      Object possibleProfilerEvent) {

    if (possibleProfilerEvent instanceof ProfilerEvent) {
      StringBuffer msgBuf = new StringBuffer();

      ProfilerEvent evt = (ProfilerEvent) possibleProfilerEvent;

      Throwable locationException = evt.getEventCreationPoint();

      if (locationException == null) {
        locationException = new Throwable();
      }

      msgBuf.append("Profiler Event: [");

      boolean appendLocationInfo = false;
     
      switch (evt.getEventType()) {
      case ProfilerEvent.TYPE_EXECUTE:
        msgBuf.append("EXECUTE");

        break;

      case ProfilerEvent.TYPE_FETCH:
        msgBuf.append("FETCH");

        break;

      case ProfilerEvent.TYPE_OBJECT_CREATION:
        msgBuf.append("CONSTRUCT");

        break;

      case ProfilerEvent.TYPE_PREPARE:
        msgBuf.append("PREPARE");

        break;

      case ProfilerEvent.TYPE_QUERY:
        msgBuf.append("QUERY");

        break;

      case ProfilerEvent.TYPE_WARN:
        msgBuf.append("WARN");
        appendLocationInfo = true;
       
        break;
       
      case ProfilerEvent.TYPE_SLOW_QUERY:
        msgBuf.append("SLOW QUERY");
        appendLocationInfo = false;
       
        break;
       
      default:
        msgBuf.append("UNKNOWN");
      }

      msgBuf.append("] ");
      msgBuf.append(findCallingClassAndMethod(locationException));
      msgBuf.append(" duration: ");
      msgBuf.append(evt.getEventDuration());
      msgBuf.append(" ");
      msgBuf.append(evt.getDurationUnits());
      msgBuf.append(", connection-id: ");
      msgBuf.append(evt.getConnectionId());
      msgBuf.append(", statement-id: ");
      msgBuf.append(evt.getStatementId());
      msgBuf.append(", resultset-id: ");
      msgBuf.append(evt.getResultSetId());

      String evtMessage = evt.getMessage();

      if (evtMessage != null) {
        msgBuf.append(", message: ");
        msgBuf.append(evtMessage);
      }
View Full Code Here

              new Long(queryEndTime - queryStartTime)}));
          mesgBuf.append(profileQueryToLog);

          ProfilerEventHandler eventSink = ProfilerEventHandlerFactory.getInstance(this.connection);

          eventSink.consumeEvent(new ProfilerEvent(ProfilerEvent.TYPE_SLOW_QUERY,
              "", catalog, this.connection.getId(), //$NON-NLS-1$
              (callingStatement != null) ? callingStatement.getId() : 999,
                  ((ResultSetImpl)rs).resultId, System.currentTimeMillis(),
                  (int) (queryEndTime - queryStartTime), queryTimingUnits, null,
                  new Throwable(), mesgBuf.toString()));

          if (this.connection.getExplainSlowQueries()) {
            if (oldPacketPosition < MAX_QUERY_SIZE_TO_EXPLAIN) {
              explainSlowQuery(queryPacket.getBytes(5,
                  (oldPacketPosition - 5)), profileQueryToLog);
            } else {
              this.connection.getLog().logWarn(Messages.getString(
                  "MysqlIO.28") //$NON-NLS-1$
                  +MAX_QUERY_SIZE_TO_EXPLAIN +
                  Messages.getString("MysqlIO.29")); //$NON-NLS-1$
            }
          }
        }

        if (this.logSlowQueries) {

          ProfilerEventHandler eventSink = ProfilerEventHandlerFactory.getInstance(this.connection);

          if (this.queryBadIndexUsed) {
            eventSink.consumeEvent(new ProfilerEvent(
                ProfilerEvent.TYPE_SLOW_QUERY, "", catalog, //$NON-NLS-1$
                this.connection.getId(),
                (callingStatement != null) ? callingStatement.getId()
                    : 999, ((ResultSetImpl)rs).resultId,
                    System.currentTimeMillis(),
                    (queryEndTime - queryStartTime), this.queryTimingUnits,
                    null,
                    new Throwable(),
                    Messages.getString("MysqlIO.33") //$NON-NLS-1$
                    +profileQueryToLog));
          }

          if (this.queryNoIndexUsed) {
            eventSink.consumeEvent(new ProfilerEvent(
                ProfilerEvent.TYPE_SLOW_QUERY, "", catalog, //$NON-NLS-1$
                this.connection.getId(),
                (callingStatement != null) ? callingStatement.getId()
                    : 999, ((ResultSetImpl)rs).resultId,
                    System.currentTimeMillis(),
                    (queryEndTime - queryStartTime), this.queryTimingUnits,
                    null,
                    new Throwable(),
                    Messages.getString("MysqlIO.35") //$NON-NLS-1$
                    +profileQueryToLog));
          }
         
          if (this.serverQueryWasSlow) {
            eventSink.consumeEvent(new ProfilerEvent(
                ProfilerEvent.TYPE_SLOW_QUERY, "", catalog, //$NON-NLS-1$
                this.connection.getId(),
                (callingStatement != null) ? callingStatement.getId()
                    : 999, ((ResultSetImpl)rs).resultId,
                    System.currentTimeMillis(),
                    (queryEndTime - queryStartTime), this.queryTimingUnits,
                    null,
                    new Throwable(),
                    Messages.getString("MysqlIO.ServerSlowQuery") //$NON-NLS-1$
                    +profileQueryToLog));
          }
        }

        if (this.profileSql) {
          fetchEndTime = getCurrentTimeNanosOrMillis();

          ProfilerEventHandler eventSink = ProfilerEventHandlerFactory.getInstance(this.connection);

          eventSink.consumeEvent(new ProfilerEvent(ProfilerEvent.TYPE_QUERY,
              "", catalog, this.connection.getId(), //$NON-NLS-1$
              (callingStatement != null) ? callingStatement.getId() : 999,
                  ((ResultSetImpl)rs).resultId, System.currentTimeMillis(),
                  (queryEndTime - queryStartTime), this.queryTimingUnits,
                  null,
                  new Throwable(), profileQueryToLog));

          eventSink.consumeEvent(new ProfilerEvent(ProfilerEvent.TYPE_FETCH,
              "", catalog, this.connection.getId(), //$NON-NLS-1$
              (callingStatement != null) ? callingStatement.getId() : 999,
                  ((ResultSetImpl)rs).resultId, System.currentTimeMillis(),
                  (fetchEndTime - fetchBeginTime), this.queryTimingUnits,
                  null,
View Full Code Here

    if (this.useUsageAdvisor) {
      if (!calledExplicitly) {
        String message = Messages.getString("Statement.63") //$NON-NLS-1$
            + Messages.getString("Statement.64"); //$NON-NLS-1$

        this.eventSink.consumeEvent(new ProfilerEvent(
            ProfilerEvent.TYPE_WARN,
            "", //$NON-NLS-1$
            this.currentCatalog, this.connectionId, this.getId(),
            -1, System.currentTimeMillis(), 0,
            Constants.MILLIS_I18N, null, this.pointOfOrigin,
View Full Code Here

      boolean closeOpenResults) throws SQLException {
    if (this.useUsageAdvisor) {
      if (this.numberOfExecutions <= 1) {
        String message = Messages.getString("PreparedStatement.43"); //$NON-NLS-1$

        this.eventSink.consumeEvent(new ProfilerEvent(
            ProfilerEvent.TYPE_WARN, "", this.currentCatalog, //$NON-NLS-1$
            this.connectionId, this.getId(), -1, System
                .currentTimeMillis(), 0, Constants.MILLIS_I18N,
                null,
            this.pointOfOrigin, message));
View Full Code Here

          && (this.refresher == null) && (this.updater == null)) {
        this.eventSink = ProfilerEventHandlerFactory.getInstance(this.connection);

        String message = Messages.getString("UpdatableResultSet.34"); //$NON-NLS-1$

        this.eventSink.consumeEvent(new ProfilerEvent(
            ProfilerEvent.TYPE_WARN,
            "", //$NON-NLS-1$
            (this.owningStatement == null) ? "N/A" //$NON-NLS-1$
                : this.owningStatement.currentCatalog, //$NON-NLS-1$
            this.connectionId,
View Full Code Here

            mesgBuf.append(this.originalSql);
            mesgBuf.append("\n\n with parameters bound:\n\n");
            mesgBuf.append(asSql(true));

            this.eventSink
                .consumeEvent(new ProfilerEvent(
                    ProfilerEvent.TYPE_SLOW_QUERY,
                    "", this.currentCatalog, this.connection.getId(), //$NON-NLS-1$
                    getId(), 0, System.currentTimeMillis(),
                    elapsedTime, mysql
                        .getQueryTimingUnits(), null,
                    new Throwable(), mesgBuf.toString()));
          }

          if (gatherPerformanceMetrics) {
            this.connection.registerQueryExecutionTime(elapsedTime);
          }
        }

        this.connection.incrementNumberOfPreparedExecutes();

        if (this.profileSQL) {
          this.eventSink = ProfilerEventHandlerFactory
              .getInstance(this.connection);

          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_EXECUTE,
              "", this.currentCatalog, //$NON-NLS-1$
              this.connectionId, this.statementId, -1, System
                  .currentTimeMillis(), (int) (mysql
                  .getCurrentTimeNanosOrMillis() - begin),
              mysql.getQueryTimingUnits(), null, new Throwable(),
              truncateQueryToLog(asSql(true))));
        }
 
        com.mysql.jdbc.ResultSetInternalMethods rs = mysql.readAllResults(this,
            maxRowsToRetrieve, this.resultSetType,
            this.resultSetConcurrency, createStreamingResultSet,
            this.currentCatalog, resultPacket, true, this.fieldCount,
            metadataFromCache);
       
        if (this.profileSQL) {
          long fetchEndTime = mysql.getCurrentTimeNanosOrMillis();

          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_FETCH,
              "", this.currentCatalog, this.connection.getId(), //$NON-NLS-1$
              getId(), 0 /* FIXME rs.resultId */, System.currentTimeMillis(),
              (fetchEndTime - queryEndTime), mysql
                  .getQueryTimingUnits(), null,
View Full Code Here

        }

        this.connection.incrementNumberOfPrepares();

        if (this.profileSQL) {
          this.eventSink.consumeEvent(new ProfilerEvent(
              ProfilerEvent.TYPE_PREPARE,
              "", this.currentCatalog, //$NON-NLS-1$
              this.connectionId, this.statementId, -1,
              System.currentTimeMillis(),
              mysql.getCurrentTimeNanosOrMillis() - begin,
View Full Code Here

        if (getUseUsageAdvisor()) {
          if (!calledExplicitly) {
            String message = "Connection implicitly closed by Driver. You should call Connection.close() from your code to free resources more efficiently and avoid resource leaks.";

            this.eventSink.consumeEvent(new ProfilerEvent(
                ProfilerEvent.TYPE_WARN, "", //$NON-NLS-1$
                this.getCatalog(), this.getId(), -1, -1, System
                    .currentTimeMillis(), 0, Constants.MILLIS_I18N,
                    null,
                this.pointOfOrigin, message));
          }

          long connectionLifeTime = System.currentTimeMillis()
              - this.connectionCreationTimeMillis;

          if (connectionLifeTime < 500) {
            String message = "Connection lifetime of < .5 seconds. You might be un-necessarily creating short-lived connections and should investigate connection pooling to be more efficient.";

            this.eventSink.consumeEvent(new ProfilerEvent(
                ProfilerEvent.TYPE_WARN, "", //$NON-NLS-1$
                this.getCatalog(), this.getId(), -1, -1, System
                    .currentTimeMillis(), 0, Constants.MILLIS_I18N,
                    null,
                this.pointOfOrigin, message));
View Full Code Here

TOP

Related Classes of com.mysql.jdbc.profiler.ProfilerEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.