public void configure(final String iConfiguration) { if (iConfiguration == null || iConfiguration.length() == 0) return; if (isRecording()) stopRecording(); startRecording(); }
@Override public ORecord fromStream(final byte[] iSource, final ORecord iRecord, final String[] iFields) { final long timer = PROFILER.startChrono(); try { return fromString(new String(iSource,"UTF-8"), iRecord, iFields); } catch (UnsupportedEncodingException e) { throw OException.wrapException(new OSchemaException("Error reading record"),e); } finally { PROFILER .stopChrono(PROFILER.getProcessMetric("serializer.record.string.fromStream"), "Deserialize record from stream", timer); } }
public void connected() { final String dictProfilerMetric = PROFILER.getProcessMetric("network.channel.binary.*"); profilerMetric = PROFILER.getProcessMetric( "network.channel.binary." + socket.getRemoteSocketAddress().toString() +":"+ socket.getLocalPort() + "".replace('.', '_')); PROFILER.registerHookValue(profilerMetric + ".transmittedBytes", "Bytes transmitted to a network channel", METRIC_TYPE.SIZE, new OProfilerHookValue() { public Object getValue() { return metricTransmittedBytes; } }, dictProfilerMetric + ".transmittedBytes"); PROFILER.registerHookValue(profilerMetric + ".receivedBytes", "Bytes received from a network channel", METRIC_TYPE.SIZE, new OProfilerHookValue() { public Object getValue() { return metricReceivedBytes; } }, dictProfilerMetric + ".receivedBytes"); PROFILER.registerHookValue(profilerMetric + ".flushes", "Number of times the network channel has been flushed", METRIC_TYPE.COUNTER, new OProfilerHookValue() { public Object getValue() { return metricFlushes; } }, dictProfilerMetric + ".flushes"); }
protected void revertSubclassesProfiler(final OCommandContext iContext, int num) { final OProfiler profiler = Orient.instance().getProfiler(); if (profiler.isRecording()) { profiler.updateCounter(profiler.getDatabaseMetric(getDatabase().getName(), "query.indexUseAttemptedAndReverted"), "Reverted index usage in query", num); } }
@ConsoleCommand(description = "Execute a command against the profiler") public void profiler( @ConsoleParameter(name = "profiler command", description = "command to execute against the profiler") final String iCommandName) { if (iCommandName.equalsIgnoreCase("on")) { Orient.instance().getProfiler().startRecording(); message("\nProfiler is ON now, use 'profiler off' to turn off."); } else if (iCommandName.equalsIgnoreCase("off")) { Orient.instance().getProfiler().stopRecording(); message("\nProfiler is OFF now, use 'profiler on' to turn on."); } else if (iCommandName.equalsIgnoreCase("dump")) { out.println(Orient.instance().getProfiler().dump()); } }
public void change(final Object iCurrentValue, final Object iNewValue) { Orient instance = Orient.instance(); if (instance != null) { final OProfiler prof = instance.getProfiler(); if (prof != null) if ((Boolean) iNewValue) prof.startRecording(); else prof.stopRecording(); } } }),
@Deprecated public Object execute(final Map<Object, Object> iArgs) { final long start = Orient.instance().getProfiler().startChrono(); Object result; while (true) { try { if (callback != null) return callback.call(iArgs); final OCommandExecutorScript command = new OCommandExecutorScript(); command.parse(new OCommandScript(getLanguage(), getCode())); result = command.execute(iArgs); break; } catch (ONeedRetryException | ORetryQueryException ignore) { } } if (Orient.instance().getProfiler().isRecording()) Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.instance().get().getName() + ".function.execute", "Time to execute a function", start, "db.*.function.execute"); return result; }
final long msFromLastDump = System.currentTimeMillis() - statsLastAutoDump; final String[] hooks = Orient.instance().getProfiler().getHookAsString(); for (String h : hooks) { if (h.startsWith("db.") && h.endsWith("createRecord")) lastCreateRecords += (Long) Orient.instance().getProfiler().getHookValue(h); else if (h.startsWith("db.") && h.endsWith("readRecord")) lastReadRecords += (Long) Orient.instance().getProfiler().getHookValue(h); else if (h.startsWith("db.") && h.endsWith("updateRecord")) lastUpdateRecords += (Long) Orient.instance().getProfiler().getHookValue(h); else if (h.startsWith("db.") && h.endsWith("deleteRecord")) lastDeleteRecords += (Long) Orient.instance().getProfiler().getHookValue(h); else if (h.startsWith("db.") && h.endsWith("txCommit")) lastTxCommit += (Long) Orient.instance().getProfiler().getHookValue(h); else if (h.startsWith("db.") && h.endsWith("txRollback")) lastTxRollback += (Long) Orient.instance().getProfiler().getHookValue(h); final List<String> chronos = Orient.instance().getProfiler().getChronos(); for (String c : chronos) { final OProfilerEntry chrono = Orient.instance().getProfiler().getChrono(c); if (chrono != null) { if (c.startsWith("db.") && c.contains(".command."))
/** * All operations running at cache destruction stage */ public void shutdown() { underlying.shutdown(); if (Orient.instance().getProfiler() != null) { Orient.instance().getProfiler().unregisterHookValue(profilerPrefix + "enabled"); Orient.instance().getProfiler().unregisterHookValue(profilerPrefix + "current"); Orient.instance().getProfiler().unregisterHookValue(profilerPrefix + "max"); } } }
public void handle(final Signal signal) { OLogManager.instance().warn(this, "Received signal: %s", signal); final String s = signal.toString().trim(); if (Orient.instance().isSelfManagedShutdown() && (s.equals("SIGKILL") || s.equals("SIGHUP") || s.equals("SIGINT") || s .equals("SIGTERM"))) { Orient.instance().shutdown(); System.exit(1); } else if (s.equals("SIGTRAP")) { System.out.println(); OGlobalConfiguration.dumpConfiguration(System.out); System.out.println(); Orient.instance().getProfiler().dump(System.out); System.out.println(); System.out.println(Orient.instance().getProfiler().threadDump()); } else { SignalHandler redefinedHandler = redefinedHandlers.get(signal); if (redefinedHandler != null) { redefinedHandler.handle(signal); } } for (OSignalListener l : listeners) l.onSignal(signal); }
private void logProfiling() { if (executionPlan.getStatement() != null && Orient.instance().getProfiler().isRecording()) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null) { final OSecurityUser user = db.getUser(); final String userString = user != null ? user.toString() : null; Orient.instance().getProfiler() .stopChrono("db." + ODatabaseRecordThreadLocal.instance().get().getName() + ".command.sql." + executionPlan.getStatement(), "Command executed against the database", System.currentTimeMillis() - totalExecutionTime, "db.*.command.*", null, userString); } } }
/** * All operations running at cache initialization stage */ public void startup() { underlying.startup(); Orient.instance().getProfiler() .registerHookValue(profilerPrefix + "current", "Number of entries in cache", METRIC_TYPE.SIZE, new OProfilerHookValue() { public Object getValue() { return getSize(); } }, profilerMetadataPrefix + "current"); }
public long getCounter(final String statName) { if (statName == null || !isRecording()) return -1; final Long stat = counters.get(statName); if (stat == null) return -1; return stat; }
public void change(final Object iCurrentValue, final Object iNewValue) { Orient.instance().getProfiler().configure(iNewValue.toString()); } }),
protected void updateProfiler(final OCommandContext iContext, final OIndex<?> index, final List<Object> keyParams, final OIndexDefinition indexDefinition) { if (iContext.isRecordingMetrics()) iContext.updateMetric("compositeIndexUsed", +1); final OProfiler profiler = Orient.instance().getProfiler(); if (profiler.isRecording()) { profiler.updateCounter(profiler.getDatabaseMetric(index.getDatabaseName(), "query.indexUsed"), "Used index in query", +1); int params = indexDefinition.getParamCount(); if (params > 1) { final String profiler_prefix = profiler.getDatabaseMetric(index.getDatabaseName(), "query.compositeIndexUsed"); profiler.updateCounter(profiler_prefix, "Used composite index in query", +1); profiler.updateCounter(profiler_prefix + "." + params, "Used composite index in query with " + params + " params", +1); profiler.updateCounter(profiler_prefix + "." + params + '.' + keyParams.size(), "Used composite index in query with " + params + " params and " + keyParams.size() + " keys", +1); } } }
final long beginTime = Orient.instance().getProfiler().startChrono(); if (Orient.instance().getProfiler().isRecording()) { final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (db != null) { .stopChrono("db." + ODatabaseRecordThreadLocal.instance().get().getName() + ".command." + iCommand, "Command executed against the database", beginTime, "db.*.command.*", null, userString);
public synchronized void close() { PROFILER.unregisterHookValue(profilerMetric + ".transmittedBytes"); PROFILER.unregisterHookValue(profilerMetric + ".receivedBytes"); PROFILER.unregisterHookValue(profilerMetric + ".flushes");
private void registerProfilerHooks() { Orient.instance().getProfiler() .registerHookValue("db." + this.name + ".createRecord", "Number of created records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordCreated), "db.*.createRecord"); .registerHookValue("db." + this.name + ".readRecord", "Number of read records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordRead), "db.*.readRecord"); .registerHookValue("db." + this.name + ".updateRecord", "Number of updated records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordUpdated), "db.*.updateRecord"); .registerHookValue("db." + this.name + ".deleteRecord", "Number of deleted records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordDeleted), "db.*.deleteRecord"); .registerHookValue("db." + this.name + ".scanRecord", "Number of read scanned", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordScanned), "db.*.scanRecord"); .registerHookValue("db." + this.name + ".recyclePosition", "Number of recycled records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordRecycled), "db.*.recyclePosition"); .registerHookValue("db." + this.name + ".conflictRecord", "Number of conflicts during updating and deleting records", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(recordConflict), "db.*.conflictRecord"); .registerHookValue("db." + this.name + ".txBegun", "Number of transactions begun", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(txBegun), "db.*.txBegun"); .registerHookValue("db." + this.name + ".txCommit", "Number of committed transactions", OProfiler.METRIC_TYPE.COUNTER, new AtomicLongOProfilerHookValue(txCommit), "db.*.txCommit"); .registerHookValue("db." + this.name + ".txRollback", "Number of rolled back transactions", OProfiler.METRIC_TYPE.COUNTER,
public void updateCounter(final String statName, final String description, final long plus, final String metadata) { if (statName == null || !isRecording()) return; Long oldValue; Long newValue; do { oldValue = counters.get(statName); if (oldValue == null) { counters.putIfAbsent(statName, 0L); oldValue = counters.get(statName); } newValue = oldValue + plus; } while (!counters.replace(statName, oldValue, newValue)); }
protected void revertProfiler(final OCommandContext iContext, final OIndex<?> index, final List<Object> keyParams, final OIndexDefinition indexDefinition) { if (iContext.isRecordingMetrics()) { iContext.updateMetric("compositeIndexUsed", -1); } final OProfiler profiler = Orient.instance().getProfiler(); if (profiler.isRecording()) { profiler.updateCounter(profiler.getDatabaseMetric(index.getDatabaseName(), "query.indexUsed"), "Used index in query", -1); int params = indexDefinition.getParamCount(); if (params > 1) { final String profiler_prefix = profiler.getDatabaseMetric(index.getDatabaseName(), "query.compositeIndexUsed"); profiler.updateCounter(profiler_prefix, "Used composite index in query", -1); profiler.updateCounter(profiler_prefix + "." + params, "Used composite index in query with " + params + " params", -1); profiler.updateCounter(profiler_prefix + "." + params + '.' + keyParams.size(), "Used composite index in query with " + params + " params and " + keyParams.size() + " keys", -1); } } }