Ejemplo n.º 1
0
        private void InterceptTaskWithResult <TResult>(IInvocation invocation)
        {
            var ctx             = new ProfilingContext();
            var invocationClone = invocation.Clone();

            invocation.ReturnValue = Task.Run(() => BeforeInvoke(ctx, invocation))
                                     .ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    throw t.Exception;
                }

                invocationClone.Proceed();
                return(invocationClone.ReturnValue as Task <TResult>);
            })
                                     .Unwrap()
                                     .ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    throw t.Exception;
                }

                invocationClone.ReturnValue = t.Result;
                AfterInvoke(ctx, invocationClone);
                return((TResult)invocationClone.ReturnValue);
            });
        }
Ejemplo n.º 2
0
        void IInvocationProfiler.BeginMeasure(ProfilingContext ctx, IInvocation invocation)
        {
            string typeName   = invocation.Request.Method.DeclaringType.FullName;
            string methodName = invocation.Request.Method.Name;

            ctx.Timer = Stopwatch.StartNew();
            ctx.Data  = new List <object>(invocation.Request.Arguments);
            ctx.Data.Add($"{typeName}.{methodName}");
        }
Ejemplo n.º 3
0
        void IInvocationProfiler.Measure(IInvocation invocation)
        {
            var ctx      = new ProfilingContext();
            var profiler = this as IInvocationProfiler;

            profiler.BeginMeasure(ctx, invocation);
            invocation.Proceed();
            profiler.EndMeasure(ctx, invocation);
        }
Ejemplo n.º 4
0
        void IInvocationProfiler.EndMeasure(ProfilingContext ctx, IInvocation invocation)
        {
            ctx.Timer.Stop();
            ctx.Data.Add(invocation.ReturnValue);

            var snapshot = new Snapshot(ctx.Timer.Elapsed, ctx.Data.ToArray());

            _snapshots.Add(snapshot);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Takes profile action after the invocation proceeds
 /// </summary>
 /// <param name="ctx">The context of current profiling</param>
 /// <param name="invocation">The invocation that is being intercepted</param>
 private void AfterInvoke(ProfilingContext ctx, IInvocation invocation)
 {
     Profiler.EndMeasure(ctx, invocation);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Takes profile action before the invocation proceeds
 /// </summary>
 /// <param name="ctx">The context of current profiling</param>
 /// <param name="invocation">The invocation that is being intercepted</param>
 private void BeforeInvoke(ProfilingContext ctx, IInvocation invocation)
 {
     Profiler.BeginMeasure(ctx, invocation);
 }