Esempio n. 1
0
        private void Track(IIncomingGrainCallContext context, Stopwatch stopwatch, bool isException)
        {
            try
            {
                stopwatch.Stop();

                var elapsedMs = stopwatch.Elapsed.TotalMilliseconds;

                var grainMethodName = formatMethodName(context);

                //必须要这个
                if (context.Grain.GetType().GetCustomAttribute <TraceGrainAttribute>() != null)
                {
                    if (context.Grain.GetType().GetCustomAttribute <MultiGrainAttribute>() == null)
                    {
                        profiler.Track(elapsedMs, context.Grain.GetType(), string.Empty, grainMethodName, isException);
                    }
                    else
                    {
                        string identity = string.Empty;
                        if (context.Grain.GetPrimaryKeyString() == null)
                        {
                            identity = context.Grain.GetPrimaryKeyLong().ToString();
                        }
                        else
                        {
                            identity = context.Grain.GetPrimaryKeyString();
                        }

                        profiler.Track(elapsedMs, context.Grain.GetType(), identity, grainMethodName, isException);
                    }
                }
                else
                {
                    profiler.Track(elapsedMs, context.Grain.GetType(), string.Empty, grainMethodName, isException);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(100002, ex, "error recording results for grain");
            }
        }
        public static async Task TrackAsync <T>(this IGrainProfiler profiler, Func <Task> handler, [CallerMemberName] string methodName = null)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                await handler();

                stopwatch.Stop();

                profiler.Track(stopwatch.Elapsed.TotalMilliseconds, typeof(T), methodName);
            }
            catch (Exception)
            {
                stopwatch.Stop();

                profiler.Track(stopwatch.Elapsed.TotalMilliseconds, typeof(T), methodName, true);
                throw;
            }
        }
Esempio n. 3
0
        private void Track(IIncomingGrainCallContext context, Stopwatch stopwatch, bool isException)
        {
            try
            {
                stopwatch.Stop();

                var elapsedMs = stopwatch.Elapsed.TotalMilliseconds;

                var grainMethodName = formatMethodName(context);

                profiler.Track(elapsedMs, context.Grain.GetType(), grainMethodName, isException);
            }
            catch (Exception ex)
            {
                logger.LogError(100002, ex, "error recording results for grain");
            }
        }
 public static void Track <T>(this IGrainProfiler profiler, double elapsedMs, [CallerMemberName] string methodName = null, bool failed = false)
 {
     profiler.Track(elapsedMs, typeof(T), methodName, failed);
 }