public IndexingStatsScope(IndexingRunStats stats, bool start = true) { _stats = stats; _sw = new Stopwatch(); if (start) { Start(); } }
public IndexingStatsAggregator(int id, IndexingStatsAggregator lastStats) { Id = id; var now = SystemTime.UtcNow; if (lastStats == null) { StartTime = now; } else { var lastCompleted = lastStats.StartTime.Add(lastStats._scope.Duration); // due to different precision of DateTimes and Stopwatches we might have current date // smaller than completed one of the latest batch // let us adjust current start to avoid overlapping on the performance graph StartTime = lastCompleted > now ? lastCompleted : now; } _stats = new IndexingRunStats(); }
public unsafe IndexFailureInformation UpdateStats(DateTime indexingTime, IndexingRunStats stats) { if (_logger.IsInfoEnabled) { _logger.Info($"Updating statistics for '{_index.Name}'. Stats: {stats}."); } using (_contextPool.AllocateOperationContext(out TransactionOperationContext context)) using (var tx = context.OpenWriteTransaction()) { var result = new IndexFailureInformation { Name = _index.Name }; var table = tx.InnerTransaction.OpenTable(_errorsSchema, "Errors"); var statsTree = tx.InnerTransaction.ReadTree(IndexSchema.StatsTree); result.MapAttempts = statsTree.Increment(IndexSchema.MapAttemptsSlice, stats.MapAttempts); result.MapSuccesses = statsTree.Increment(IndexSchema.MapSuccessesSlice, stats.MapSuccesses); result.MapErrors = statsTree.Increment(IndexSchema.MapErrorsSlice, stats.MapErrors); var currentMaxNumberOfOutputs = statsTree.Read(IndexSchema.MaxNumberOfOutputsPerDocument)?.Reader.ReadLittleEndianInt32(); using (statsTree.DirectAdd(IndexSchema.MaxNumberOfOutputsPerDocument, sizeof(int), out byte *ptr)) { *(int *)ptr = currentMaxNumberOfOutputs > stats.MaxNumberOfOutputsPerDocument ? currentMaxNumberOfOutputs.Value : stats.MaxNumberOfOutputsPerDocument; } if (_index.Type.IsMapReduce()) { result.ReduceAttempts = statsTree.Increment(IndexSchema.ReduceAttemptsSlice, stats.ReduceAttempts); result.ReduceSuccesses = statsTree.Increment(IndexSchema.ReduceSuccessesSlice, stats.ReduceSuccesses); result.ReduceErrors = statsTree.Increment(IndexSchema.ReduceErrorsSlice, stats.ReduceErrors); } var binaryDate = indexingTime.ToBinary(); using (Slice.External(context.Allocator, (byte *)&binaryDate, sizeof(long), out Slice binaryDateslice)) statsTree.Add(IndexSchema.LastIndexingTimeSlice, binaryDateslice); if (stats.Errors != null) { for (var i = Math.Max(stats.Errors.Count - MaxNumberOfKeptErrors, 0); i < stats.Errors.Count; i++) { var error = stats.Errors[i]; var ticksBigEndian = Bits.SwapBytes(error.Timestamp.Ticks); using (var document = context.GetLazyString(error.Document)) using (var action = context.GetLazyString(error.Action)) using (var e = context.GetLazyString(error.Error)) { var tvb = new TableValueBuilder { { (byte *)&ticksBigEndian, sizeof(long) }, { document.Buffer, document.Size }, { action.Buffer, action.Size }, { e.Buffer, e.Size } }; table.Insert(tvb); } } CleanupErrors(table); } tx.Commit(); return(result); } }