/// <summary>
        /// Creates a snapshot of the current state of the performance counter.
        /// </summary>
        /// <returns>Newly created snapshot.</returns>
        public BackendPerformanceSnapshot Snapshot()
        {
            var snap = new BackendPerformanceSnapshot(this.insertedEntities, this.insertTime, this.queriedEntities, this.queryTime)
            {
                Start = this.Start,
                // TODO: Would it not be better for these two guys to be part of the constructor? Either implicitly or explicitly.
                Taken = this.dateTimeProvider.GetUtcNow()
            };

            return(snap);
        }
Ejemplo n.º 2
0
        public BackendPerformanceSnapshot Snapshot()
        {
#if !(PORTABLE || NETCORE)
            Thread.MemoryBarrier();
#endif
            var snap = new BackendPerformanceSnapshot(this._InsertedEntities, this._InsertTime, this._QueriedEntities, this._QueryTime)
            {
                Start = this.Start,
                Taken = DateTime.UtcNow
            };
            return(snap);
        }
Ejemplo n.º 3
0
        private void AddBenchStats(StringBuilder log)
        {
            log.AppendLine(">> Leveldb Bench");

            BackendPerformanceSnapshot snapShot = this.performanceCounter.Snapshot();

            if (this.latestPerformanceSnapShot == null)
            {
                log.AppendLine(snapShot.ToString());
            }
            else
            {
                log.AppendLine((snapShot - this.latestPerformanceSnapShot).ToString());
            }

            this.latestPerformanceSnapShot = snapShot;
        }
Ejemplo n.º 4
0
        private void AddBenchStats(StringBuilder log)
        {
            this.logger.LogTrace("()");

            log.AppendLine("======DBreezeCoinView Bench======");

            BackendPerformanceSnapshot snapShot = this.performanceCounter.Snapshot();

            if (this.latestPerformanceSnapShot == null)
            {
                log.AppendLine(snapShot.ToString());
            }
            else
            {
                log.AppendLine((snapShot - this.latestPerformanceSnapShot).ToString());
            }

            this.latestPerformanceSnapShot = snapShot;

            this.logger.LogTrace("(-)");
        }
        /// <summary>
        /// Creates a snapshot based on difference of two performance counter snapshots.
        /// <para>
        /// This is used to obtain statistic information about performance of the backend
        /// during certain period.</para>
        /// </summary>
        /// <param name="end">Newer performance counter snapshot.</param>
        /// <param name="start">Older performance counter snapshot.</param>
        /// <returns>Snapshot of the difference between the two performance counter snapshots.</returns>
        /// <remarks>The two snapshots should be taken from a single performance counter.
        /// Otherwise the start times of the snapshots will be different, which is not allowed.</remarks>
        public static BackendPerformanceSnapshot operator -(BackendPerformanceSnapshot end, BackendPerformanceSnapshot start)
        {
            if (end.Start != start.Start)
            {
                throw new InvalidOperationException("Performance snapshot should be taken from the same point of time");
            }

            if (end.Taken < start.Taken)
            {
                throw new InvalidOperationException("The difference of snapshot can't be negative");
            }

            long insertedEntities = end.totalInsertedEntities - start.totalInsertedEntities;
            long insertTime       = end.totalInsertTime - start.totalInsertTime;
            long queriedEntities  = end.totalQueriedEntities - start.totalQueriedEntities;
            long queryTime        = end.totalQueryTime - start.totalQueryTime;
            var  snapshot         = new BackendPerformanceSnapshot(insertedEntities, insertTime, queriedEntities, queryTime)
            {
                Start = start.Taken,
                Taken = end.Taken
            };

            return(snapshot);
        }