@Override public int[] executeBatch() throws SQLException { Watch w = Watch.start(); try (Operation op = new Operation(() -> "executeBatch: " + preparedSQL, Duration.ofSeconds(30))) { int[] result = delegate.executeBatch(); w.submitMicroTiming("BATCH-SQL", preparedSQL); Databases.numQueries.inc(); Databases.queryDuration.addValue(w.elapsedMillis()); if (w.elapsedMillis() > Databases.getLogQueryThresholdMillis()) { Databases.numSlowQueries.inc(); DB.SLOW_DB_LOG.INFO("A slow JDBC batch query was executed (%s): %s (%s rows)\n%s", w.duration(), preparedSQL, result.length, ExecutionPoint.snapshot().toString()); } return result; } }
Watch wt = new Watch(); String name = InputHelper.getInput("Enter name: "); String serial = InputHelper.getInput("Enter serial: "); long sr = Long.parseLong(serial); wt.addWatch(name, sr, desc, color, pr, wg); // this is a method inside Watch class that is responsible for adding watch information watchStore.add(wt); if(w.getSerial() == serial) { System.out.print("found"); return w;
/** * Returns the number of millis since the last call to <tt>reset</tt> or <tt>start</tt>. * * @return returns the number of milliseconds since the start of this watch. */ public long elapsedMillis() { return elapsed(TimeUnit.MILLISECONDS, false); }
public void addWatches(){ String name = InputHelper.getInput("Enter name: "); String serial = InputHelper.getInput("Enter serial: "); String desc = InputHelper.getInput("Enter description: "); String color = InputHelper.getInput("Enter Color: "); String price = InputHelper.getInput("Enter price: "); String weight = InputHelper.getInput("Enter weight: "); double pr = Double.parseDouble(price); double wg = Double.parseDouble(weight); long sr = Long.parseLong(serial); Watch wt = new Watch(); wt.addWatch(name, sr, desc, color, pr, wg); // this is a method inside Watch class that is responsible for adding watch information watchStore.add(wt); }
private void handleTracingAndReporting(String collection, Watch w) { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "FIND ALL - " + collection + ": " + filterObject); } traceIfRequired(collection, w); }
/** * Executes one or more Redis commands and returns a value of the given type. * * @param description a description of the actions performed used for debugging and tracing * @param task the actual task to perform using redis * @param <T> the generic type of the result * @return a result computed by <tt>task</tt> */ public <T> T query(Supplier<String> description, Function<Jedis, T> task) { Watch w = Watch.start(); try (Operation op = new Operation(description, Duration.ofSeconds(10)); Jedis redis = getConnection()) { return task.apply(redis); } catch (Exception e) { throw Exceptions.handle(Redis.LOG, e); } finally { redisInstance.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("redis", description.get()); } } }
/** * Executes the query as update. * <p> * Requires the SQL statement to be an UPDATE or DELETE statement. * * @return the number of rows changed * @throws SQLException in case of a database error */ public int executeUpdate() throws SQLException { Watch w = Watch.start(); try (Connection c = ds.getConnection()) { try (PreparedStatement stmt = createPreparedStatement(c)) { if (stmt == null) { return 0; } return stmt.executeUpdate(); } } finally { w.submitMicroTiming(MICROTIMING_KEY, sql); } }
@Override public void iterate(Function<Row, Boolean> handler, @Nullable Limit limit) throws SQLException { Watch w = Watch.start(); try (ResultSet rs = query.prepareStmt().executeQuery()) { query.avarage.addValue(w.elapsedMillis()); TaskContext tc = TaskContext.get(); processResultSet(handler, limit, rs, tc); } }
protected void updateStatistics(String sql, Watch w) { w.submitMicroTiming("SQL", sql); Databases.numQueries.inc(); Databases.queryDuration.addValue(w.elapsedMillis()); if (w.elapsedMillis() > Databases.getLogQueryThresholdMillis()) { Databases.numSlowQueries.inc(); DB.SLOW_DB_LOG.INFO("A slow JDBC query was executed (%s): %s\n%s", w.duration(), sql, ExecutionPoint.snapshot().toString()); } }
@Override public ResultSet executeQuery(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.executeQuery(sql); } finally { updateStatistics(sql, w); } }
private void createIndices(MongoDatabase db) { for (IndexDescription idx : indexDescriptions) { Watch w = Watch.start(); try { LOG.INFO("Creating indices in Mongo DB: %s", idx.getClass().getName()); idx.createIndices(db); LOG.INFO("Completed indices for: %s (%s)", idx.getClass().getName(), w.duration()); } catch (Exception t) { Exceptions.handle() .to(LOG) .error(t) .withSystemErrorMessage("Error while creating indices for '%s': %s (%s)", idx.getClass().getName()) .handle(); } } }
/** * Boilerplate method for calling <tt>duration(false)</tt> * * @return a string representation as generated by {@link #duration(boolean)} */ public String duration() { return duration(false); }
protected void traceIfRequired(String collection, Watch w) { if (mongo.tracing && w.elapsedMillis() >= mongo.traceLimit) { String location = determineLocation(); Doc explanation = explain(collection); mongo.traceData.put(location, Tuple.create(collection + ": " + filterObject.toString() + " [" + w.duration() + "]", explanation.toString())); } if (w.elapsedMillis() > mongo.getLogQueryThresholdMillis()) { mongo.numSlowQueries.inc(); DB.SLOW_DB_LOG.INFO("A slow MongoDB query was executed (%s): %s\n%s\n%s", w.duration(), collection, filterObject, ExecutionPoint.snapshot().toString()); } }
private void executeTask(final TimedTask task) { tasks.executor(TIMER) .dropOnOverload(() -> Exceptions.handle() .to(LOG) .withSystemErrorMessage( "Dropping timer task '%s' (%s) due to system overload!", task, task.getClass()) .handle()) .start(() -> { try { Watch w = Watch.start(); task.runTimer(); if (w.elapsed(TimeUnit.SECONDS, false) > 1) { LOG.WARN("TimedTask '%s' (%s) took over a second to complete! " + "Consider executing the work in a separate executor!", task, task.getClass()); } } catch (Exception t) { Exceptions.handle(LOG, t); } }); }
/** * Creates and starts a new watch. * * @return a new watch, started with the invocation of this method. */ public static Watch start() { return new Watch(); }
private void fixMDC() { if (logger.isDebugEnabled() || Sirius.isDev() || Sirius.isStartedAsTest()) { CallContext callContext = CallContext.getCurrent(); MDC.put("flow", "|" + callContext.getWatch().elapsedMillis() + "ms"); } }
/** * Counts the number of documents in the result of the given query. * <p> * Note that limits are ignored for this query. * * @param collection the collection to search in * @return the number of documents found */ public long countIn(String collection) { Watch w = Watch.start(); try { return mongo.db().getCollection(collection).count(filterObject); } finally { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "COUNT - " + collection + ": " + filterObject); } traceIfRequired(collection, w); } }
private void delete(boolean force) { try { if (forceFail) { return; } Watch w = Watch.start(); deleteByIteration(force); if (Microtiming.isEnabled()) { w.submitMicroTiming("ES", "DELETE: " + toString(true)); } } catch (Exception e) { throw Exceptions.handle(IndexAccess.LOG, e); } }
protected void tryCommit(boolean cascade) { if (stmt == null) { return; } if (batchBacklog > 0) { try { Watch w = Watch.start(); stmt.executeBatch(); avarage.addValues(batchBacklog, w.elapsedMillis()); batchBacklog = 0; } catch (SQLException e) { if (cascade) { context.safeClose(); } throw Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("An error occured while batch executing a statement: %s (%s)") .handle(); } } }
protected void updateStatistics(String sql, Watch w) { w.submitMicroTiming("SQL", sql); Databases.numQueries.inc(); Databases.queryDuration.addValue(w.elapsedMillis()); if (w.elapsedMillis() > Databases.getLogQueryThresholdMillis()) { Databases.numSlowQueries.inc(); DB.SLOW_DB_LOG.INFO("A slow JDBC query was executed (%s): %s\n%s", w.duration(), sql, ExecutionPoint.snapshot().toString()); } }