mirror of
https://github.com/slendidev/lunar.git
synced 2026-01-31 00:38:59 +02:00
3526
subprojects/tracy/python/tracy_client/TracyClientBindings.pyi
Normal file
3526
subprojects/tracy/python/tracy_client/TracyClientBindings.pyi
Normal file
File diff suppressed because one or more lines are too long
3
subprojects/tracy/python/tracy_client/__init__.py
Normal file
3
subprojects/tracy/python/tracy_client/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from tracy_client.tracy import *
|
||||
0
subprojects/tracy/python/tracy_client/py.typed
Normal file
0
subprojects/tracy/python/tracy_client/py.typed
Normal file
119
subprojects/tracy/python/tracy_client/scoped.py
Normal file
119
subprojects/tracy/python/tracy_client/scoped.py
Normal file
@@ -0,0 +1,119 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
|
||||
from functools import wraps
|
||||
from typing import Callable, Optional, Union
|
||||
|
||||
from tracy_client.TracyClientBindings import (
|
||||
is_enabled,
|
||||
_ScopedZone,
|
||||
ColorType,
|
||||
frame_mark_start,
|
||||
frame_mark_end,
|
||||
)
|
||||
|
||||
Color = Union[int, ColorType]
|
||||
|
||||
|
||||
class ScopedZone(_ScopedZone):
|
||||
def __init__(
|
||||
self,
|
||||
name: Optional[str] = None,
|
||||
color: Color = 0,
|
||||
depth: Optional[int] = None,
|
||||
active: bool = True,
|
||||
) -> None:
|
||||
frame = sys._getframe(1)
|
||||
_ScopedZone.__init__(
|
||||
self,
|
||||
name,
|
||||
int(color),
|
||||
depth,
|
||||
active,
|
||||
frame.f_code.co_name,
|
||||
frame.f_code.co_filename,
|
||||
frame.f_lineno,
|
||||
)
|
||||
|
||||
def color(self, color: Color) -> None:
|
||||
self._color(int(color))
|
||||
|
||||
def __enter__(self):
|
||||
self.enter()
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.exit()
|
||||
|
||||
|
||||
def ScopedZoneDecorator(
|
||||
name: Optional[str] = None,
|
||||
color: Color = 0,
|
||||
depth: Optional[int] = None,
|
||||
active: bool = True,
|
||||
class_name: Optional[str] = None,
|
||||
):
|
||||
|
||||
def decorator(function: Callable):
|
||||
if not is_enabled():
|
||||
return function
|
||||
|
||||
source = function.__name__
|
||||
if class_name is not None:
|
||||
source = f"{class_name}:{source}"
|
||||
|
||||
zone = _ScopedZone(
|
||||
name,
|
||||
int(color),
|
||||
depth,
|
||||
active,
|
||||
source,
|
||||
function.__code__.co_filename,
|
||||
function.__code__.co_firstlineno,
|
||||
)
|
||||
|
||||
@wraps(function)
|
||||
def wrapped(*args, **kwargs):
|
||||
zone.enter()
|
||||
value = function(*args, **kwargs)
|
||||
zone.exit()
|
||||
return value
|
||||
|
||||
return wrapped
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class ScopedFrame:
|
||||
def __init__(self, name: str) -> None:
|
||||
self.__name = name
|
||||
self.__id: Optional[int] = None
|
||||
|
||||
def __enter__(self):
|
||||
self.__id = frame_mark_start(self.__name)
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
if self.__id is None:
|
||||
return
|
||||
frame_mark_end(self.__id)
|
||||
|
||||
|
||||
def ScopedFrameDecorator(name: str):
|
||||
|
||||
def decorator(function: Callable):
|
||||
if not is_enabled():
|
||||
return function
|
||||
|
||||
@wraps(function)
|
||||
def wrapped(*args, **kwargs):
|
||||
frame_id = frame_mark_start(name)
|
||||
value = function(*args, **kwargs)
|
||||
if frame_id is not None:
|
||||
frame_mark_end(frame_id)
|
||||
return value
|
||||
|
||||
return wrapped
|
||||
|
||||
return decorator
|
||||
36
subprojects/tracy/python/tracy_client/tracy.py
Normal file
36
subprojects/tracy/python/tracy_client/tracy.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Optional, Union
|
||||
|
||||
from tracy_client.TracyClientBindings import (
|
||||
is_enabled,
|
||||
program_name,
|
||||
thread_name,
|
||||
app_info,
|
||||
ColorType,
|
||||
PlotFormatType,
|
||||
frame_mark,
|
||||
frame_mark_start,
|
||||
frame_mark_end,
|
||||
frame_image,
|
||||
alloc,
|
||||
free,
|
||||
message,
|
||||
plot,
|
||||
_plot_config,
|
||||
)
|
||||
from tracy_client.scoped import (
|
||||
Color,
|
||||
ScopedZone,
|
||||
ScopedFrame,
|
||||
ScopedZoneDecorator,
|
||||
ScopedFrameDecorator,
|
||||
)
|
||||
|
||||
PlotType = Union[int, PlotFormatType]
|
||||
|
||||
|
||||
def plot_config(
|
||||
name: str, type: PlotType, step: bool = False, flip: bool = False, color: Color = 0
|
||||
) -> Optional[int]:
|
||||
return _plot_config(name, int(type), step, flip, int(color))
|
||||
Reference in New Issue
Block a user