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 steps

  • message_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

update(task_id=None, advance=1, *args, **kwargs)[source]#

Update the progress bar

Parameters:
  • task_id (Optional[NewType()(TaskID, int)]) – the task to update

  • advance (float) – Add a value to main task.completed

add_task(description, start=True, total=100.0, completed=0, visible=True, **fields)#

Add a new ‘task’ to the Progress display.

Args:

description (str): A description of the task. start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False,

you will need to call start manually. Defaults to True.

total (float, optional): Number of total steps in the progress if known.

Set to None to render a pulsing animation. Defaults to 100.

completed (int, optional): Number of steps completed so far. Defaults to 0. visible (bool, optional): Enable display of the task. Defaults to True. **fields (str): Additional data fields required for rendering.

Returns:

TaskID: An ID you can use when calling update.

Return type:

NewType()(TaskID, int)

advance(task_id, advance=1)#

Advance task by a number of steps.

Args:

task_id (TaskID): ID of task. advance (float): Number of steps to advance. Default is 1.

Return type:

None

property console: Console#
Return type:

Console

property finished: bool#

Check if all tasks have been completed.

Return type:

bool

classmethod get_default_columns()#
Get the default columns used for a new Progress instance:
  • a text column for the description (TextColumn)

  • the bar itself (BarColumn)

  • a text column showing completion percentage (TextColumn)

  • an estimated-time-remaining column (TimeRemainingColumn)

If the Progress instance is created without passing a columns argument, the default columns defined here will be used.

You can also create a Progress instance using custom columns before and/or after the defaults, as in this example:

progress = Progress(

SpinnerColumn(), *Progress.get_default_columns(), “Elapsed:”, TimeElapsedColumn(),

)

This code shows the creation of a Progress display, containing a spinner to the left, the default columns, and a labeled elapsed time column.

Return type:

Tuple[ProgressColumn, ...]

get_renderable()#

Get a renderable for the progress display.

Return type:

Union[ConsoleRenderable, RichCast, str]

get_renderables()#

Get a number of renderables for the progress display.

Return type:

Iterable[Union[ConsoleRenderable, RichCast, str]]

make_tasks_table(tasks)#

Get a table to render the Progress display.

Args:

tasks (Iterable[Task]): An iterable of Task instances, one per row of the table.

Returns:

Table: A table instance.

Return type:

Table

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, *, total=None, task_id=None, description='Reading...')#

Track progress while reading from a binary file.

Args:

path (Union[str, PathLike[str]]): The path to the file to read. mode (str): The mode to use to open the file. Only supports “r”, “rb” or “rt”. buffering (int): The buffering strategy to use, see io.open(). encoding (str, optional): The encoding to use when reading in text mode, see io.open(). errors (str, optional): The error handling strategy for decoding errors, see io.open(). newline (str, optional): The strategy for handling newlines in text mode, see io.open(). total (int, optional): Total number of bytes to read. If none given, os.stat(path).st_size is used. task_id (TaskID): Task to track. Default is new task. description (str, optional): Description of task, if new task is created.

Returns:

BinaryIO: A readable file-like object in binary mode.

Raises:

ValueError: When an invalid mode is given.

refresh()#

Refresh (render) the progress information.

Return type:

None

remove_task(task_id)#

Delete a task if it exists.

Args:

task_id (TaskID): A task ID.

Return type:

None

reset(task_id, *, start=True, total=None, completed=0, visible=None, description=None, **fields)#

Reset a task so completed is 0 and the clock is reset.

Args:

task_id (TaskID): ID of task. start (bool, optional): Start the task after reset. Defaults to True. total (float, optional): New total steps in task, or None to use current total. Defaults to None. completed (int, optional): Number of steps completed. Defaults to 0. visible (bool, optional): Enable display of the task. Defaults to True. description (str, optional): Change task description if not None. Defaults to None. **fields (str): Additional data fields required for rendering.

Return type:

None

start()#

Start the progress display.

Return type:

None

start_task(task_id)#

Start a task.

Starts a task (used when calculating elapsed time). You may need to call this manually, if you called add_task with start=False.

Args:

task_id (TaskID): ID of task.

Return type:

None

stop()#

Stop the progress display.

Return type:

None

stop_task(task_id)#

Stop a task.

This will freeze the elapsed time on the task.

Args:

task_id (TaskID): ID of task.

Return type:

None

property task_ids: List[TaskID]#

A list of task IDs.

Return type:

List[NewType()(TaskID, int)]

property tasks: List[Task]#

Get a list of Task instances.

Return type:

List[Task]

track(sequence, total=None, completed=0, task_id=None, description='Working...', update_period=0.1)#

Track progress by iterating over a sequence.

Args:

sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress. total: (float, optional): Total number of steps. Default is len(sequence). completed (int, optional): Number of steps completed so far. Defaults to 0. task_id: (TaskID): Task to track. Default is new task. description: (str, optional): Description of task, if new task is created. update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.

Returns:

Iterable[ProgressType]: An iterable of values taken from the provided sequence.

Return type:

Iterable[TypeVar(ProgressType)]

wrap_file(file, total=None, *, task_id=None, description='Reading...')#

Track progress file reading from a binary file.

Args:

file (BinaryIO): A file-like object opened in binary mode. total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given. task_id (TaskID): Task to track. Default is new task. description (str, optional): Description of task, if new task is created.

Returns:

BinaryIO: A readable file-like object in binary mode.

Raises:

ValueError: When no total value can be extracted from the arguments or the task.

Return type:

BinaryIO

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 (Optional[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']#
now()[source]#

Get the passed time from start to now.

Return type:

float

Returns:

passed time