forked from pytorch/tnt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IProfiler protocol (pytorch#599)
Summary: Add a protocol to define a Profiler. Reviewed By: crassirostris Differential Revision: D50765964
- Loading branch information
1 parent
d3fdc28
commit e096b70
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import logging | ||
from types import TracebackType | ||
from typing import Optional, Protocol, Type | ||
|
||
logger: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
class IProfiler(Protocol): | ||
"""Protocol for profilers. Can be used as a context manager.""" | ||
|
||
def __enter__(self) -> None: | ||
"""Enters the context manager and starts the profiler.""" | ||
pass | ||
|
||
def __exit__( | ||
self, | ||
exc_type: Optional[Type[BaseException]], | ||
exc_value: Optional[BaseException], | ||
tb: Optional[TracebackType], | ||
) -> Optional[bool]: | ||
"""Exits the context manager and stops the profiler.""" | ||
pass | ||
|
||
def start(self) -> None: | ||
"""Starts the profiler.""" | ||
pass | ||
|
||
def stop(self) -> None: | ||
"""Stops the profiler.""" | ||
pass | ||
|
||
def step(self) -> None: | ||
"""Signals to the profiler that the next profiling step has started.""" | ||
pass |