Esempio n. 1
0
        public void PerformanceTimeCheck(
            )
        {
            StopWatch.Stop();
            if (StopWatch.ElapsedMilliseconds > 500)
            {
                var performance = new CrudeDefaultPerformanceTimeData();
                performance.CommandName   = MethodName;
                performance.Milliseconds  = ( int )StopWatch.ElapsedMilliseconds;
                performance.DefaultUserId = UserId;
                performance.DateTime      = DateTime.UtcNow;
                performance.Insert();
            }

            if (StopWatch.ElapsedMilliseconds > 500)
            {
                var performance = new CrudeDefaultPerformanceIssueData();
                performance.CommandName   = MethodName;
                performance.CommandText   = _sql;
                performance.Milliseconds  = ( int )StopWatch.ElapsedMilliseconds;
                performance.DefaultUserId = UserId;
                performance.DateTime      = DateTime.UtcNow;
                performance.Insert();
            }
        }
Esempio n. 2
0
        public void PerformanceTimeStop(
            int logIfMoreThanMilliseconds
            )
        {
            StopWatch.Stop();
            StopUTC = DateTime.UtcNow;

            if (StopWatch.ElapsedMilliseconds > logIfMoreThanMilliseconds)
            {
                var performance = new CrudeDefaultPerformanceTimeData();
                performance.CommandName   = MethodName;
                performance.Milliseconds  = ( int )StopWatch.ElapsedMilliseconds;
                performance.DefaultUserId = UserId;
                performance.DateTime      = DateTime.UtcNow;
                performance.Insert();

                // update rollup
                int hits = 0;
                using (var conn = new SqlConnection(Conn.ConnectionString)) {
                    conn.Open();
                    using (var command = new SqlCommand(@" 
                                update [default_performance_time_rollup] set
                                        milliseconds = milliseconds + @milliseconds
                                    ,hits = hits + 1
                                where command_name = @command_name
                                ",
                                                        conn
                                                        )) {
                        command.Parameters.Add("@command_name", SqlDbType.NVarChar).Value = MethodName;
                        command.Parameters.Add("@milliseconds", SqlDbType.BigInt).Value   = ( int )StopWatch.ElapsedMilliseconds;

                        hits = command.ExecuteNonQuery();
                    }
                }

                if (hits == 0)
                {
                    // no hits, insert instead
                    using (var conn = new SqlConnection(Conn.ConnectionString)) {
                        conn.Open();
                        using (var command = new SqlCommand(@"
                                insert into [default_performance_time_rollup] (default_performance_time_rollup_id, command_name, milliseconds, hits, date_time, default_user_id)
                                        values (newid(), @command_name, @milliseconds, 1, getutcdate(), @user_id)
                                ",
                                                            conn
                                                            )) {
                            command.Parameters.Add("@command_name", SqlDbType.NVarChar).Value    = MethodName;
                            command.Parameters.Add("@milliseconds", SqlDbType.BigInt).Value      = ( int )StopWatch.ElapsedMilliseconds;
                            command.Parameters.Add("@user_id", SqlDbType.UniqueIdentifier).Value = UserId;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
        }