|
| 1 | +__all__ = ['BaseInstrumenter'] |
| 2 | + |
| 3 | +import abc |
| 4 | +import os |
| 5 | +import sys |
| 6 | + |
| 7 | + |
| 8 | +def get_module_name(frame): |
| 9 | + modulename = frame.f_globals.get('__name__', None) |
| 10 | + if modulename is None: |
| 11 | + # this is a NUMPY special situation, see NEP-18, and Score-P Issue |
| 12 | + # issues #63 |
| 13 | + if frame.f_code.co_filename == "<__array_function__ internals>": |
| 14 | + modulename = "numpy.__array_function__" |
| 15 | + else: |
| 16 | + modulename = "unkown" |
| 17 | + return modulename |
| 18 | + |
| 19 | + |
| 20 | +def get_file_name(frame): |
| 21 | + file_name = frame.f_code.co_filename |
| 22 | + if file_name is not None: |
| 23 | + full_file_name = os.path.abspath(file_name) |
| 24 | + else: |
| 25 | + full_file_name = "None" |
| 26 | + return full_file_name |
| 27 | + |
| 28 | + |
| 29 | +if sys.version_info >= (3, 4): |
| 30 | + class _BaseInstrumenter(abc.ABC): |
| 31 | + pass |
| 32 | +else: |
| 33 | + class _BaseInstrumenter(): |
| 34 | + __metaclass__ = abc.ABCMeta |
| 35 | + |
| 36 | + |
| 37 | +class BaseInstrumenter(_BaseInstrumenter): |
| 38 | + @abc.abstractmethod |
| 39 | + def register(self): |
| 40 | + pass |
| 41 | + |
| 42 | + @abc.abstractmethod |
| 43 | + def unregister(self): |
| 44 | + pass |
| 45 | + |
| 46 | + @abc.abstractmethod |
| 47 | + def get_registered(self): |
| 48 | + return None |
| 49 | + |
| 50 | + @abc.abstractmethod |
| 51 | + def run(self, cmd): |
| 52 | + pass |
| 53 | + |
| 54 | + @abc.abstractmethod |
| 55 | + def runctx(self, cmd, globals=None, locals=None): |
| 56 | + pass |
| 57 | + |
| 58 | + @abc.abstractmethod |
| 59 | + def runfunc(self, func, *args, **kw): |
| 60 | + pass |
| 61 | + |
| 62 | + @abc.abstractmethod |
| 63 | + def region_begin(self, module_name, function_name, file_name, line_number): |
| 64 | + pass |
| 65 | + |
| 66 | + @abc.abstractmethod |
| 67 | + def region_end(self, module_name, function_name): |
| 68 | + pass |
| 69 | + |
| 70 | + @abc.abstractmethod |
| 71 | + def rewind_begin(self, name, file_name=None, line_number=None): |
| 72 | + pass |
| 73 | + |
| 74 | + @abc.abstractmethod |
| 75 | + def rewind_end(self, name, value): |
| 76 | + pass |
| 77 | + |
| 78 | + @abc.abstractmethod |
| 79 | + def oa_region_begin(self, name, file_name=None, line_number=None): |
| 80 | + pass |
| 81 | + |
| 82 | + @abc.abstractmethod |
| 83 | + def oa_region_end(self, name): |
| 84 | + pass |
| 85 | + |
| 86 | + @abc.abstractmethod |
| 87 | + def user_enable_recording(self): |
| 88 | + pass |
| 89 | + |
| 90 | + @abc.abstractmethod |
| 91 | + def user_disable_recording(self): |
| 92 | + pass |
| 93 | + |
| 94 | + @abc.abstractmethod |
| 95 | + def user_parameter_int(self, name, val): |
| 96 | + pass |
| 97 | + |
| 98 | + @abc.abstractmethod |
| 99 | + def user_parameter_uint(self, name, val): |
| 100 | + pass |
| 101 | + |
| 102 | + @abc.abstractmethod |
| 103 | + def user_parameter_string(self, name, string): |
| 104 | + pass |
0 commit comments