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); }
private void enableTiming(Output output) { if (Microtiming.isEnabled()) { generateOutput(output); Microtiming.setEnabled(false); output.line("Resetting Microtiming..."); } else { output.line("Enabling Microtiming..."); } Microtiming.setEnabled(true); }
/** * Submits the value for this watch to the {@link Microtiming} framework using the given key * * @param category selects the category for the given key * @param key the key used to store the elapsed time for */ public void submitMicroTiming(@Nonnull String category, @Nonnull String key) { long newTime = System.nanoTime(); Microtiming.submit(category, key, newTime - lastMicroTime); lastMicroTime = newTime; }
long delta = System.currentTimeMillis() - Microtiming.getLastReset(); Microtiming.getTimings() .stream() .collect(MultiMap.groupingBy(MultiMap::create, Microtiming.Timing::getCategory))
private void disableTiming(Output output) { generateOutput(output); Microtiming.setEnabled(false); output.line("Disabling Microtiming..."); }
@Override public void execute(Output output, String... params) throws Exception { if (params.length == 1 && Strings.isFilled(params[0])) { parseParameters(output, params[0]); } else { if (Microtiming.isEnabled()) { generateOutput(output); } else { output.line("Microtiming is disabled! Use: 'timing +' to enable."); } } }
/** * 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()); } } }
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); } }
@Override public void truncate() { Watch w = Watch.start(); Compiler compiler = compileDELETE(); try { try (Connection c = db.getConnection()) { try (PreparedStatement stmt = compiler.prepareStatement(c)) { stmt.executeUpdate(); } } finally { if (Microtiming.isEnabled()) { w.submitMicroTiming("OMA", compiler.toString()); } } } catch (Exception e) { throw queryError(compiler, e); } }
if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "AGGREGATE - " + collection + "." + field + " (" + operator + "): " + filterObject);
/** * 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); } }
/** * Executes the insert statement into the given collection. * * @param collection the collection to insert the document into * @return the inserted document */ public Doc into(String collection) { if (Mongo.LOG.isFINE()) { Mongo.LOG.FINE("INSERT: %s\nObject: %s", collection, obj); } Watch w = Watch.start(); mongo.db().getCollection(collection).insertOne(obj); mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("mongo", "INSERT - " + collection + ": " + obj); } return new Doc(obj); } }
/** * Executes the delete statement on the given collection. * * @param collection the name of the collection to delete documents from * @return the result of the delete operation */ public DeleteResult singleFrom(String collection) { Watch w = Watch.start(); try { if (Mongo.LOG.isFINE()) { Mongo.LOG.FINE("DELETE: %s\nFilter: %s", collection, filterObject); } return mongo.db().getCollection(collection).deleteOne(filterObject); } finally { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("mongo", "DELETE - " + collection + ": " + filterObject); } traceIfRequired(collection, w); } }
@Override public long count() { Watch w = Watch.start(); Compiler compiler = compileCOUNT(); try { try (Connection c = db.getConnection()) { return execCount(compiler, c); } finally { if (Microtiming.isEnabled()) { w.submitMicroTiming("OMA", compiler.toString()); } } } catch (Exception e) { throw queryError(compiler, e); } }
if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "FIND ONE - " + collection + ": " + filterObject);
/** * Internal execution of the query along with the transformation of the result for a count of entities * * @param builder the completed query * @return the result of the query */ protected long transformCount(SearchRequestBuilder builder) { Watch w = Watch.start(); SearchResponse res = builder.execute().actionGet(); if (IndexAccess.LOG.isFINE()) { IndexAccess.LOG.FINE("COUNT: %s.%s: SUCCESS: %d", indexAccess.getIndex(clazz), indexAccess.getDescriptor(clazz).getType(), res.getHits().getTotalHits()); } if (Microtiming.isEnabled()) { w.submitMicroTiming("ES", "COUNT: " + toString(true)); } return res.getHits().getTotalHits(); }
/** * Executes the delete statement on the given collection. * * @param collection the name of the collection to delete documents from * @return the result of the delete operation */ public DeleteResult manyFrom(String collection) { Watch w = Watch.start(); try { if (Mongo.LOG.isFINE()) { Mongo.LOG.FINE("DELETE: %s\nFilter: %s", collection, filterObject); } return mongo.db().getCollection(collection).deleteMany(filterObject); } finally { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("mongo", "DELETE - " + collection + ": " + filterObject); } traceIfRequired(collection, w); } } }
@Override public void iterate(Function<E, Boolean> handler) { Compiler compiler = compileSELECT(); try { Watch w = Watch.start(); try (Connection c = db.getConnection(); PreparedStatement stmt = compiler.prepareStatement(c)) { Limit limit = getLimit(); boolean nativeLimit = db.hasCapability(Capability.LIMIT); tuneStatement(stmt, limit, nativeLimit); try (ResultSet rs = stmt.executeQuery()) { execIterate(handler, compiler, limit, nativeLimit, rs); } } finally { if (Microtiming.isEnabled()) { w.submitMicroTiming("OMA", compiler.toString()); } } } catch (Exception e) { throw queryError(compiler, e); } }
/** * Executes the update on the given collection. * * @param collection the collection to update * @return the result of the update */ public UpdateResult executeFor(String collection) { Document updateObject = prepareUpdate(collection); Watch w = Watch.start(); try { if (Mongo.LOG.isFINE()) { Mongo.LOG.FINE("UPDATE: %s\nFilter: %s\n Update:%s", collection, filterObject, updateObject); } UpdateOptions updateOptions = new UpdateOptions().upsert(this.upsert); if (many) { return mongo.db().getCollection(collection).updateMany(filterObject, updateObject, updateOptions); } else { return mongo.db().getCollection(collection).updateOne(filterObject, updateObject, updateOptions); } } finally { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("mongo", "UPDATE - " + collection + ": " + filterObject); } traceIfRequired(collection, w); } }
} finally { elastic.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("elastic", method + ": " + uri);