Пример #1
0
        public static SqlCounters operator +(SqlCounters one, SqlCounters two)
        {
            SqlCounters ret = new SqlCounters();

            ret.Duration  = one.Duration + two.Duration;
            ret.CPU       = one.CPU + two.CPU;
            ret.Reads     = one.Reads + two.Reads;
            ret.Writes    = one.Writes + two.Writes;
            ret.RowCounts = one.RowCounts + two.RowCounts;
            ret.Requests  = one.Requests + two.Requests;
            return(ret);
        }
Пример #2
0
        public TraceGroupsReport <TKey> ReadGroupsReport <TKey>(TraceColumns groupingField)
        {
            if ((_columns & groupingField) == 0)
            {
                throw new ArgumentException("Axis field " + groupingField + " is not included in trace", "groupingField");
            }

            TraceFieldInfo info = TraceFieldInfo.Get(groupingField);

            string sql = string.Format(
                SQL_SELECT_GROUPS,
                info.GroupExpression);

            using (SqlConnection con = new SqlConnection(_connectionString))
            {
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }

                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    cmd.Parameters.Add("@file", SqlDbType.NVarChar).Value = _traceFile + ".trc";
                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        TraceGroupsReport <TKey> ret = new TraceGroupsReport <TKey>();
                        while (rdr.Read())
                        {
                            object      rawKey   = rdr.IsDBNull(0) ? null : rdr.GetValue(0);
                            int         count    = rdr.GetInt32(1);
                            SqlCounters counters = ReadCounters(rdr, 2);
                            if (counters != null)
                            {
                                counters.Requests = count;
                                TKey key = (TKey)rawKey;
                                SqlGroupCounters <TKey> group =
                                    new SqlGroupCounters <TKey>()
                                {
                                    Group = key, Count = count, Counters = counters
                                };

                                ret.Add(key, group);
                            }
                        }

                        return(ret);
                    }
                }
            }
        }
        public void Filter(Predicate filter)
        {
            List <SqlStatementCounters> found = new List <SqlStatementCounters>();

            foreach (SqlStatementCounters detailsReport in this)
            {
                if (filter(detailsReport))
                {
                    found.Add(detailsReport);
                }
            }

            base.Items.Clear();
            foreach (SqlStatementCounters statementCounter in found)
            {
                base.Items.Add(statementCounter);
            }

            _Summary = null;
        }
Пример #4
0
        private static SqlCounters ReadCounters(SqlDataReader rdr, int startIndex)
        {
            SqlCounters ret     = new SqlCounters();
            bool        isNull0 = rdr.IsDBNull(startIndex + 0);
            bool        isNull1 = rdr.IsDBNull(startIndex + 1);
            bool        isNull2 = rdr.IsDBNull(startIndex + 2);
            bool        isNull3 = rdr.IsDBNull(startIndex + 3);
            bool        isNull4 = rdr.IsDBNull(startIndex + 4);

            if (isNull0 && isNull1 && isNull2 && isNull3)
            {
                return(null);
            }

            ret.Duration  = isNull0 ? 0 : rdr.GetInt64(startIndex + 0) / 1000;
            ret.CPU       = isNull1 ? 0 : rdr.GetInt32(startIndex + 1);
            ret.Reads     = isNull2 ? 0 : rdr.GetInt64(startIndex + 2);
            ret.Writes    = isNull3 ? 0 : rdr.GetInt64(startIndex + 3);
            ret.RowCounts = isNull4 ? 0 : rdr.GetInt64(startIndex + 4);
            return(ret);
        }