本文整理汇总了C#中Stopwatch.TimeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Stopwatch.TimeAsync方法的具体用法?C# Stopwatch.TimeAsync怎么用?C# Stopwatch.TimeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.TimeAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PruneBlock
private async Task PruneBlock(PruningMode mode, Chain chain, ChainedHeader pruneBlock)
{
//TODO the replay information about blocks that have been rolled back also needs to be pruned (UnmintedTx)
var txCount = 0;
var totalStopwatch = Stopwatch.StartNew();
var pruneBlockTxesStopwatch = new Stopwatch();
var pruneTxIndexStopwatch = new Stopwatch();
var pruneSpentTxesStopwatch = new Stopwatch();
// retrieve the spent txes for this block
BlockSpentTxes spentTxes;
using (var handle = this.storageManager.OpenChainStateCursor())
{
var chainStateCursor = handle.Item;
chainStateCursor.BeginTransaction(readOnly: true);
chainStateCursor.TryGetBlockSpentTxes(pruneBlock.Height, out spentTxes);
}
if (spentTxes != null)
{
txCount = spentTxes.Count;
pruneBlockTxesStopwatch.Start();
pruneTxIndexStopwatch.Start();
await Task.WhenAll(
// prune block txes (either merkle prune or delete)
PruneBlockTxesAsync(mode, chain, pruneBlock, spentTxes)
.ContinueWith(_ => pruneBlockTxesStopwatch.Stop()),
// prune tx index
PruneTxIndexAsync(mode, chain, pruneBlock, spentTxes)
.ContinueWith(_ => pruneTxIndexStopwatch.Stop())
);
// remove block spent txes information
//TODO should have a buffer on removing this, block txes pruning may need it again if flush doesn't happen
var pruneSpentTxesTask = PruneBlockSpentTxes(mode, chain, pruneBlock);
await pruneSpentTxesStopwatch.TimeAsync(pruneSpentTxesTask);
}
// if spent txes aren't available, block txes can still be deleted entirely for that pruning style
else if (mode.HasFlag(PruningMode.BlockTxesDelete))
{
pruneBlockTxesStopwatch.Start();
await PruneBlockTxesAsync(mode, chain, pruneBlock, null);
pruneBlockTxesStopwatch.Stop();
}
else //if (pruneBlock.Height > 0)
{
//TODO can't throw an exception unless the pruned chain is persisted
//logger.Info("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: {0:N0}".Format2(pruneBlock.Height));
//throw new InvalidOperationException();
txCount = 0;
}
// track stats
txCountMeasure.Tick(txCount);
txRateMeasure.Tick((float)(txCount / totalStopwatch.Elapsed.TotalSeconds));
pruneBlockTxesDurationMeasure.Tick(pruneBlockTxesStopwatch.Elapsed);
pruneTxIndexDurationMeasure.Tick(pruneTxIndexStopwatch.Elapsed);
pruneSpentTxesDurationMeasure.Tick(pruneSpentTxesStopwatch.Elapsed);
totalDurationMeasure.Tick(totalStopwatch.Elapsed);
}