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