private TraceGroupsReport <T> CreateDictionary <T>(GetKey <T> getKey)
        {
            TraceGroupsReport <T> ret = new TraceGroupsReport <T>();

            foreach (SqlStatementCounters counter in this)
            {
                T key = getKey(counter);
                SqlGroupCounters <T> value;
                if (!ret.TryGetValue(key, out value))
                {
                    value          = new SqlGroupCounters <T>();
                    value.Count    = 1;
                    value.Group    = key;
                    value.Counters = counter.Counters;
                    ret[key]       = value;
                }
                else
                {
                    value.Count++;
                    value.Counters = value.Counters + counter.Counters;
                }
            }

            return(ret);
        }
Exemple #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);
                    }
                }
            }
        }