public override IEnumerable <BsonDocument> Aggregate(AggregateArgs args) { var sw = new Stopwatch(); sw.Start(); var underlyingEnumerable = base.Aggregate(args); sw.Stop(); var profiledEnumerable = new ProfiledEnumerable <BsonDocument>(underlyingEnumerable); sw.Start(); var profiledEnumerator = (ProfiledEnumerator <BsonDocument>)profiledEnumerable.GetEnumerator(); sw.Stop(); profiledEnumerator.EnumerationEnded += (sender, eventArgs) => { var operationsList = args.Pipeline.ToList(); string commandString = string.Format("db.{0}.aggregate(pipeline)\n\npipeline = \n{1}", Name, string.Join("\n", operationsList.Select(operation => string.Format(" {0}", operation)))); ProfilerUtils.AddMongoTiming(commandString, (long)(eventArgs.Elapsed + sw.Elapsed).TotalMilliseconds, ExecuteType.Read); }; return(profiledEnumerable); }
/// <summary> /// Provides base <see cref="ElasticClient"/> with profiling features to current <see cref="MiniProfiler"/> session. /// </summary> /// <param name="configuration">Instance of <see cref="ConnectionSettings"/>. Its responses will be handled and pushed to <see cref="MiniProfiler"/></param> public ProfiledElasticClient(ConnectionSettings configuration) : base(configuration) { ProfilerUtils.ExcludeElasticsearchAssemblies(); ProfilerUtils.ApplyConfigurationSettings(configuration); configuration.SetConnectionStatusHandler(response => MiniProfilerElasticsearch.HandleResponse(response, _profiler)); }
/// <summary> /// Provides base <see cref="ElasticLowLevelClient"/> with profiling features to current <see cref="MiniProfiler"/> session. /// </summary> /// <param name="configuration">Instance of <see cref="ConnectionConfiguration"/>. Its responses will be handled and pushed to <see cref="MiniProfiler"/></param> public ProfiledElasticLowLevelClient(ConnectionConfiguration configuration) : base(configuration) { ProfilerUtils.ExcludeElasticsearchAssemblies(); ProfilerUtils.ApplyConfigurationSettings(configuration); configuration.OnRequestCompleted(apiCallDetails => MiniProfilerElasticsearch.HandleResponse(apiCallDetails)); }
public override FindAndModifyResult FindAndModify(FindAndModifyArgs args) { var sw = new Stopwatch(); sw.Start(); var result = base.FindAndModify(args); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.findAndModify(query, sort, update, new, fields, upsert)", Name); if (args.Query != null) { commandStringBuilder.AppendFormat("\nquery = {0}", args.Query.ToBsonDocument()); } else { commandStringBuilder.Append("\nquery = null"); } if (args.SortBy != null) { commandStringBuilder.AppendFormat("\nsort = {0}", args.SortBy.ToBsonDocument()); } else { commandStringBuilder.Append("\nsort = null"); } if (args.Update != null) { commandStringBuilder.AppendFormat("\nupdate = {0}", args.Update.ToBsonDocument()); } else { commandStringBuilder.Append("\nupdate = null"); } commandStringBuilder.AppendFormat("\nnew = {0}", args.VersionReturned == FindAndModifyDocumentVersion.Modified ? "true" : "false"); if (args.Fields != null) { commandStringBuilder.AppendFormat("\nfields = {0}", args.Fields.ToBsonDocument()); } else { commandStringBuilder.Append("\nfields = null"); } commandStringBuilder.AppendFormat("\nupsert = {0}", args.Upsert ? "true" : "false"); string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update); return(result); }
/// <summary> Initialize the agent.</summary> /// <remarks> /// An application must call this method to initialize the class framework /// and runtime. No other methods can be called until the agent has been /// successfully initialized. When the agent exits it is important that the /// <c>shutdown</c> method be called to safely release the resources /// allocated by the runtime. /// /// If an application overrides this method, it should call the superclass /// implementation <i>after</i> performing its own initialization. /// </remarks> /// <seealso cref="Shutdown()"></seealso> /// <exception cref="Exception">If the agent is unable to initialize due to a file or resource exception</exception> /// <exception cref="AdkException">Thrown if the agent has already /// been initialized /// </exception> public virtual void Initialize() { lock (this) { if (fInit) { AdkUtils._throw(new AdkException("Agent is already initialized", null), Log); } if (fShutdownInProgress) { AdkUtils._throw (new AdkException("Agent is in the process of shutting down", null), Log); } #if EVAL try { new E(this); } catch (Exception) { Console.WriteLine("Corrupt ADK Evaluation Edition or internal error. Please report this notice to OpenADK Tech Support."); Environment.Exit(0); } #endif if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Initializing agent..."); } // Verify home directory exists and can be written to AssertDirectoryExists(HomeDir, "Home"); // Verify work directory exists and can be written to AssertDirectoryExists(WorkDir, "Work"); #if PROFILED { // TODO: Implement Support for Profiling System.out.println("SIF Profiling Harness support enabled in ADK"); // Establish the SIFProfilerClient name (i.e. "sourceId_ADK") ProfilerUtils.setProfilerName(getId() + "_ADK"); } #endif //Initialize the TransportManager fTransportManager.Activate(this); fShutdownInProgress = false; fInit = true; if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Agent initialized"); } } }
public override IEnumerable <BsonDocument> Group(IMongoQuery query, BsonJavaScript keyFunction, BsonDocument initial, BsonJavaScript reduce, BsonJavaScript finalize) { var sw = new Stopwatch(); sw.Start(); var result = base.Group(query, keyFunction, initial, reduce, finalize); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.group({{keyf, reduce, initial", Name); if (query != null) { commandStringBuilder.Append(", cond"); } if (initial != null) { commandStringBuilder.Append(", initial"); } if (finalize != null) { commandStringBuilder.Append(", finalize"); } commandStringBuilder.Append("})"); commandStringBuilder.AppendFormat("\nkeyf = javascript"); commandStringBuilder.Append("\nreduce = javascript"); commandStringBuilder.AppendFormat("\ninitial = {0}", initial.ToBsonDocument()); if (query != null) { commandStringBuilder.AppendFormat("\ncond = {0}", query.ToBsonDocument()); } if (initial != null) { commandStringBuilder.AppendFormat("\ninitial = {0}", initial.ToBsonDocument()); } if (finalize != null) { commandStringBuilder.Append("\nfinalize = javascript"); } string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Read); return(result); }
public override WriteConcernResult Update(IMongoQuery query, IMongoUpdate update, MongoUpdateOptions options) { var sw = new Stopwatch(); sw.Start(); var result = base.Update(query, update, options); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.update(query, update", Name); var optionsList = new List <string>(); if ((options.Flags & UpdateFlags.Upsert) == UpdateFlags.Upsert) { optionsList.Add("upsert: true"); } if ((options.Flags & UpdateFlags.Multi) == UpdateFlags.Multi) { optionsList.Add("multi: true"); } if (optionsList.Any()) { commandStringBuilder.AppendFormat("{{ {0} }}", string.Join(", ", optionsList)); } commandStringBuilder.Append(")"); if (query != null) { commandStringBuilder.AppendFormat("\nquery = {0}", query.ToBsonDocument()); } else { commandStringBuilder.Append("\nquery = {}"); } if (update != null) { commandStringBuilder.AppendFormat("\nupdate = {0}", update.ToBsonDocument()); } else { commandStringBuilder.Append("\nupdate = {}"); } string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update); return(result); }
public override void Drop() { var sw = new Stopwatch(); sw.Start(); base.Drop(); sw.Stop(); string commandString = string.Format("{0}.drop()", Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); }
public override MapReduceResult MapReduce(MapReduceArgs args) { var sw = new Stopwatch(); sw.Start(); var result = base.MapReduce(args); sw.Stop(); string commandString = string.Format("db.{0}.mapReduce(<map function>, <reduce function>, options)", Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Read); return(result); }
public override CommandResult DropCollection(string collectionName) { var sw = new Stopwatch(); sw.Start(); var result = base.DropCollection(collectionName); sw.Stop(); string commandString = string.Format("db.{0}.drop()", collectionName); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public override MapReduceResult MapReduce(BsonJavaScript map, BsonJavaScript reduce, IMongoMapReduceOptions options) { var sw = new Stopwatch(); sw.Start(); var result = base.MapReduce(map, reduce, options); sw.Stop(); string commandString = string.Format("db.{0}.mapReduce(<map function>, <reduce function>, options)", Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Create); return(result); }
public override CommandResult DropIndexByName(string indexName) { var sw = new Stopwatch(); sw.Start(); var result = base.DropIndexByName(indexName); sw.Stop(); string commandString = string.Format("db.{0}.dropIndex(\"{1}\")", Name, indexName); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public override CommandResult ReIndex() { var sw = new Stopwatch(); sw.Start(); var result = base.ReIndex(); sw.Stop(); string commandString = string.Format("db.{0}.reIndex()", Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Create); return(result); }
public override FindAndModifyResult FindAndRemove(FindAndRemoveArgs args) { var sw = new Stopwatch(); sw.Start(); var result = base.FindAndRemove(args); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.findAndModify(query, sort, remove, fields)", Name); if (args.Query != null) { commandStringBuilder.AppendFormat("\nquery = {0}", args.Query.ToBsonDocument()); } else { commandStringBuilder.Append("\nquery = null"); } if (args.SortBy != null) { commandStringBuilder.AppendFormat("\nsort = {0}", args.SortBy.ToBsonDocument()); } else { commandStringBuilder.Append("\nsort = null"); } commandStringBuilder.AppendFormat("\nremove = true"); if (args.Fields != null) { commandStringBuilder.AppendFormat("\nfields = {0}", args.Fields.ToBsonDocument()); } else { commandStringBuilder.Append("\nfields = null"); } string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update); return(result); }
public override CommandResult RenameCollection(string oldCollectionName, string newCollectionName, bool dropTarget) { var sw = new Stopwatch(); sw.Start(); var result = base.RenameCollection(oldCollectionName, newCollectionName, dropTarget); sw.Stop(); string commandString = string.Format("db.{0}.renameCollection(\"{1}\", {2})", oldCollectionName, newCollectionName, dropTarget.ToString().ToLower()); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public override WriteConcernResult CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { var sw = new Stopwatch(); sw.Start(); var result = base.CreateIndex(keys, options); sw.Stop(); string commandString = options != null ? string.Format("db.{0}.ensureIndex(keys, options)\n\nkeys = {1}\n\noptions = {2}", Name, keys.ToBsonDocument(), options.ToBsonDocument()) : string.Format("db.{0}.ensureIndex(keys, options)\n\nkeys = {1}", Name, keys.ToBsonDocument()); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public override BsonDocument Explain() { var sw = new Stopwatch(); sw.Start(); var result = base.Explain(); sw.Stop(); string commandString = Query != null ? string.Format("{0}.find(query).explain()\n\nquery = {1}", Collection.Name, Query.ToBsonDocument()) : string.Format("{0}.find().explain()", Collection.Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public override IEnumerable <BsonValue> Distinct(string key, IMongoQuery query) { var sw = new Stopwatch(); sw.Start(); var result = base.Distinct(key, query); sw.Stop(); string commandString = query != null ? string.Format("db.{0}.distinct(\"{1}\", query)\n\nquery = {2}", Name, key, query) : string.Format("db.{0}.distinct(\"{1}\")", Name, key); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Read); return(result); }
public override long Count(IMongoQuery query) { var sw = new Stopwatch(); sw.Start(); var result = base.Count(query); sw.Stop(); string commandString = query != null ? string.Format("db.{0}.count(query)\n\nquery = {1}", Name, query) : string.Format("db.{0}.count()", Name); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Read); return(result); }
public override WriteConcernResult Remove(IMongoQuery query, RemoveFlags flags, WriteConcern writeConcern) { var sw = new Stopwatch(); sw.Start(); var result = base.Remove(query, flags, writeConcern); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.remove", Name); if (query == null) { if ((flags & RemoveFlags.None) == RemoveFlags.None) { commandStringBuilder.Append("()"); } else if ((flags & RemoveFlags.Single) == RemoveFlags.Single) { commandStringBuilder.Append("({}, true)"); } } else { commandStringBuilder.Append("("); commandStringBuilder.AppendFormat("query"); if ((flags & RemoveFlags.Single) == RemoveFlags.Single) { commandStringBuilder.Append(", true"); } commandStringBuilder.Append(")"); commandStringBuilder.AppendFormat("\nquery = {0}", query.ToBsonDocument()); } string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Create); return(result); }
public override AggregateResult Aggregate(IEnumerable <BsonDocument> operations) { var operationsList = operations.ToList(); var sw = new Stopwatch(); sw.Start(); var result = base.Aggregate(operationsList); sw.Stop(); string commandString = string.Format("db.{0}.aggregate(pipeline)\n\npipeline = \n{1}", Name, string.Join("\n", operationsList.Select(operation => string.Format(" {0}", operation)))); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Read); return(result); }
protected sealed override async UniTask OnContextActivate(IContext context) { #if UNITY_EDITOR || GAME_LOGS_ENABLED var profileId = ProfilerUtils.BeginWatch($"Service_{typeof(TServiceApi).Name}"); GameLog.Log($"GameService Profiler Init : {typeof(TServiceApi).Name} | {DateTime.Now}"); #endif _service = await CreateService(context); #if UNITY_EDITOR || GAME_LOGS_ENABLED var watchResult = ProfilerUtils.GetWatchData(profileId); GameLog.Log($"GameService Profiler Create : {typeof(TServiceApi).Name} | Take {watchResult.watchMs} | {DateTime.Now}"); #endif _service.AddTo(LifeTime); await BindService(_service, context); await OnServiceCreated(_service, context); GameLog.LogRuntime($"NODE SERVICE {typeof(TServiceApi).Name} CREATED"); }
public override IEnumerable <WriteConcernResult> InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options) { var documentsList = documents.Cast <object>().ToList(); var sw = new Stopwatch(); sw.Start(); var result = base.InsertBatch(nominalType, documentsList, options); sw.Stop(); var commandStringBuilder = new StringBuilder(512); commandStringBuilder.AppendFormat("db.{0}.insert(", Name); if (documentsList.Count > 1) { commandStringBuilder.AppendFormat("<{0} documents>", documentsList.Count); } else { // handle ensureIndex specially if (Name == "system.indexes") { commandStringBuilder.AppendFormat("{0}", documentsList.First().ToBsonDocument()); } else { commandStringBuilder.Append("<document>"); } } commandStringBuilder.Append(")"); string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Create); return(result); }
private FindAndModifyResult FindAndModifyImpl(IMongoQuery query, IMongoSortBy sortBy, bool remove, IMongoUpdate update, bool returnNew, IMongoFields fields, bool upsert) { var sw = new Stopwatch(); sw.Start(); var result = base.FindAndModify(query, sortBy, update, fields, returnNew, upsert); sw.Stop(); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.AppendFormat("db.{0}.findAndModify(query, sort, remove, update, new, fields, upsert)", Name); if (query != null) { commandStringBuilder.AppendFormat("\nquery = {0}", query.ToBsonDocument()); } else { commandStringBuilder.Append("\nquery = null"); } if (sortBy != null) { commandStringBuilder.AppendFormat("\nsort = {0}", sortBy.ToBsonDocument()); } else { commandStringBuilder.Append("\nsort = null"); } commandStringBuilder.AppendFormat("\nremove = {0}", remove ? "true" : "false"); if (update != null) { commandStringBuilder.AppendFormat("\nupdate = {0}", update.ToBsonDocument()); } else { commandStringBuilder.Append("\nupdate = null"); } commandStringBuilder.AppendFormat("\nnew = {0}", returnNew ? "true" : "false"); if (fields != null) { commandStringBuilder.AppendFormat("\nfields = {0}", fields.ToBsonDocument()); } else { commandStringBuilder.Append("\nfields = null"); } commandStringBuilder.AppendFormat("\nupsert = {0}", upsert ? "true" : "false"); string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update); return(result); }
public virtual void Shutdown(ProvisioningFlags provisioningOptions) { if (!fInit) { return; } fShutdownInProgress = true; if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Shutting down agent..."); } // Close the SIFProfilerClient if supported #if PROFILED { // TODO: Implement Support for Profiling com.OpenADK.sifprofiler.SIFProfilerClient prof = com.OpenADK.sifprofiler.SIFProfilerClient.getInstance(ProfilerUtils.getProfilerName()); if (prof != null) { try { prof.close(); } catch (Exception ex) { } } } #endif try { // JAVA_TODO: Unsubscribe, Unprovide topics // Disconnect and shutdown each zone... IZoneFactory zf = IZoneFactory; IZone[] zones = zf.GetAllZones(); for (int i = 0; i < zones.Length; i++) { zones[i].Disconnect(provisioningOptions); ((ZoneImpl)zones[i]).Shutdown(); } if (fTransportManager != null) { // Shutdown transports if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Info("Shutting down Transports..."); } fTransportManager.Shutdown(); } // Close RequestCache try { RequestCache rc = RequestCache.GetInstance(this); if (rc != null) { rc.Close(); } } catch { // Do nothing } if ((Adk.Debug & AdkDebugFlags.Lifecycle) != 0) { Log.Debug("Agent shutdown complete"); } } finally { fInit = false; fShutdown = true; } }
private void ProfiledEnumeratorOnEnumerationEnded(object sender, ProfiledEnumerator <TDocument> .EnumerationEndedEventArgs enumerationEndedEventArgs) { BsonValue hint = null, orderBy = null; var hasHint = Options != null && Options.TryGetValue("$hint", out hint); var hasOrderBy = Options != null && Options.TryGetValue("$orderby", out orderBy); var commandStringBuilder = new StringBuilder(1024); commandStringBuilder.Append(Collection.Name); commandStringBuilder.Append(".find("); if (Query != null) { commandStringBuilder.Append("query"); } if (Fields != null) { commandStringBuilder.Append(",fields"); } commandStringBuilder.Append(")"); if (hasOrderBy) { commandStringBuilder.Append(".sort(orderBy)"); } if (hasHint) { commandStringBuilder.Append(".hint(hint)"); } if (Skip != 0) { commandStringBuilder.AppendFormat(".skip({0})", Skip); } if (Limit != 0) { commandStringBuilder.AppendFormat(".limit({0})", Limit); } if (Query != null) { commandStringBuilder.AppendFormat("\nquery = {0}", Query.ToBsonDocument()); } if (Fields != null) { commandStringBuilder.AppendFormat("\nfields = {0}", Fields.ToBsonDocument()); } if (hasOrderBy) { commandStringBuilder.AppendFormat("\norderBy = {0}", orderBy.ToBsonDocument()); } if (hasHint) { commandStringBuilder.AppendFormat("\nhint = {0}", hint.ToBsonDocument()); } // TODO: implement other options printout if needed string commandString = commandStringBuilder.ToString(); ProfilerUtils.AddMongoTiming(commandString, (long)enumerationEndedEventArgs.Elapsed.TotalMilliseconds, ExecuteType.Read); }