jina.logging.profile module#
- jina.logging.profile.used_memory(unit=1073741824)[source]#
Get the memory usage of the current process.
- Parameters
unit (
int
) – Unit of the memory, default in Gigabytes.- Return type
float
- Returns
Memory usage of the current process.
- jina.logging.profile.used_memory_readable()[source]#
Get the memory usage of the current process in a human-readable format.
- Return type
str
- Returns
Memory usage of the current process.
- jina.logging.profile.profiling(func)[source]#
Create the Decorator to mark a function for profiling. The time and memory usage will be recorded and printed.
Example: .. highlight:: python .. code-block:: python
@profiling def foo():
print(1)
- Parameters
func – function to be profiled
- Returns
arguments wrapper
- class jina.logging.profile.ProgressBar(description='Working...', total_length=None, message_on_done=None, columns=None, disable=False, console=None, **kwargs)[source]#
Bases:
Progress
A progress bar made with rich.
- Example:
with ProgressBar(100, 'loop') as p_bar: for i in range(100): do_busy() p_bar.update()
Init a custom progress bar based on rich. This is the default progress bar of jina if you want to customize it you should probably just use a rich Progress and add your custom column and task
- Parameters
description (
str
) – description of your task ex : ‘Working…’total_length (
Optional
[float
]) – the number of stepsmessage_on_done (
Union
[str
,Callable
[…,str
],None
]) – The message that you want to print at the end of your task. It can either be a string to
be formatted with task (ex ‘{task.completed}’) task or a function which take task as input (ex : lambda task : f’{task.completed}’ :type columns:
Union
[str
,ProgressColumn
,None
] :param columns: If you want to customize the column of the progress bar. Note that you should probably directly use rich Progress object than overwriting these columns parameters. :param total_length: disable the progress bar
- class jina.logging.profile.TimeContext(task_name, logger=None)[source]#
Bases:
object
Timing a code snippet with a context manager.
Create the context manager to timing a code snippet.
- Parameters
task_name (
str
) – The context/message.logger (JinaLogger) – Use existing logger or use naive
print()
.
Example: .. highlight:: python .. code-block:: python
- with TimeContext(‘loop’):
do_busy()
- time_attrs = ['years', 'months', 'days', 'hours', 'minutes', 'seconds']#