private void StartCounterCollection() { var task = Task.Factory.StartNew(async() => { var perfService = new PerfService(); while (true) { var results = perfService.GetResults(); Clients.All.newCounters(results); await Task.Delay(2000); } }, TaskCreationOptions.LongRunning); }
public async Task <bool> SendPing() { if (!_isInitialized) { return(true); } if (_pongCompletionSource != null) { if (Logger.IsWarn) { Logger.Warn($"Another ping request in process: {P2PSession.RemoteNodeId}"); } return(true); } _pongCompletionSource = new TaskCompletionSource <Packet>(); var pongTask = _pongCompletionSource.Task; if (Logger.IsTrace) { Logger.Trace($"{P2PSession.RemoteNodeId} P2P sending ping on {P2PSession.RemotePort} ({RemoteClientId})"); } Send(PingMessage.Instance); P2PSession?.NodeStats.AddNodeStatsEvent(NodeStatsEventType.P2PPingOut); var pingPerfCalcId = PerfService.StartPerfCalc(); var firstTask = await Task.WhenAny(pongTask, Task.Delay(Timeouts.P2PPing)); _pongCompletionSource = null; if (firstTask != pongTask) { return(false); } var latency = PerfService.EndPerfCalc(pingPerfCalcId); if (latency.HasValue) { P2PSession?.NodeStats.AddLatencyCaptureEvent(NodeLatencyStatType.P2PPingPong, latency.Value); } return(true); }
private async Task <BlockHeader[]> SendRequest(GetBlockHeadersMessage message, CancellationToken token) { if (Logger.IsTrace) { Logger.Trace("Sending headers request:"); Logger.Trace($"Starting blockhash: {message.StartingBlockHash}"); Logger.Trace($"Starting number: {message.StartingBlockNumber}"); Logger.Trace($"Skip: {message.Skip}"); Logger.Trace($"Reverse: {message.Reverse}"); Logger.Trace($"Max headers: {message.MaxHeaders}"); } var request = new Request <GetBlockHeadersMessage, BlockHeader[]>(message); _headersRequests.Add(request, token); var perfCalcId = PerfService.StartPerfCalc(); Send(request.Message); Task <BlockHeader[]> task = request.CompletionSource.Task; var firstTask = await Task.WhenAny(task, Task.Delay(Timeouts.Eth62, token)); if (firstTask.IsCanceled) { token.ThrowIfCancellationRequested(); } if (firstTask == task) { var latency = PerfService.EndPerfCalc(perfCalcId); if (latency.HasValue) { P2PSession?.NodeStats.AddLatencyCaptureEvent(NodeLatencyStatType.BlockHeaders, latency.Value); } return(task.Result); } // TODO: work in progress throw new TimeoutException($"{P2PSession.RemoteNodeId} Request timeout in {nameof(GetBlockHeadersMessage)}"); }
/// <summary> /// Render method renders the visual tree. /// </summary> void ICompositionTarget.Render(bool inResize, DUCE.Channel channel) { #if DEBUG_CLR_MEM bool clrTracingEnabled = false; if (CLRProfilerControl.ProcessIsUnderCLRProfiler && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance)) { clrTracingEnabled = true; ++_renderCLRPass; CLRProfilerControl.CLRLogWriteLine("Begin_FullRender_{0}", _renderCLRPass); } #endif // DEBUG_CLR_MEM // // Now we render the scene // #if MEDIA_PERFORMANCE_COUNTERS _frameRateTimer.Begin(); #endif if (_rootVisual.Value != null) { bool etwTracingEnabled = false; if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordGeneral | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info)) { etwTracingEnabled = true; EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientPrecomputeSceneBegin, EventTrace.Keyword.KeywordGraphics | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info, PerfService.GetPerfElementID(this)); } #if MEDIA_PERFORMANCE_COUNTERS _precomputeRateTimer.Begin(); #endif // precompute is channel agnostic _rootVisual.Value.Precompute(); #if MEDIA_PERFORMANCE_COUNTERS _precomputeRateTimer.End(); #endif if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientPrecomputeSceneEnd, EventTrace.Keyword.KeywordGraphics | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info); } #if DEBUG MediaTrace.RenderPass.Trace("Full Update"); #endif if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent( EventTrace.Event.WClientCompileSceneBegin, EventTrace.Keyword.KeywordGraphics | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info, PerfService.GetPerfElementID(this)); } #if MEDIA_PERFORMANCE_COUNTERS _renderRateTimer.Begin(); #endif Compile(channel); #if MEDIA_PERFORMANCE_COUNTERS _renderRateTimer.End(); #endif if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent( EventTrace.Event.WClientCompileSceneEnd, EventTrace.Keyword.KeywordGraphics | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info); } } #if DEBUG_CLR_MEM if (clrTracingEnabled && CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance) { CLRProfilerControl.CLRLogWriteLine("End_FullRender_{0}", _renderCLRPass); } #endif // DEBUG_CLR_MEM #if MEDIA_PERFORMANCE_COUNTERS _frameRateTimer.End(); System.Console.WriteLine("RENDERING PERFORMANCE DATA"); System.Console.WriteLine("Frame rendering time: " + _frameRateTimer.TimeOfLastPeriod + "ms"); System.Console.WriteLine("Frame precompute time: " + _precomputeRateTimer.TimeOfLastPeriod + "ms"); System.Console.WriteLine("Frame render time: " + _renderRateTimer.TimeOfLastPeriod + "ms"); #endif }
private static object Load(System.Xaml.XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) { XamlObjectWriter xamlWriter = null; XamlContextStack <WpfXamlFrame> stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame()); int persistId = 1; settings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args) { if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose)) { IXamlLineInfo ixli = xamlReader as IXamlLineInfo; int lineNumber = -1; int linePosition = -1; if (ixli != null && ixli.HasLineInfo) { lineNumber = ixli.LineNumber; linePosition = ixli.LinePosition; } EventTrace.EventProvider.TraceEvent( EventTrace.Event.WClientParseXamlBamlInfo, EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose, args.Instance == null ? 0 : PerfService.GetPerfElementID(args.Instance), lineNumber, linePosition); } UIElement uiElement = args.Instance as UIElement; if (uiElement != null) { uiElement.SetPersistId(persistId++); } XamlSourceInfoHelper.SetXamlSourceInfo(args.Instance, args, baseUri); DependencyObject dObject = args.Instance as DependencyObject; if (dObject != null && stack.CurrentFrame.XmlnsDictionary != null) { XmlnsDictionary dictionary = stack.CurrentFrame.XmlnsDictionary; dictionary.Seal(); XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary); } stack.CurrentFrame.Instance = args.Instance; }; if (writerFactory != null) { xamlWriter = writerFactory.GetXamlObjectWriter(settings); } else { xamlWriter = new System.Xaml.XamlObjectWriter(xamlReader.SchemaContext, settings); } IXamlLineInfo xamlLineInfo = null; try { //Handle Line Numbers xamlLineInfo = xamlReader as IXamlLineInfo; IXamlLineInfoConsumer xamlLineInfoConsumer = xamlWriter as IXamlLineInfoConsumer; bool shouldPassLineNumberInfo = false; if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) && (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo)) { shouldPassLineNumberInfo = true; } IStyleConnector styleConnector = rootObject as IStyleConnector; TransformNodes(xamlReader, xamlWriter, false /*onlyLoadOneNode*/, skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, stack, styleConnector); xamlWriter.Close(); return(xamlWriter.Result); } catch (Exception e) { // Don't wrap critical exceptions or already-wrapped exceptions. if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !XamlReader.ShouldReWrapException(e, baseUri)) { throw; } XamlReader.RewrapException(e, xamlLineInfo, baseUri); return(null); // this should never be executed } }
/// <summary> /// Tells ContextLayoutManager to finalize possibly async update. /// Used before accessing services off Visual. /// </summary> //[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking internal void UpdateLayout() { VerifyAccess(); //make UpdateLayout to be a NOP if called during UpdateLayout. if (_isInUpdateLayout || _measuresOnStack > 0 || _arrangesOnStack > 0 || _isDead) { return; } #if DEBUG_CLR_MEM bool clrTracingEnabled = false; // Start over with the Measure and arrange counters for this layout pass int measureCLRPass = 0; int arrangeCLRPass = 0; if (CLRProfilerControl.ProcessIsUnderCLRProfiler) { clrTracingEnabled = true; if (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance) { ++_layoutCLRPass; CLRProfilerControl.CLRLogWriteLine("Begin_Layout_{0}", _layoutCLRPass); } } #endif // DEBUG_CLR_MEM bool etwTracingEnabled = false; long perfElementID = 0; const EventTrace.Keyword etwKeywords = EventTrace.Keyword.KeywordLayout | EventTrace.Keyword.KeywordPerf; if (!_isUpdating && EventTrace.IsEnabled(etwKeywords, EventTrace.Level.Info)) { etwTracingEnabled = true; perfElementID = PerfService.GetPerfElementID(this); EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientLayoutBegin, etwKeywords, EventTrace.Level.Info, perfElementID, EventTrace.LayoutSource.LayoutManager); } int cnt = 0; bool gotException = true; UIElement currentElement = null; try { invalidateTreeIfRecovering(); while (hasDirtiness || _firePostLayoutEvents) { if (++cnt > 153) { //loop detected. Lets go over to background to let input/user to correct the situation. //most frequently, we get such a loop as a result of input detecting a mouse in the "bad spot" //and some event handler oscillating a layout-affecting property depending on hittest result //of the mouse. Going over to background will not break the loopp but will allow user to //move the mouse so that it goes out of the "bad spot". Dispatcher.BeginInvoke(DispatcherPriority.Background, _updateLayoutBackground, this); currentElement = null; gotException = false; if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientLayoutAbort, etwKeywords, EventTrace.Level.Info, 0, cnt); } return; } //this flag stops posting update requests to MediaContext - we are already in one //note that _isInUpdateLayout is close but different - _isInUpdateLayout is reset //before firing LayoutUpdated so that event handlers could call UpdateLayout but //still could not cause posting of MediaContext work item. Posting MediaContext workitem //causes infinite loop in MediaContext. _isUpdating = true; _isInUpdateLayout = true; #if DEBUG_CLR_MEM if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Verbose)) { ++measureCLRPass; CLRProfilerControl.CLRLogWriteLine("Begin_Measure_{0}_{1}", _layoutCLRPass, measureCLRPass); } #endif // DEBUG_CLR_MEM if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientMeasureBegin, etwKeywords, EventTrace.Level.Info, perfElementID); } // Disable processing of the queue during blocking operations to prevent unrelated reentrancy. using (Dispatcher.DisableProcessing()) { //loop for Measure //We limit the number of loops here by time - normally, all layout //calculations should be done by this time, this limit is here for //emergency, "infinite loop" scenarios - yielding in this case will //provide user with ability to continue to interact with the app, even though //it will be sluggish. If we don't yield here, the loop is goign to be a deadly one //and it will be impossible to save results or even close the window. int loopCounter = 0; DateTime loopStartTime = new DateTime(0); while (true) { if (++loopCounter > 153) { loopCounter = 0; //first bunch of iterations is free, then we start count time //this way, we don't call DateTime.Now in most layout updates if (loopStartTime.Ticks == 0) { loopStartTime = DateTime.UtcNow; } else { TimeSpan loopDuration = (DateTime.UtcNow - loopStartTime); if (loopDuration.Milliseconds > 153 * 2) // 153*2 = magic*science { //loop detected. Lets go over to background to let input work. Dispatcher.BeginInvoke(DispatcherPriority.Background, _updateLayoutBackground, this); currentElement = null; gotException = false; if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientMeasureAbort, etwKeywords, EventTrace.Level.Info, loopDuration.Milliseconds, loopCounter); } return; } } } currentElement = MeasureQueue.GetTopMost(); if (currentElement == null) { break; //exit if no more Measure candidates } currentElement.Measure(currentElement.PreviousConstraint); //dmitryt, } if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientMeasureEnd, etwKeywords, EventTrace.Level.Info, loopCounter); EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientArrangeBegin, etwKeywords, EventTrace.Level.Info, perfElementID); } #if DEBUG_CLR_MEM if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Verbose)) { CLRProfilerControl.CLRLogWriteLine("End_Measure_{0}_{1}", _layoutCLRPass, measureCLRPass); ++arrangeCLRPass; CLRProfilerControl.CLRLogWriteLine("Begin_Arrange_{0}_{1}", _layoutCLRPass, arrangeCLRPass); } #endif // DEBUG_CLR_MEM //loop for Arrange //if Arrange dirtied the tree go clean it again //We limit the number of loops here by time - normally, all layout //calculations should be done by this time, this limit is here for //emergency, "infinite loop" scenarios - yielding in this case will //provide user with ability to continue to interact with the app, even though //it will be sluggish. If we don't yield here, the loop is goign to be a deadly one //and it will be impossible to save results or even close the window. loopCounter = 0; loopStartTime = new DateTime(0); while (MeasureQueue.IsEmpty) { if (++loopCounter > 153) { loopCounter = 0; //first bunch of iterations is free, then we start count time //this way, we don't call DateTime.Now in most layout updates if (loopStartTime.Ticks == 0) { loopStartTime = DateTime.UtcNow; } else { TimeSpan loopDuration = (DateTime.UtcNow - loopStartTime); if (loopDuration.Milliseconds > 153 * 2) // 153*2 = magic*science { //loop detected. Lets go over to background to let input work. Dispatcher.BeginInvoke(DispatcherPriority.Background, _updateLayoutBackground, this); currentElement = null; gotException = false; if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientArrangeAbort, etwKeywords, EventTrace.Level.Info, loopDuration.Milliseconds, loopCounter); } return; } } } currentElement = ArrangeQueue.GetTopMost(); if (currentElement == null) { break; //exit if no more Measure candidates } Rect finalRect = getProperArrangeRect(currentElement); currentElement.Arrange(finalRect); //dmitryt, } if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientArrangeEnd, etwKeywords, EventTrace.Level.Info, loopCounter); } #if DEBUG_CLR_MEM if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Verbose)) { CLRProfilerControl.CLRLogWriteLine("End_Arrange_{0}_{1}", _layoutCLRPass, arrangeCLRPass); } #endif // DEBUG_CLR_MEM //if Arrange dirtied the tree go clean it again //it is not neccesary to check ArrangeQueue sicnce we just exited from Arrange loop if (!MeasureQueue.IsEmpty) { continue; } //let LayoutUpdated handlers to call UpdateLayout //note that it means we can get reentrancy into UpdateLayout past this point, //if any of event handlers call UpdateLayout sync. Need to protect from reentrancy //in the firing methods below. _isInUpdateLayout = false; } fireSizeChangedEvents(); if (hasDirtiness) { continue; } fireLayoutUpdateEvent(); if (hasDirtiness) { continue; } fireAutomationEvents(); if (hasDirtiness) { continue; } fireSizeChangedEvents(); // if nothing is dirty, one last chance for any size changes to announce. } currentElement = null; gotException = false; } finally { _isUpdating = false; _layoutRequestPosted = false; _isInUpdateLayout = false; if (gotException) { if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientLayoutException, etwKeywords, EventTrace.Level.Info, PerfService.GetPerfElementID(currentElement)); } //set indicator _gotException = true; _forceLayoutElement = currentElement; //make attempt to request the subsequent layout calc //some exception handler schemas use Idle priorities to //wait until dust settles. Then they correct the issue noted in the exception handler. //We don't want to attempt to re-do the operation on the priority higher then that. Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, _updateLayoutBackground, this); } } MS.Internal.Text.TextInterface.Font.ResetFontFaceCache(); MS.Internal.FontCache.BufferCache.Reset(); if (etwTracingEnabled) { EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientLayoutEnd, etwKeywords, EventTrace.Level.Info); } #if DEBUG_CLR_MEM if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance)) { CLRProfilerControl.CLRLogWriteLine("End_Layout_{0}", _layoutCLRPass); } #endif // DEBUG_CLR_MEM }
// Token: 0x0600226A RID: 8810 RVA: 0x000AAE10 File Offset: 0x000A9010 private static object Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, XamlObjectWriterSettings settings, Uri baseUri) { XamlContextStack <WpfXamlFrame> stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame()); int persistId = 1; settings.AfterBeginInitHandler = delegate(object sender, XamlObjectEventArgs args) { if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose)) { IXamlLineInfo xamlLineInfo2 = xamlReader as IXamlLineInfo; int num = -1; int num2 = -1; if (xamlLineInfo2 != null && xamlLineInfo2.HasLineInfo) { num = xamlLineInfo2.LineNumber; num2 = xamlLineInfo2.LinePosition; } EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientParseXamlBamlInfo, EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, new object[] { (args.Instance == null) ? 0L : PerfService.GetPerfElementID(args.Instance), num, num2 }); } UIElement uielement = args.Instance as UIElement; if (uielement != null) { UIElement uielement2 = uielement; int persistId = persistId; persistId++; uielement2.SetPersistId(persistId); } XamlSourceInfoHelper.SetXamlSourceInfo(args.Instance, args, baseUri); DependencyObject dependencyObject = args.Instance as DependencyObject; if (dependencyObject != null && stack.CurrentFrame.XmlnsDictionary != null) { XmlnsDictionary xmlnsDictionary = stack.CurrentFrame.XmlnsDictionary; xmlnsDictionary.Seal(); XmlAttributeProperties.SetXmlnsDictionary(dependencyObject, xmlnsDictionary); } stack.CurrentFrame.Instance = args.Instance; }; XamlObjectWriter xamlObjectWriter; if (writerFactory != null) { xamlObjectWriter = writerFactory.GetXamlObjectWriter(settings); } else { xamlObjectWriter = new XamlObjectWriter(xamlReader.SchemaContext, settings); } IXamlLineInfo xamlLineInfo = null; object result; try { xamlLineInfo = (xamlReader as IXamlLineInfo); IXamlLineInfoConsumer xamlLineInfoConsumer = xamlObjectWriter; bool shouldPassLineNumberInfo = false; if (xamlLineInfo != null && xamlLineInfo.HasLineInfo && xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo) { shouldPassLineNumberInfo = true; } IStyleConnector styleConnector = rootObject as IStyleConnector; WpfXamlLoader.TransformNodes(xamlReader, xamlObjectWriter, false, skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, stack, styleConnector); xamlObjectWriter.Close(); result = xamlObjectWriter.Result; } catch (Exception ex) { if (CriticalExceptions.IsCriticalException(ex) || !XamlReader.ShouldReWrapException(ex, baseUri)) { throw; } XamlReader.RewrapException(ex, xamlLineInfo, baseUri); result = null; } return(result); }