/** * Boilerplate method for calling <tt>duration(false)</tt> * * @return a string representation as generated by {@link #duration(boolean)} */ public String duration() { return duration(false); }
@Override public String toString() { return duration(); } }
@Override public String toString() { if (name == null) { name = nameProvider.get(); } String result = name + " (" + w.duration() + "/" + NLS.convertDuration(timeout.getSeconds(), true, false) + ")"; if (isOvertime()) { result += " OVERTIME!"; } return result; }
/** * Creates a new log entry. * * @param function name or method of the function which was invoked * @param description description of the call * @param result outcome of the call * @param watch watch representing the duration of the call */ public void log(String function, String description, Result result, Watch watch) { synchronized (entries) { entries.add(0, new Entry("OBJECT " + function, description, result.name(), watch.duration())); if (entries.size() > 250) { entries.remove(entries.size() - 1); } } } }
private void buildAndLogExecutionInfo(Watch watch, LocalDateTime startedAt, String executedWorkDescription) { if (executedWorkDescription != null) { executionInfo = NLS.toUserString(startedAt) + " (" + watch.duration() + "): " + executedWorkDescription; Log.BACKGROUND.FINE(getName() + ": " + executionInfo); } else { executionInfo = NLS.toUserString(startedAt) + " (" + watch.duration() + ") - no work executed..."; } }
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(); } } }
output.apply("%-20s %59s", e.getFirst(), e.getSecond()); output.apply("Flow duration: %s", cc.get().getWatch().duration());
private static void waitForLifecyclePaticipants() { LOG.INFO("Awaiting system halt..."); LOG.INFO(SEPARATOR_LINE); for (int i = lifecycleKillParticipants.size() - 1; i >= 0; i--) { Killable killable = lifecycleKillParticipants.get(i); try { Watch w = Watch.start(); killable.awaitTermination(); LOG.INFO("Terminated: %s (Took: %s)", killable.getClass().getName(), w.duration()); } catch (Exception e) { Exceptions.handle() .error(e) .to(LOG) .withSystemErrorMessage("Termination of: %s failed!", killable.getClass().getName()) .handle(); } } }
/** * Initializes the framework. * <p> * This is called by <tt>IPL.main</tt> once the class loader is fully populated. * * @param setup the setup class used to configure the framework */ public static void start(Setup setup) { Watch w = Watch.start(); Sirius.setup = setup; setup.init(); LOG.INFO(SEPARATOR_LINE); LOG.INFO("System is STARTING..."); LOG.INFO(SEPARATOR_LINE); init(); LOG.INFO(SEPARATOR_LINE); LOG.INFO("System is UP and RUNNING - %s", w.duration()); LOG.INFO(SEPARATOR_LINE); Runtime.getRuntime().addShutdownHook(new Thread(Sirius::stop)); }
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()); } }
@Override public void close() throws SQLException { try (Operation op = new Operation(() -> database.name + ".close()", Duration.ofSeconds(5))) { delegate.close(); } catch (SQLException e) { // Most likely this exception will be a false alert because DBCP 1.2.2 cannot deal with connections which // are closed by their driver (due to network issues). // The next release of DBCP will fix this problem. The exception is logged at INFO level in case a "real" // problem occurred. If we wouldn't call delegate.close, the connection would remain active and might block // the pool. Databases.LOG.INFO("Error closing connection"); Databases.LOG.INFO(e); } finally { watch.submitMicroTiming("SQL", "Connection Duration: " + database.name); if (watch.elapsedMillis() > Databases.getLogConnectionThresholdMillis()) { DB.SLOW_DB_LOG.INFO("A long running connection was detected (%s): Opened:\n%s\n\nClosed:\n%s", watch.duration(), connected.toString(), ExecutionPoint.snapshot().toString()); } } }
@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; } }
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()); } }
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()); } }
/** * Executes the query and returns the resulting items as a {@link sirius.web.controller.Page}. * * @return the result of the query along with all facets and paging-metadata */ public Page<E> queryPage() { if (limit == null) { throw new IllegalStateException("limit must be set when using queryPage (Call .page(...)!)"); } Watch w = Watch.start(); ResultList<E> result = new ResultList<>(termFacets, null); if (!forceFail) { try { result = queryResultList(); } catch (Exception e) { UserContext.handle(e); } } int total = Math.toIntExact(result.getTotalNumberOfHits()); boolean hasMore = total > start + limit; return new Page<E>().withQuery(queryString) .withStart(start + 1) .withItems(result.getResults()) .withTotalItems(total) .withFactesSupplier(result::getFacets) .withHasMore(hasMore) .withDuration(w.duration()) .withPageSize(pageSize); }
elastic.numSlowQueries.inc(); DB.SLOW_DB_LOG.INFO("A slow Elasticsearch query was executed (%s): %s\n%s\n%s", w.duration(), method + ": " + uri, buildContent().orElse("no content"),