diff --git a/src/core/triggerset.py b/src/core/triggerset.py
index 5ef76f0..b5dca51 100644
|
a
|
b
|
class _Trigger:
|
| 150 | 150 | self._usage_cb = usage_cb |
| 151 | 151 | self._default_one_time = default_one_time |
| 152 | 152 | self._remove_bad_handlers = remove_bad_handlers |
| | 153 | self._profile_next_run = False |
| | 154 | self._profile_params = None |
| 153 | 155 | |
| 154 | 156 | def add(self, handler): |
| 155 | 157 | if self._locked: |
| … |
… |
class _Trigger:
|
| 171 | 173 | if self._usage_cb and len(self._handlers) == len(self._pending_del): |
| 172 | 174 | self._usage_cb(self._name, 0) |
| 173 | 175 | |
| | 176 | def profile_next_run(self, sort_by='time', num_entries=20): |
| | 177 | self._profile_next_run = True |
| | 178 | self._profile_params = {'sort_by': sort_by, 'num_entries': num_entries} |
| | 179 | |
| 174 | 180 | def activate(self, data): |
| | 181 | if not self._profile_next_run: |
| | 182 | self._activate(data) |
| | 183 | return |
| | 184 | import cProfile, pstats, io |
| | 185 | params = self._profile_params |
| | 186 | pr = cProfile.Profile() |
| | 187 | pr.enable() |
| | 188 | self._activate(data) |
| | 189 | pr.disable() |
| | 190 | s = io.StringIO() |
| | 191 | ps = pstats.Stats(pr, stream=s).sort_stats(params['sort_by']) |
| | 192 | ps.print_stats(params['num_entries']) |
| | 193 | print('Profile for last activation of {} trigger:'.format(self._name)) |
| | 194 | print(s.getvalue()) |
| | 195 | self._profile_next_run = False |
| | 196 | |
| | 197 | |
| | 198 | def _activate(self, data): |
| 175 | 199 | if self._blocked: |
| 176 | 200 | # don't raise trigger multiple times for identical |
| 177 | 201 | # data |
| … |
… |
class TriggerSet:
|
| 350 | 374 | """ |
| 351 | 375 | self._triggers[name].release() |
| 352 | 376 | |
| | 377 | def profile_trigger(self, name, sort_by='time', num_entries=20): |
| | 378 | """Supported API. Profile the next firing of the given trigger. |
| | 379 | |
| | 380 | triggerset.profile_trigger(name) => None |
| | 381 | |
| | 382 | The resulting profile information will be printed to the ChimeraX log. |
| | 383 | The optional sort_by argument may be any of the arguments allowed by |
| | 384 | Python's `pstats.sort_stats()` method. Typically, the most useful of |
| | 385 | these are: |
| | 386 | |
| | 387 | 'calls': call count |
| | 388 | 'cumulative': cumulative time |
| | 389 | 'time': internal time |
| | 390 | """ |
| | 391 | self._triggers[name].profile_next_run(sort_by=sort_by, num_entries=num_entries) |
| | 392 | |
| 353 | 393 | def has_trigger(self, name): |
| 354 | 394 | """Supported API. Check if trigger exists.""" |
| 355 | 395 | return name in self._triggers |