code: def watch_memory():
      """Bring in the global memory usage value from the previous iteration"""
      global previous_call_memory_usage, keep_watching, watching_memory, input_cells
      new_memory_usage = memory_profiler.memory_usage()[0]
      memory_delta = new_memory_usage - previous_call_memory_usage
      keep_watching = False
      total_memory = psutil.virtual_memory()[0] / 1024 / 1024  # in Mb
      # calculate time delta using global t1 (from the pre-run event) and current time
      time_delta_secs = time.time() - t1
      num_commands = len(input_cells) - 1
      cmd = "In [{}]".format(num_commands)
      # convert the results into a pretty string
      output_template = (
          "{cmd} used {memory_delta:0.4f} Mb RAM in "
          "{time_delta:0.2f}s, total RAM usage "
          "{memory_usage:0.2f} Mb, total RAM "
          "memory {total_memory:0.2f} Mb"
      )
      output = output_template.format(
          time_delta=time_delta_secs,
          cmd=cmd,
          memory_delta=memory_delta,
          memory_usage=new_memory_usage,
          total_memory=total_memory,
      )
      if watching_memory:
          print(str(output))
      previous_call_memory_usage = new_memory_usage
  
file_path: recommenders/recommenders/utils/notebook_memory_management.py
imports: from __future__ import division
  from __future__ import absolute_import
  from __future__ import print_function
  from __future__ import unicode_literals
  import time
  import memory_profiler
  from IPython import get_ipython
  import psutil
  import warnings
label_desc: Use image node_id 3 for calling a global function with example usage: watch_memory() without return types