| @@ -10,6 +10,17 | |||||
| 10 | TraceContext.Instance.Leave(); |
|
10 | TraceContext.Instance.Leave(); | |
| 11 | }); |
|
11 | }); | |
| 12 | } |
|
12 | } | |
|
|
13 | ||||
|
|
14 | public static IPromise EndLogicalOperation(this IPromise promise) { | |||
|
|
15 | Safe.ArgumentNotNull(promise, "promise"); | |||
|
|
16 | var op = TraceContext.Instance.DetachLogicalOperation(); | |||
|
|
17 | ||||
|
|
18 | return promise.Anyway(() => { | |||
|
|
19 | TraceContext.Instance.EnterLogicalOperation(op,true); | |||
|
|
20 | TraceLog.EndLogicalOperation(); | |||
|
|
21 | TraceContext.Instance.Leave(); | |||
|
|
22 | }); | |||
|
|
23 | } | |||
| 13 | } |
|
24 | } | |
| 14 | } |
|
25 | } | |
| 15 |
|
26 | |||
| @@ -41,9 +41,10 namespace Implab.Diagnostics { | |||||
| 41 | } |
|
41 | } | |
| 42 |
|
42 | |||
| 43 | public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) { |
|
43 | public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) { | |
| 44 | LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Attach, String.Format("{0} -> [{1}]", operation.Name, m_threadId))); |
|
44 | var prev = CurrentOperation; | |
| 45 | m_stack.Push(m_current); |
|
45 | m_stack.Push(m_current); | |
| 46 | m_current = new OperationContext(operation, takeOwnership); |
|
46 | m_current = new OperationContext(operation, takeOwnership); | |
|
|
47 | LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name))); | |||
| 47 | } |
|
48 | } | |
| 48 |
|
49 | |||
| 49 | public void StartLogicalOperation(string name) { |
|
50 | public void StartLogicalOperation(string name) { | |
| @@ -61,15 +62,17 namespace Implab.Diagnostics { | |||||
| 61 | } |
|
62 | } | |
| 62 |
|
63 | |||
| 63 | public LogicalOperation DetachLogicalOperation() { |
|
64 | public LogicalOperation DetachLogicalOperation() { | |
| 64 |
var |
|
65 | var prev = m_current.DetachLogicalOperation(); | |
| 65 |
LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format(" |
|
66 | LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name))); | |
| 66 |
return |
|
67 | return prev; | |
| 67 | } |
|
68 | } | |
| 68 |
|
69 | |||
| 69 | public void Leave() { |
|
70 | public void Leave() { | |
| 70 | if (m_stack.Count > 0) { |
|
71 | if (m_stack.Count > 0) { | |
| 71 | m_current.Leave(); |
|
72 | m_current.Leave(); | |
|
|
73 | var prev = CurrentOperation; | |||
| 72 | m_current = m_stack.Pop(); |
|
74 | m_current = m_stack.Pop(); | |
|
|
75 | LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name))); | |||
| 73 | } else { |
|
76 | } else { | |
| 74 | TraceLog.TraceWarning("Attemtp to leave the last operation context"); |
|
77 | TraceLog.TraceWarning("Attemtp to leave the last operation context"); | |
| 75 | m_current = OperationContext.EMPTY; |
|
78 | m_current = OperationContext.EMPTY; | |
| @@ -13,5 +13,7 namespace Implab.Diagnostics { | |||||
| 13 | OperationCompleted, |
|
13 | OperationCompleted, | |
| 14 | Attach, |
|
14 | Attach, | |
| 15 | Detach, |
|
15 | Detach, | |
|
|
16 | Enter, | |||
|
|
17 | Leave | |||
| 16 | } |
|
18 | } | |
| 17 | } |
|
19 | } | |
| @@ -1,7 +1,4 | |||||
| 1 | using System; |
|
1 | using System; | |
| 2 | using System.Collections.Generic; |
|
|||
| 3 | using System.Linq; |
|
|||
| 4 | using System.Text; |
|
|||
| 5 |
|
2 | |||
| 6 | namespace Implab { |
|
3 | namespace Implab { | |
| 7 | public interface IPromise<T> : IPromise { |
|
4 | public interface IPromise<T> : IPromise { | |
| @@ -44,7 +44,7 namespace Implab | |||||
| 44 | } |
|
44 | } | |
| 45 |
|
45 | |||
| 46 | [DebuggerStepThrough] |
|
46 | [DebuggerStepThrough] | |
| 47 |
public static IPromise<T> |
|
47 | public static IPromise<T> InvokePromise<T>(Func<T> action) { | |
| 48 | ArgumentNotNull(action, "action"); |
|
48 | ArgumentNotNull(action, "action"); | |
| 49 |
|
49 | |||
| 50 | var p = new Promise<T>(); |
|
50 | var p = new Promise<T>(); | |
| @@ -58,11 +58,11 namespace Implab | |||||
| 58 | } |
|
58 | } | |
| 59 |
|
59 | |||
| 60 | [DebuggerStepThrough] |
|
60 | [DebuggerStepThrough] | |
| 61 |
public static IPromise<T> |
|
61 | public static IPromise<T> InvokePromise<T>(Func<IPromise<T>> action) { | |
| 62 | ArgumentNotNull(action, "action"); |
|
62 | ArgumentNotNull(action, "action"); | |
| 63 |
|
63 | |||
| 64 | try { |
|
64 | try { | |
| 65 | return action(); |
|
65 | return action() ?? Promise<T>.ExceptionToPromise(new Exception("The action returned null")); | |
| 66 | } catch (Exception err) { |
|
66 | } catch (Exception err) { | |
| 67 | return Promise<T>.ExceptionToPromise(err); |
|
67 | return Promise<T>.ExceptionToPromise(err); | |
| 68 | } |
|
68 | } | |
| @@ -6,6 +6,9 using Implab; | |||||
| 6 | namespace MonoPlay { |
|
6 | namespace MonoPlay { | |
| 7 | class MainClass { |
|
7 | class MainClass { | |
| 8 | public static void Main(string[] args) { |
|
8 | public static void Main(string[] args) { | |
|
|
9 | if (args == null) | |||
|
|
10 | throw new ArgumentNullException("args"); | |||
|
|
11 | ||||
| 9 | var listener = new ConsoleTraceListener(true); |
|
12 | var listener = new ConsoleTraceListener(true); | |
| 10 | listener.Subscribe<TraceEvent>(); |
|
13 | listener.Subscribe<TraceEvent>(); | |
| 11 |
|
14 | |||
| @@ -13,12 +16,10 namespace MonoPlay { | |||||
| 13 |
|
16 | |||
| 14 | TraceLog.StartLogicalOperation("program"); |
|
17 | TraceLog.StartLogicalOperation("program"); | |
| 15 |
|
18 | |||
| 16 | Console.WriteLine("Hello World!"); |
|
|||
| 17 |
|
||||
| 18 | TraceLog.StartLogicalOperation("async"); |
|
19 | TraceLog.StartLogicalOperation("async"); | |
| 19 | AsyncPool.Invoke(() => { |
|
20 | AsyncPool.Invoke(() => { | |
| 20 | TraceLog.TraceInformation("Hello async"); |
|
21 | TraceLog.TraceInformation("Hello async"); | |
| 21 | TraceLog.StartLogicalOperation(); |
|
22 | TraceLog.StartLogicalOperation("foo"); | |
| 22 | return 0; |
|
23 | return 0; | |
| 23 | }) |
|
24 | }) | |
| 24 | .EndLogicalOperation() |
|
25 | .EndLogicalOperation() | |
General Comments 0
You need to be logged in to leave comments.
Login now
