private long doCommand(DatabaseType dbtype, Connection conn, String command, String table) { Statement stmt = null; StopWatch watch = new StopWatch(); if (table == null) { table = ""; } command = command.replace("{0}", table); if (LOG.isDebugEnabled()) { LOG.debug("Execute command: " + command); } try { stmt = conn.createStatement(); stmt.execute(command); return watch.getElapsed(); } catch (SQLException e) { LOG.error("Error in command: " + command + ": " + e, e); return watch.getElapsed(); } finally { dbtype.closeStatement(stmt); } }
public StopWatch() { reset(); }
public String toString() { final long elap = this.getElapsed(); final StringBuffer buf = new StringBuffer(formatMillis(elap)); if (markerMap.size() > 0) { buf.append(" {StopWatch Markers:\n"); long totalMarked = 0; TreeSet<String> keys = new TreeSet<String>(markerMap.keySet()); for (String key : keys) { TimeSlice ts = markerMap.get(key); totalMarked += (ts.end - ts.begin); ts.writeBuf(buf); buf.append('\n'); } long unmarked = elap - totalMarked; if (unmarked > 99) { // only show if the value is substantial buf.append(" [unmarked=").append(formatMillis(unmarked)).append("]\n"); } buf.append("}"); } return buf.toString(); }
StopWatch watch = new StopWatch(); try { conn = dataSource.getConnection(); insStmt.setLong(3, end); watch.reset(); rows = insStmt.executeUpdate(); + (watch.getElapsed() / SECOND) + "] seconds");
final StopWatch stopWatch = new StopWatch(); String marker = null; Map<Integer, Resource> resourceMap = new HashMap<Integer, Resource>(resourceIdList.size()); markerPrefix = String.format("a. Batch [%03d] (%d): ", batchNumber, syncInfos.size()); marker = String.format("%sGet resource ID sublist - %d of %d remaining", markerPrefix, end, size); stopWatch.markTimeBegin(marker); stopWatch.markTimeEnd(marker); stopWatch.markTimeBegin(marker); stopWatch.markTimeEnd(marker); stopWatch.markTimeBegin(marker); stopWatch.markTimeEnd(marker); stopWatch.markTimeBegin(marker); stopWatch.markTimeEnd(marker);
public long reset() { try { return this.getElapsed(); } finally { start = System.currentTimeMillis(); markerMap = new HashMap<String, TimeSlice>(); } }
int reportSize = report.getResourceAvailability().size(); String agentName = report.getAgentName(); StopWatch watch = new StopWatch(); MeasurementMonitor.getMBean().incrementAvailabilityInsertTime(watch.getElapsed()); watch.reset();
@Override @TransactionAttribute(REQUIRES_NEW) public void purgeByDriftDefinitionName(Subject subject, int resourceId, String driftDefName) throws Exception { int driftsDeleted; int changeSetsDeleted; StopWatch timer = new StopWatch(); // purge all drift entities first Query q = entityManager.createNamedQuery(JPADrift.QUERY_DELETE_BY_DRIFTDEF_RESOURCE); q.setParameter("resourceId", resourceId); q.setParameter("driftDefinitionName", driftDefName); driftsDeleted = q.executeUpdate(); // delete the drift set // JPADriftChangeSet changeSet = entityManager.createQuery( // "select c from JPADriftChangeSet c where c.version = 0 and c.driftDefinition") // now purge all changesets q = entityManager.createNamedQuery(JPADriftChangeSet.QUERY_DELETE_BY_DRIFTDEF_RESOURCE); q.setParameter("resourceId", resourceId); q.setParameter("driftDefinitionName", driftDefName); changeSetsDeleted = q.executeUpdate(); LOG.info("Purged [" + driftsDeleted + "] drift items and [" + changeSetsDeleted + "] changesets associated with drift def [" + driftDefName + "] from resource [" + resourceId + "]. Elapsed time=[" + timer.getElapsed() + "]ms"); }
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void truncateMeasurements(String tableName) throws SQLException { // Make sure we only truncate the dead table... other tables may have live data in them if (tableName.equals(MeasurementDataManagerUtility.getDeadTable(System.currentTimeMillis()))) { Connection conn = null; Statement stmt = null; StopWatch watch = new StopWatch(); try { conn = dataSource.getConnection(); stmt = conn.createStatement(); long startTime = System.currentTimeMillis(); stmt.executeUpdate("TRUNCATE TABLE " + tableName); MeasurementMonitor.getMBean().incrementPurgeTime(System.currentTimeMillis() - startTime); } finally { JDBCUtil.safeClose(conn, stmt, null); log.info("Truncated table [" + tableName + "] in [" + (watch.getElapsed() / SECOND) + "] seconds"); } } } }
/** * Purge data older than a given time. */ // 60 minute timeout @TransactionTimeout(60 * 60) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public int purgeMeasurementInterval(String tableName, long purgeAfter, long purgeBefore) throws SQLException { Connection conn = null; PreparedStatement stmt = null; log.info("Begin purging data from table [" + tableName + "] between [" + TimeUtil.toString(purgeAfter) + "] and [" + TimeUtil.toString(purgeBefore) + "]"); StopWatch watch = new StopWatch(); int rows; try { conn = dataSource.getConnection(); String sql = "DELETE FROM " + tableName + " WHERE time_stamp >= ? AND time_stamp < ?"; stmt = conn.prepareStatement(sql); stmt.setLong(1, purgeAfter); stmt.setLong(2, purgeBefore); rows = stmt.executeUpdate(); } finally { JDBCUtil.safeClose(conn, stmt, null); } MeasurementMonitor.getMBean().incrementPurgeTime(watch.getElapsed()); log.info("Finished purging data from table [" + tableName + "] between [" + TimeUtil.toString(purgeAfter) + "] and [" + TimeUtil.toString(purgeBefore) + "], [" + rows + "] rows removed in [" + ((watch.getElapsed()) / SECOND) + "] seconds"); return rows; }