public static UIElement CreateTimedButtonAsync(MemberInfo methodToLink, object bindingObject, Dictionary <string, object> options = null) { var e = new System.Windows.Controls.Button(); AbstractModule m = options["currentModule"] as AbstractModule; var del = (Func <Task>)Delegate.CreateDelegate(typeof(Func <Task>), bindingObject, methodToLink as MethodInfo); e.Click += async(o, i) => await TimedAction(del, m, m.Iterations).Invoke(); e.Content = methodToLink.Name; return(e); // Lokale Methode: "Wrappt" die zu ausführende Methode mit einer Stopwatch und erlaubt es X iterationen durchzuführen Func <Task> TimedAction(Func <Task> a, AbstractModule target, object iter) { var s = new Stopwatch(); return(new Func <Task>(async() => await s.TimeAsync(() => a(), iter, target))); } }
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); }
/************************** * ===== Worker Loops ===== **************************/ private async Task DoDownloadWork(object state) { TaskState taskState = (TaskState)state; Stopwatch stopwatch = new Stopwatch(); while (active && downloadersActive) { taskState.Status = State.Running; if (!await CanDownload()) { taskState.Status = State.Paused; await Task.Delay(500); continue; } if (!PageDownloadingQueue.IsEmpty) { RobloxThread thread; if (!PageDownloadingQueue.TryDequeue(out thread)) { //Another thread grabbed the item before we did, continue other work continue; } try { await stopwatch.TimeAsync( async() => await DownloadThreadPage(thread), async (long time) => TelemetryManager.Incriment(TelemetryType.downloaded_pages, taskState.Id, time) ); } catch (Exception ex) { taskState.Status = State.Error; active = false; exception = ex; break; } continue; } if (!ThreadQueue.IsEmpty) { int id; if (!ThreadQueue.TryDequeue(out id)) { //Nothing left in queue? //TODO: Handle end conditions continue; } try { await stopwatch.TimeAsync( async() => await DownloadThread(id), async (long time) => TelemetryManager.Incriment(TelemetryType.downloaded_threads, taskState.Id, time) ); } catch (Exception ex) { taskState.Status = State.Error; active = false; exception = ex; break; } } else { downloadersActive = false; break; } } taskState.Status = State.Complete; }