| 138 | # GUID setter ? |
| 139 | |
| 140 | class CtxProcess(object): |
| 141 | def __init__(self, trace, func, stop=False): |
| 142 | self.trace = trace |
| 143 | self.func = func |
| 144 | self.stop = stop |
| 145 | self.timing = {} |
| 146 | |
| 147 | def _get_time(self): |
| 148 | now = gdef.FILETIME() |
| 149 | windows.winproxy.GetSystemTimeAsFileTime(now) |
| 150 | return now |
| 151 | |
| 152 | def __enter__(self): |
| 153 | self.timing["begin"] = self._get_time() |
| 154 | return self.timing |
| 155 | |
| 156 | def __exit__(self, exc_type, exc_value, traceback): |
| 157 | # bad_end = self._get_time() |
| 158 | self.trace.flush() |
| 159 | if self.stop: |
| 160 | self.trace.stop() |
| 161 | # End time after the flush is effective. |
| 162 | self.timing["end"] = self._get_time() |
| 163 | # print("Trace ctx: fake-end: {0:#x}".format(int(fake_end))) |
| 164 | print("Trace ctx: begin={0:#x} | end={1:#x}".format(int(self.timing["begin"]), int(self.timing["end"]))) |
| 165 | self.trace.process(self.func, **self.timing) |
| 166 | |
| 167 | |
| 168 | class EtwTrace(object): |