コード例 #1
0
        private DbProfilingRecord GetProfilingRecord(MiniProfiler profiler)
        {
            // Profiling record
            DbProfilingRecord dbProfilingRecord = new DbProfilingRecord();

            dbProfilingRecord.Name         = profiler.Name;
            dbProfilingRecord.Url          = profiler.Url;
            dbProfilingRecord.Referer      = profiler.Referer;
            dbProfilingRecord.Action       = profiler.Action;
            dbProfilingRecord.Event        = profiler.Event;
            dbProfilingRecord.ClientIP     = profiler.ClientIP;
            dbProfilingRecord.ClientAgent  = profiler.ClientAgent;
            dbProfilingRecord.RequestID    = profiler.RequestID;
            dbProfilingRecord.ActiveUser   = profiler.ActiveUser;
            dbProfilingRecord.MachineName  = profiler.MachineName;
            dbProfilingRecord.Started      = profiler.Started;
            dbProfilingRecord.Duration     = profiler.DurationMilliseconds;
            dbProfilingRecord.ResponseSize = profiler.ResponseSize;
            dbProfilingRecord.RequestSize  = profiler.RequestSize;
            dbProfilingRecord.Exception    = profiler.Exception;
            dbProfilingRecord.SessionID    = profiler.SessionID;

            // Client tracking
            dbProfilingRecord.ClientRequestID          = profiler.ClientRequestID;
            dbProfilingRecord.ClientTotalDuration      = profiler.ClientTotalDuration;
            dbProfilingRecord.ClientRedirectDuration   = profiler.ClientRedirectDuration;
            dbProfilingRecord.ClientDnsDuration        = profiler.ClientDnsDuration;
            dbProfilingRecord.ClientConnectionDuration = profiler.ClientConnectionDuration;
            dbProfilingRecord.ClientRequestDuration    = profiler.ClientRequestDuration;
            dbProfilingRecord.ClientResponseDuration   = profiler.ClientResponseDuration;
            dbProfilingRecord.ClientDomDuration        = profiler.ClientDomDuration;
            dbProfilingRecord.ClientLoadDuration       = profiler.ClientLoadDuration;

            dbProfilingRecord.Timings = new List <DbProfilingTimingRecord>();

            // Child timings
            foreach (var child in profiler.Timings)
            {
                DbProfilingTimingRecord dbProfilingTimingRecord = new DbProfilingTimingRecord();

                dbProfilingTimingRecord.Name         = child.Name;
                dbProfilingTimingRecord.SQL          = child.SQL;
                dbProfilingTimingRecord.StartOffset  = child.StartMilliseconds;
                dbProfilingTimingRecord.Duration     = child.DurationMilliseconds;
                dbProfilingTimingRecord.DataSize     = child.DataSize;
                dbProfilingTimingRecord.DataRowCount = child.DataRowCount;

                dbProfilingRecord.Timings.Add(dbProfilingTimingRecord);
            }

            return(dbProfilingRecord);
        }
コード例 #2
0
        public void SaveTimingRecord(DbConnection connection, DbProfilingRecord profiler, DbProfilingTimingRecord timing)
        {
            const string sql =
                @"INSERT INTO [ProfilingTiming]
				   ([ProfilingId],
				   [Name],
				   [SQL],
				   [StartOffset],
				   [Duration],
				   [DataSize],
				   [DataRowCount])
				 VALUES (
					@ProfilingId,
					@Name,
					@SQL,
					@StartOffset,
					@Duration,
				    @DataSize,
				    @DataRowCount)

				SELECT SCOPE_IDENTITY()"                ;

            using (var conn = DataHelper.GetOpenConnection())
            {
                // Connection created succesfully? It should be the case always, but...
                if (conn == null)
                {
                    throw new Exception("Mini Profiler Error. Couldn't create connection to database. Suspending...");
                }

                // Create command
                DbCommand cmd = conn.CreateCommand();

                // Command created succesfully?
                if (cmd == null)
                {
                    throw new Exception("Mini Profiler Error. Couldn't create command. Suspending...");
                }

                cmd.CommandText = sql;

                cmd.Parameters.Add(new SqlParameter("ProfilingId", profiler.ProfilingId));
                cmd.Parameters.Add(new SqlParameter("Name", timing.Name.Truncate(128)));
                cmd.Parameters.Add(new SqlParameter("SQL", timing.SQL.ToDBNull()));
                cmd.Parameters.Add(new SqlParameter("StartOffset", timing.StartOffset));
                cmd.Parameters.Add(new SqlParameter("Duration", timing.Duration));
                cmd.Parameters.Add(new SqlParameter("DataSize", timing.DataSize));
                cmd.Parameters.Add(new SqlParameter("DataRowCount", timing.DataRowCount));

                timing.TimingId = cmd.ExecuteScalar().ToInt();
            }
        }