summaryrefslogtreecommitdiff
path: root/service/test/reactor/defer.patch
blob: 06f49706c7ca625beead8ce9d5636341478289ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
33a34,46
> from datetime import datetime
> 
> class Clock():
>     def __init__(self, label):
>         self.start = datetime.now()
>         self.label = label
> 
>     def stop(self, callback_type):
>         end = datetime.now()
>         total = (end - self.start).total_seconds()
>         if total > 0.1:
>             print('EXECUTING {}: {} {:.5f}'.format(callback_type, self.label, total))
> 
195c208,221
< 
---
> import threading
> import inspect
> def identifyItem(i):
>     if i is None:
>         return "(None)"
>     else:
>         if inspect.isbuiltin(i):
>             return str(i)
>         else:
>             if 'gotResult' == i.__name__:
>                 return False
>             f = inspect.getsourcefile(i)
>             ln = inspect.getsourcelines(i)[1]
>             return "%s (%s:%d)" % (str(i), f, ln)
588c614,624
<                         current.result = callback(current.result, *args, **kw)
---
>                         currentItem = identifyItem(callback)
>                         currentThreadId = threading.current_thread().ident
> 
>                         if currentItem:
>                             clock = Clock("%s in thread %d" % (currentItem, currentThreadId))
>                         try:
>                             current.result = callback(current.result, *args, **kw)
>                         finally:
>                             if currentItem:
>                                 clock.stop('deferred')
>                             
1123a1160
>             currentThreadId = threading.current_thread().ident
1127a1165
>                 c = Clock("%s in thread %d" % (str(g.gi_code), currentThreadId))
1128a1167
>                 c.stop('inlineCallback')
1133a1173
>             c.stop('inlineCallback')