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.TimeDict[source]

Bases: object

Records of time information.

  • reset()[source]

    Clear the time information.

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

class jina.logging.profile.ProgressBar(description=’Working…’, message_on_done=None, final_line_feed=True, total_length=None)[source]

Bases: jina.logging.profile.TimeContext

A simple progress bar.

  • Example:

    1. with ProgressBar('loop'):
    2. do_busy()

Create the ProgressBar.

  • Parameters

    • description (str) – The name of the task, will be displayed in front of the bar.

    • message_on_done (Union[str, Callable[…, str], None]) – The final message to print when the progress is complete

    • final_line_feed (bool) – if False, the line will not get a Line Feed and thus is easily overwritable.

    • total_length (Optional[int]) – if set, then every update() increases the bar by 1/total_length * _bars_on_row

  • col_width = 100

  • clear_line = ‘\r \r’

  • spinner = <itertools.cycle object>

  • update(progress=1.0, description=None, message=None, status=ProgressBarStatus.WORKING, first_enter=False)[source]

    Increment the progress bar by one unit.

    • Parameters

      • progress (float) – The number of unit to increment.

      • description (Optional[str]) – Change the description text before the progress bar on update.

      • message (Optional[str]) – Change the message text followed after the progress bar on update.

      • status (ProgressBarStatus) – If set to a value, it will mark the task as complete, can be either “Done” or “Canceled”

      • first_enter (bool) – if this method is called by __enter__

      Return type

      None