forked from spyder-ide/spyder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstrumentaspect.py
99 lines (85 loc) · 3.2 KB
/
instrumentaspect.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from monitoring.Controller import MonitoringController, WriterController
from monitoring.traceregistry import TraceRegistry
import aspectlib
import os
import importlib
from monitoring.Record import *
monitoring_controller = MonitoringController(WriterController())
trace_reg = TraceRegistry()
@aspectlib.Aspect(bind=True)
def wrapper(cutpoint, *args, **kwargs):
print('before')
trace = trace_reg.get_trace()
print(trace)
if(trace is None):
trace = trace_reg.register_trace()
monitoring_controller.new_monitoring_record(trace)
trace_id = trace.trace_id
timestamp = monitoring_controller.time_source_controller.get_time()
func_module = cutpoint.__module__
class_signature = cutpoint.__qualname__.split(".", 1)[0]
monitoring_controller.new_monitoring_record(BeforeOperationEvent(
timestamp,
trace_id,
trace.get_next_order_id(),
cutpoint.__name__,
f'{func_module}.{class_signature}'))
try:
result = yield aspectlib.Proceed
except Exception as e:
print('after failed')
timestamp = monitoring_controller.time_source_controller.get_time()
monitoring_controller.new_monitoring_record(
AfterOperationFailedEvent(timestamp,
-1
-2,
cutpoint.__name__,
f'{func_module}.{class_signature}',
repr(e)))
raise e
print('after')
timestamp = monitoring_controller.time_source_controller.get_time()
monitoring_controller.new_monitoring_record(AfterOperationEvent(
timestamp,
trace_id,
trace.get_next_order_id(),
cutpoint.__name__,
f'{func_module}.{class_signature}'))
yield aspectlib.Return(result)
path = os.getcwd()
dir_list = os.listdir(path)
print(dir_list)
#aspect = ModuleAspectizer()
print('new')
exceptions = ['pyplot.py', 'setup.py', 'bootstrap.py', 'instrument.py',
'windows.py','pybloom.py', 'switcher.py','mainwindow.py']
def load_and_instrument(item):
pass
for root, dirs, files in os.walk('spyder'):
print(files)
if 'tests' in dirs:
dirs.remove('tests')
if 'config' in dirs:
dirs.remove('config')
for f in files:
if (f not in exceptions
and '_' not in f
#and 'py' in f
and f[-3:]=='.py'):
print(f)
filename = os.path.basename(f)[:-3]
filedir = os.path.join(root,f)
spec = importlib.util.spec_from_file_location(
filename,
filedir)
module = importlib.util.module_from_spec(spec)
aspectlib.weave(module, wrapper)
#spec.loader.exec_module(module)
#print(module)
#aspect.add_module(module)
#aspect.instrumentize()
import bootstrap
@aspectlib.Aspect
def test():
result = yield
yield aspectlib.Return(1)