Пример #1
0
        private DatabaseOperationContext Prepare(string info, string spName, string[] parameters, object[] values)
        {
            DatabaseOperationContext ctx = new DatabaseOperationContext();

            ctx.Info       = info;
            ctx.SpName     = spName;
            ctx.Parameters = parameters;
            ctx.Values     = values;
            ctx.Ex         = null;
            ctx.Watch      = Stopwatch.StartNew();

            if (parameters != null && values != null && parameters.Length != values.Length)
            {
                string msg = string.Format("{0} Parameters({1}) != Values({2})", spName, parameters.Length, values.Length);
                throw new InvalidOperationException(msg);
            }

            ctx.Operation = GetInnerOperation();
            TracingManager.Info(
                delegate() {
                _tracing.Info(info + ":\r\n" + ctx.Operation.FormatSql(spName, parameters, values));
            }
                );

            ctx.Observer = GetObserverItem(spName);

            _perfCounters.CommandExecutedTotal.Increment();
            _perfCounters.CommandExecutedPerSec.Increment();
            return(ctx);
        }
Пример #2
0
        internal void OnException(DatabaseOperationContext ctx, Exception ex)
        {
            ctx.Ex = ex;
            _perfCounters.CommandFailedTotal.Increment();

            _tracing.ErrorFmt(ex, "{0} Failed in {1} \r\n{2}",
                              ctx.Info,
                              _configItem.Name,
                              ctx.Operation.FormatSql(ctx.SpName, ctx.Parameters, ctx.Values));
        }
Пример #3
0
        internal void OnFinally(DatabaseOperationContext ctx)
        {
            int elapseMs = Convert.ToInt32(ctx.Watch.ElapsedMilliseconds);

            ctx.Observer.Track(ctx.Ex == null, ctx.Ex, ctx.Watch.ElapsedTicks);
            if (elapseMs > SlowSqlTimeout)
            {
                _tracing.ErrorFmt("{0} SlowSql({1}) in {2} cost {3}ms",
                                  ctx.Info,
                                  ctx.Operation.FormatSql(ctx.SpName, ctx.Parameters, ctx.Values),
                                  _configItem.Name,
                                  elapseMs);
            }
            _perfCounters.AvgExecuteMs.IncrementBy(elapseMs);
        }