__init__.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:odin 作者: imito 项目源码 文件源码
def get_system_status(memory_total=False, memory_total_actual=False,
                      memory_total_usage=False, memory_total_free=False,
                      all_pids=False, swap_memory=False, pid=False):
  """
  Parameters
  ----------
  threads: bool
      return dict {id: (user_time, system_time)}
  memory_maps: bool
      return dict {path: rss}

  Note
  ----
  All memory is returned in `MiB`
  To calculate memory_percent:
      get_system_status(memory_usage=True) / get_system_status(memory_total=True) * 100
  """
  import psutil
  # ====== general system query ====== #
  if memory_total:
    return psutil.virtual_memory().total / float(2 ** 20)
  if memory_total_actual:
    return psutil.virtual_memory().available / float(2 ** 20)
  if memory_total_usage:
    return psutil.virtual_memory().used / float(2 ** 20)
  if memory_total_free:
    return psutil.virtual_memory().free / float(2 ** 20)
  if swap_memory:
    tmp = psutil.swap_memory()
    tmp.total /= float(2 ** 20)
    tmp.used /= float(2 ** 20)
    tmp.free /= float(2 ** 20)
    tmp.sin /= float(2**20)
    tmp.sout /= float(2**20)
    return tmp
  if all_pids:
    return psutil.pids()
  if pid:
    return os.getpid()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号