public void LogCommandExecution(LogItem item, bool fullLogging)
        {
            long commandTextHash = item.CommandText.GetHashCode();
            var statement = this.StatementRepository.Query(Projection.BaseTable)
                .Where(StatementFields.CommandTextHash, commandTextHash)
                .And(StatementFields.CommandText, item.CommandText).ToList().FirstOrDefault();

            string parametersAsString = item.Params;
            if (statement == null)
            {
                statement = new Statement();
                statement.CommandText = item.CommandText;
                statement.CommandTextHash = commandTextHash;
                statement.ExecutionCount = 1;
                statement.MaxTime = item.ExecutionTime.TotalMilliseconds;
                statement.MaxTimeParams = parametersAsString;
                statement.MinTime = item.ExecutionTime.TotalMilliseconds;
                statement.MinTimeParams = parametersAsString;
                statement.SampleParams = parametersAsString;
                statement.SampleTime = item.ExecutionTime.TotalMilliseconds;
                statement.TotalTime = item.ExecutionTime.TotalMilliseconds;
                this.Insert(statement);
            }
            else
            {
                statement.ExecutionCount += 1;
                statement.TotalTime += item.ExecutionTime.TotalMilliseconds;

                if (item.ExecutionTime.TotalMilliseconds > statement.MaxTime)
                {
                    statement.MaxTime = item.ExecutionTime.TotalMilliseconds;
                    statement.MaxTimeParams = parametersAsString;
                }
                if (item.ExecutionTime.TotalMilliseconds < statement.MinTime)
                {
                    statement.MinTime = item.ExecutionTime.TotalMilliseconds;
                    statement.MinTimeParams = parametersAsString;
                }

                double avgTime = statement.TotalTime / statement.ExecutionCount;

                if (Math.Abs(avgTime - item.ExecutionTime.TotalMilliseconds) < Math.Abs(avgTime - statement.SampleTime))
                {
                    statement.SampleTime = item.ExecutionTime.TotalMilliseconds;
                    statement.SampleParams = parametersAsString;
                }

                this.Update(statement);
            }

            if (fullLogging)
            {
                var exec = new Execution();
                exec.ExecutionDate = DateTime.Now;
                exec.ExecutionTime = item.ExecutionTime.TotalMilliseconds;
                exec.StatementId = statement.StatementId;
                this.Insert(exec);
            }
        }
예제 #2
0
 public void LogCommandExecution(DbCommand command, DataService dataService, TimeSpan executionTime)
 {
     if (!IsRunning || dataService is SqliteProfilerDataService) return;
     var item = new LogItem
     {
         CommandText = command.CommandText,
         ExecutionTime = executionTime,
         Params = command.GetParamsAsString()
     };
     logItems.Enqueue(item);
     signal.Set();
 }