public void PublishNormalizedStatementRelationStatistics(LogEntryStatementRelationStatisticsData relationStatisticsData)
        {
            var key    = relationStatisticsData.NormalizedStatementFingerprint;
            var sample = new NormalizedStatementRelationStatistics()
            {
                AvgTotalCost    = relationStatisticsData.TotalCost,
                CreatedDate     = DateTime.Now,
                DatabaseID      = relationStatisticsData.DatabaseID,
                Date            = relationStatisticsData.ExecutionDate,
                RelationID      = relationStatisticsData.RelationID,
                MaxTotalCost    = relationStatisticsData.TotalCost,
                MinTotalCost    = relationStatisticsData.TotalCost,
                TotalScansCount = 1
            };

            lock (lockObject)
            {
                if (!statementRelationStatistics.ContainsKey(key))
                {
                    statementRelationStatistics.Add(key, new NormalizedStatementRelationStatisticsSampler(dateTimeSelector, null));
                }
            }
            lock (String.Intern(key))
            {
                statementRelationStatistics[key].AddSample(sample);
            }
        }
 public static void ApplySample(NormalizedStatementRelationStatistics cumulativeData, NormalizedStatementRelationStatistics newSample)
 {
     cumulativeData.MaxTotalCost = Math.Max(cumulativeData.MaxTotalCost, newSample.MaxTotalCost);
     cumulativeData.MinTotalCost = Math.Min(cumulativeData.MinTotalCost, newSample.MinTotalCost);
     if (cumulativeData.TotalScansCount > 0 || newSample.TotalScansCount > 0)
     {
         cumulativeData.AvgTotalCost = (cumulativeData.TotalScansCount * cumulativeData.AvgTotalCost
                                        + newSample.TotalScansCount * newSample.AvgTotalCost
                                        )
                                       / (cumulativeData.TotalScansCount + newSample.TotalScansCount);
     }
     else
     {
         cumulativeData.AvgTotalCost = newSample.AvgTotalCost;
     }
     cumulativeData.TotalScansCount += newSample.TotalScansCount;
 }
Ejemplo n.º 3
0
        private void PersistStatementRelationStatistics(NormalizedStatementRelationStatistics newStatistics)
        {
            var repository = repositories.GetNormalizedStatementRelationStatisticsRepository();
            var uniqueKey  = new NormalizedStatementRelationStatisticsUniqueKey()
            {
                DatabaseID            = newStatistics.DatabaseID,
                Date                  = newStatistics.Date,
                RelationID            = newStatistics.RelationID,
                NormalizedStatementID = newStatistics.NormalizedStatementID
            };
            var oldStatistics = repository.GetByUniqueKey(uniqueKey);

            if (oldStatistics == null)
            {
                repository.Create(newStatistics);
            }
            else
            {
                NormalizedStatementRelationStatisticsMergeUtility.ApplySample(oldStatistics, newStatistics);
                repository.Update(oldStatistics);
            }
        }