private void ProcessIndices(IEnumerable <IIndexStatistics> indices, DateTime collectedDate, bool isStatisticsResetDetected)
 {
     foreach (var i in indices)
     {
         var lastValue             = GetLastValue <IIndexStatistics>(i.ID);
         TotalIndexStatistics diff = null;
         if (!isStatisticsResetDetected && lastValue != null && !i.Equals(lastValue))
         {
             diff = new TotalIndexStatistics()
             {
                 CreatedDate          = DateTime.Now,
                 DatabaseID           = i.DatabaseID,
                 Date                 = collectedDate,
                 IndexID              = i.ID,
                 IndexScanCount       = Math.Max(i.IndexScanCount - lastValue.IndexScanCount, 0),
                 IndexTupleFetchCount = Math.Max(i.IndexTupleFetchCount - lastValue.IndexTupleFetchCount, 0),
                 IndexTupleReadCount  = Math.Max(i.IndexTupleReadCount - lastValue.IndexTupleReadCount, 0),
                 RelationID           = i.RelationID
             };
         }
         indexStatistics.AddOrUpdate(i.ID, new TotalIndexStatisticsSampler(dateTimeSelector, diff), (k, v) =>
         {
             if (diff != null)
             {
                 v.AddSample(diff);
             }
             return(v);
         });
         SaveLastValue(i.ID, i);
     }
 }
示例#2
0
        private void PersistTotalIndexStatistics(TotalIndexStatistics newStatistics)
        {
            var repository = repositories.GetTotalIndexStatisticsRepository();
            var uniqueKey  = new TotalIndexStatisticsUniqueKey()
            {
                DatabaseID = newStatistics.DatabaseID,
                Date       = newStatistics.Date,
                IndexID    = newStatistics.IndexID,
                RelationID = newStatistics.RelationID
            };
            var oldStatistics = repository.GetByUniqueKey(uniqueKey);

            if (oldStatistics == null)
            {
                repository.Create(newStatistics);
            }
            else
            {
                TotalIndexStatisticsMergeUtility.ApplySample(oldStatistics, newStatistics);
                repository.Update(oldStatistics);
            }
        }
 public static void ApplySample(TotalIndexStatistics cumulativeData, TotalIndexStatistics newSample)
 {
     cumulativeData.IndexScanCount       += newSample.IndexScanCount;
     cumulativeData.IndexTupleFetchCount += newSample.IndexTupleFetchCount;
     cumulativeData.IndexTupleReadCount  += newSample.IndexTupleReadCount;
 }