jina.logging.profile

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 (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(bar_len=20, task_name='', batch_unit='requests', logger=None)[source]

Bases: jina.logging.profile.TimeContext

A simple progress bar.

Example:
with ProgressBar('loop'):
    do_busy()

Create the ProgressBar.

Parameters
  • bar_len (int) – Total length of the bar.

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

  • batch_unit (str) – Unit of batch

  • logger – Jina logger

update_tick(tick=0.1)[source]

Increment the progress bar by one tick, when the ticks accumulate to one, trigger one update().

Parameters

tick (float) – A float unit to increment (should < 1).

Return type

None

update(progress=None, *args, **kwargs)[source]

Increment the progress bar by one unit.

Parameters
  • progress (Optional[int]) – The number of unit to increment.

  • args – extra arguments

  • kwargs – keyword arguments

Return type

None