/// <summary> /// Writes an activity event, used to correlate start and stop events properly. /// </summary> /// <param name="provider">The event provider to use</param> /// <param name="startEventId">The starting event ID to write</param> /// <param name="stopEventId">The stopping event ID to write</param> /// <returns>The activity to be disposed when stopped</returns> public static DisposableEventActivity WriteEventActivity(this IEventProvider provider, int startEventId, int stopEventId) { if (provider.IsEnabled) { var activity = CreateEventActivity(); provider.WriteEvent( new EventDescriptor( eventId: startEventId, opcode: EventOpcode.Start, activityId: activity?.Id ?? 0 ) ); return(new DisposableEventActivity( activity, () => provider.WriteEvent( new EventDescriptor( eventId: stopEventId, opcode: EventOpcode.Stop, activityId: activity?.Id ?? 0 ) ) )); } else { // the using statement handles null disposable properly. return(null); } }
public override bool DispatchTouchEvent(MotionEvent ev) { if (_trace.IsEnabled) { if (ev.Action == MotionEventActions.Down) { _trace.WriteEvent(TraceProvider.TouchStart); } if (ev.Action == MotionEventActions.Up) { _trace.WriteEvent(TraceProvider.TouchStop); } } return(base.DispatchTouchEvent(ev)); }
internal void Scavenge(bool isManual) { var now = _platformProvider.Now; var removedInstancesCount = 0; foreach (var list in _pooledInstances.Values) { removedInstancesCount += list.RemoveAll(t => isManual || now - t.CreationTime > TimeToLive); } if (removedInstancesCount > 0) { if (_trace.IsEnabled) { for (int i = 0; i < removedInstancesCount; i++) { _trace.WriteEvent(TraceProvider.ReleaseTemplate); } } // Under iOS and Android, we need to force the collection for the GC // to pick up the orphan instances that we've just released. GC.Collect(); } }
/// <summary> /// Write a single activity event, to be used with the stopping opcode later on. /// </summary> /// <param name="provider">The event provider to use</param> /// <param name="eventId">The event ID to write</param> /// <param name="opCode">The opcode of the event</param> /// <param name="payload">An optional payload</param> /// <returns>An activity identifier, to be used as a relatedActivityId, or activity id for the stopping event.</returns> public static EventActivity WriteEventActivity(this IEventProvider provider, int eventId, EventOpcode opCode, object[] payload = null) { var activity = CreateEventActivity(); provider.WriteEvent(new EventDescriptor(eventId: eventId, opcode: opCode, activityId: activity?.Id ?? 0), payload); return(activity); }
private static bool InnerInvokeJSUnmarshalled(string functionIdentifier, IntPtr arg0) { var methodId = GetMethodId(functionIdentifier); var res = WebAssembly.JSInterop.InternalCalls.InvokeJSUnmarshalled(out var exception, null, methodId, arg0, IntPtr.Zero); if (exception != null) { if (_trace.IsEnabled) { _trace.WriteEvent( TraceProvider.InvokeException, new object[] { functionIdentifier, exception.ToString() } ); } throw new Exception(exception); } return(res != IntPtr.Zero); }
private static bool InnerInvokeJSUnmarshalled(string functionIdentifier, IntPtr arg0, out Exception?exception) { exception = null; var methodId = GetMethodId(functionIdentifier); var res = WebAssembly.JSInterop.InternalCalls.InvokeJSUnmarshalled(out var exceptionMessage, null, methodId, arg0, IntPtr.Zero); if (!string.IsNullOrEmpty(exceptionMessage)) { if (_trace.IsEnabled) { _trace.WriteEvent( TraceProvider.InvokeException, new object[] { functionIdentifier, exceptionMessage } ); } exception = new Exception(exceptionMessage); } return(res != IntPtr.Zero); }
protected virtual bool GoToStateCore(Control control, IFrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions) { #if IS_UNO if (_trace.IsEnabled) { _trace.WriteEvent( TraceProvider.StoryBoard_GoToState, EventOpcode.Send, new[] { control.GetType()?.ToString(), control?.GetDependencyObjectId().ToString(), stateName, useTransitions ? "UseTransitions" : "NoTransitions" } ); } #endif var originalState = group.CurrentState; if (VisualState.Equals(originalState, state)) { // Already in the right state return(true); } RaiseCurrentStateChanging(group, originalState, state); // The visual state group must not keep a hard reference to the control, // otherwise it may leak. var wr = Uno.UI.DataBinding.WeakReferencePool.RentWeakReference(this, control); group.GoToState( control, state, originalState, useTransitions, () => { var innerControl = wr?.Target as Control; if (innerControl != null) { RaiseCurrentStateChanged(group, originalState, state); } } ); return(true); }
public static string InvokeJS(string str) { using (WritePropertyEventTrace(TraceProvider.InvokeStart, TraceProvider.InvokeEnd, str)) { try { if (_logger.Value.IsEnabled(LogLevel.Debug)) { _logger.Value.Debug("InvokeJS:" + str); } string result; if (InvokeJSOverride == null) { result = WebAssembly.Runtime.InvokeJS(str); } else { result = InvokeJSOverride(str); } if (result == null) { throw new InvalidOperationException("The invoked Javascript method did not return a value (" + str + ")"); } return(result); } catch (Exception e) { if (_trace.IsEnabled) { _trace.WriteEvent( TraceProvider.InvokeException, new object[] { str, e.ToString() } ); } throw; } } }
private void DispatchItems() { UIAsyncOperation operation = null; CoreDispatcherPriority operationPriority = CoreDispatcherPriority.Normal; for (int i = 3; i >= 0; i--) { var queue = _queues[i]; lock (_gate) { if (queue.Count > 0) { operation = queue.Dequeue(); operationPriority = (CoreDispatcherPriority)(i - 2); if (DecrementGlobalCount() > 0) { EnqueueNative(); } break; } } } if (operation != null) { if (!operation.IsCancelled) { IDisposable runActivity = null; try { if (_trace.IsEnabled) { runActivity = _trace.WriteEventActivity( TraceProvider.CoreDispatcher_InvokeStart, TraceProvider.CoreDispatcher_InvokeStop, relatedActivity: operation.ScheduleEventActivity, payload: new[] { ((int)operationPriority).ToString(), operation.GetDiagnosticsName() } ); } using (runActivity) { using (CoreDispatcherSynchronizationContext.Apply(this, operationPriority)) { operation.Action(); operation.Complete(); } } } catch (Exception ex) { if (_trace.IsEnabled) { _trace.WriteEvent(TraceProvider.CoreDispatcher_Exception, EventOpcode.Send, new[] { ex.GetType().ToString(), operation.GetDiagnosticsName() }); } operation.SetError(ex); this.Log().Error("Dispatcher unhandled exception", ex); } } else { if (_trace.IsEnabled) { _trace.WriteEvent(TraceProvider.CoreDispatcher_Cancelled, EventOpcode.Send, new[] { operation.GetDiagnosticsName() }); } } } else { throw new InvalidOperationException("Dispatch queue is empty"); } }
/// <summary> /// Write a single activity event, to be used with the stopping opcode later on. /// </summary> /// <param name="provider">The event provider to use</param> /// <param name="eventId">The event ID to write</param> /// <param name="opCode">The opcode of the event</param> /// <param name="activityId">The current activity</param> /// <param name="payload">An optional payload</param> /// <returns>An activity identifier, to be used as a relatedActivityId, or activity id for the stopping event.</returns> public static void WriteEventActivity(this IEventProvider provider, int eventId, EventOpcode opCode, EventActivity activity, object[] payload = null) { provider.WriteEvent(new EventDescriptor(eventId: eventId, opcode: opCode, activityId: activity?.Id ?? 0), payload); }
/// <summary> /// Writes an event in the specified provider. /// </summary> /// <param name="provider">The event provider to use</param> /// <param name="eventId">The event ID to use</param> /// <param name="opCode">The opcode for the event</param> /// <param name="payload">The payload for the event</param> public static void WriteEvent(this IEventProvider provider, int eventId, EventOpcode opCode, object[] payload = null) { provider.WriteEvent(new EventDescriptor(eventId: eventId, opcode: opCode), payload); }
/// <summary> /// Writes an event in the specified provider. /// </summary> /// <param name="provider">The event provider to use</param> /// <param name="eventId">The event ID to use</param> /// <param name="payload">The payload for the event</param> public static void WriteEvent(this IEventProvider provider, int eventId, object[] payload = null) { provider.WriteEvent(new EventDescriptor(eventId), payload); }
private void DispatchItems() { UIAsyncOperation operation = null; var operationPriority = CoreDispatcherPriority.Normal; Rendering?.Invoke(null, RenderingEventArgsGenerator(DateTimeOffset.UtcNow - _startTime)); var didEnqueue = false; for (var i = 3; i >= 0; i--) { var queue = _queues[i]; lock (_gate) { if (queue.Count > 0) { operation = queue.Dequeue(); operationPriority = (CoreDispatcherPriority)(i - 2); if (DecrementGlobalCount() > 0) { didEnqueue = true; EnqueueNative(); } break; } } } if (operation != null) { if (!operation.IsCancelled) { IDisposable runActivity = null; try { if (_trace.IsEnabled) { runActivity = _trace.WriteEventActivity( TraceProvider.CoreDispatcher_InvokeStart, TraceProvider.CoreDispatcher_InvokeStop, relatedActivity: operation.ScheduleEventActivity, payload: new[] { ((int)operationPriority).ToString(), operation.GetDiagnosticsName() } ); } using (runActivity) { using (GetSyncContext(operationPriority).Apply()) { operation.Action(); operation.Complete(); } } } catch (Exception ex) { if (_trace.IsEnabled) { _trace.WriteEvent(TraceProvider.CoreDispatcher_Exception, EventOpcode.Send, new[] { ex.GetType().ToString(), operation.GetDiagnosticsName() }); } operation.SetError(ex); this.Log().Error("Dispatcher unhandled exception", ex); } } else { if (_trace.IsEnabled) { _trace.WriteEvent(TraceProvider.CoreDispatcher_Cancelled, EventOpcode.Send, new[] { operation.GetDiagnosticsName() }); } } } else if (!ShouldRaiseRenderEvents) { if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Error("Dispatch queue is empty"); } } if (!didEnqueue && ShouldRaiseRenderEvents) { DispatchWakeUp(); } }