public async override Task Invoke(AspectContext context, AspectDelegate next) { var profilers = context.ServiceProvider.ResolveMany <IProfiler <RedisProfilingContext> >(); if (profilers.Any()) { var connectionMultiplexer = context.ServiceProvider.ResolveRequired <IConnectionMultiplexer>(); var profilerContext = new object(); AspectRedisDatabaseProfilerContext.Context = profilerContext; connectionMultiplexer.BeginProfiling(profilerContext); await context.Invoke(next); var profiledResult = connectionMultiplexer.FinishProfiling(profilerContext); var redisProfiledCommands = profiledResult.Select(x => RedisProfilingCommand.Create( x.Command, x.EndPoint, x.Db, x.CommandCreated, x.CreationToEnqueued, x.EnqueuedToSending, x.SentToResponse, x.ResponseToCompletion, x.ElapsedTime, connectionMultiplexer.ClientName, connectionMultiplexer.OperationCount)).ToArray(); foreach (var profiler in profilers) { profiler.Invoke(new RedisProfilingContext(redisProfiledCommands)); } AspectRedisDatabaseProfilerContext.Context = null; } else { await context.Invoke(next); } }
internal static RedisProfilingCommand Create(string command, EndPoint server, int db, DateTime commandCreated, TimeSpan creationToEnqueued, TimeSpan enqueuedToSending, TimeSpan sentToResponse, TimeSpan responseToCompletion, TimeSpan elapsed, string clientName, long operationCount) { var redisProfilingCommand = new RedisProfilingCommand(); redisProfilingCommand.Command = command; redisProfilingCommand.Server = server; redisProfilingCommand.Db = db; redisProfilingCommand.CommandCreated = commandCreated; redisProfilingCommand.Elapsed = elapsed; redisProfilingCommand.CreationToEnqueued = creationToEnqueued; redisProfilingCommand.EnqueuedToSending = enqueuedToSending; redisProfilingCommand.SentToResponse = enqueuedToSending; redisProfilingCommand.ResponseToCompletion = responseToCompletion; redisProfilingCommand.ClientName = clientName; redisProfilingCommand.OperationCount = operationCount; return(redisProfilingCommand); }