r"""Profile graph execution in imperative mode. Args: path: default path prefix for profiler to dump. with_backtrace: Whether to record backtrace information for ops. with_scopes: Whether to keep more scopes to record record module/functional hierarchy. Enabling this opt
| 31 | |
| 32 | |
| 33 | class Profiler(ContextDecorator): |
| 34 | r"""Profile graph execution in imperative mode. |
| 35 | |
| 36 | Args: |
| 37 | path: default path prefix for profiler to dump. |
| 38 | with_backtrace: Whether to record backtrace information for ops. |
| 39 | with_scopes: Whether to keep more scopes to record record module/functional hierarchy. Enabling this option will slow down your program execution. |
| 40 | |
| 41 | Examples: |
| 42 | |
| 43 | .. code-block:: |
| 44 | |
| 45 | import megengine as mge |
| 46 | import megengine.module as M |
| 47 | from megengine.utils.profiler import Profiler |
| 48 | |
| 49 | # With Learnable Parameters |
| 50 | profiler = Profiler() |
| 51 | |
| 52 | for iter in range(0, 10): |
| 53 | # Only profile record of last iter would be saved |
| 54 | |
| 55 | with profiler: |
| 56 | # your code here |
| 57 | |
| 58 | # Then open the profile file in chrome timeline window |
| 59 | """ |
| 60 | |
| 61 | CHROME_TIMELINE = "chrome_timeline.json" |
| 62 | |
| 63 | valid_options = { |
| 64 | "sample_rate": 0, |
| 65 | "profile_device": 1, |
| 66 | "num_tensor_watch": 10, |
| 67 | "enable_cupti": 0, |
| 68 | } |
| 69 | valid_formats = {"chrome_timeline.json", "memory_flow.svg"} |
| 70 | |
| 71 | def __init__( |
| 72 | self, |
| 73 | path: str = "profile", |
| 74 | format: str = "chrome_timeline.json", |
| 75 | formats: List[str] = None, |
| 76 | with_backtrace: bool = False, |
| 77 | with_scopes: bool = False, |
| 78 | **kwargs |
| 79 | ) -> None: |
| 80 | if not formats: |
| 81 | formats = [format] |
| 82 | |
| 83 | assert not isinstance(formats, str), "formats excepts list, got str" |
| 84 | |
| 85 | for format in formats: |
| 86 | assert format in Profiler.valid_formats, "unsupported format {}".format( |
| 87 | format |
| 88 | ) |
| 89 | |
| 90 | self._path = path |
no outgoing calls